View unanswered posts | View active topics It is currently Fri Oct 19, 2018 3:20 pm

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
RobotC Guard Conditions
Author Message
Rookie

Joined: Wed Dec 04, 2013 9:04 pm
Posts: 2
RobotC Guard Conditions
Hi

I am new to RobotC / NXT Encoder Programming. I have to program Guard conditions so I don't lock my motor which opening or closing the claw. If the Claw is already open and If I press on the Joystick - Open Button, it locks the motor. Similarly if the Claw is closed, and If I press the Close Button, the motor gets locked.

Basically here is my pseudo code based on the code to open the Claw to

if (Open Button Pressed) {
nMotorEncoder[motorB] = 0; // Reset the Motor Encoder of Motor B.
nMotorEncoderTarget[motorB] = 60; // Set the target for Motor Encoder of Motor B to 60.
motor[motorB] = 75; // Motor B is run at a power level of 75.
while((nMotorRunState[motorB] != runStateIdle) && (nMotorEncoderTarget[motorB] < 60)) // While Motor B is still running:
{
// Do not continue.
}
motor[motorB] = 0; // Motor B is stopped at a power level of 0.
}

if (Close Button Pressed) {
nMotorEncoder[motorB] = 0; // Reset the Motor Encoder of Motor B.
nMotorEncoderTarget[motorB] = -60; // Set the target for Motor Encoder of Motor B to 60.
motor[motorB] = 75; // Motor B is run at a power level of 75.
while((nMotorRunState[motorB] != runStateIdle) && (nMotorEncoderTarget[motorB] > -60)) // While Motor B is still running:
{
// Do not continue.
}
motor[motorB] = 0; // Motor B is stopped at a power level of 0.
}

Is this correct or am I missing something basic. This is my first day of Programming RobotC, so please forgive me for not reading the manuals.

thanks,
Rajesh

Wed Dec 04, 2013 9:20 pm
Professor

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
Re: RobotC Guard Conditions
Hmm, you're on the right track, but there's a few things you need to know. First of all, putting loops in your driver-control program is typically not a good idea because all of the rest of your code will have to wait for the loop to finish before it runs. For example, you would be unable to drive around your robot while the claw was moving. I'm not 100% sure on this, but I believe you would be able to set the nMotorEncoderTarget when the button is pushed and the motor would automatically stop moving when it reached that target. In other words, you wouldn't need to worry about putting any code in to make it stop.

As far as making sure you don't jam your motor, you could put in a simple Boolean variable. Something like:
 Code:bool bClawOpen = true; //Set to true or false depending on whether your claw starts opened or closed

Then, in your code for opening and closing the claw:
 Code:if (Open Button Pressed && !bClawOpen){  bClawOpen = true;  // Open the claw}else if (Closed Button Pressed && bClawOpen){  bClawOpen = false;  // Close the claw}

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.

Thu Dec 05, 2013 1:32 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 2 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.