View unanswered posts | View active topics It is currently Fri May 26, 2017 10:38 pm

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
nMotorEncoderTarget Freeze
Author Message
Rookie

Joined: Wed Nov 13, 2013 7:44 pm
Posts: 1
nMotorEncoderTarget Freeze
I am attempting to use the nMotorEncoderTarget to get controlled movement out of my robot. The problem is that if the target is not met, the motors have slowed down so much they cannot reach the target and the robot needs a bump to satisfy the target and move on in the program. Is there a way to abort the command or task after a set time and continue down the program? Please Help!

Wed Nov 13, 2013 7:49 pm

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Re: nMotorEncoderTarget Freeze
 AHComets wrote:I am attempting to use the nMotorEncoderTarget to get controlled movement out of my robot. The problem is that if the target is not met, the motors have slowed down so much they cannot reach the target and the robot needs a bump to satisfy the target and move on in the program. Is there a way to abort the command or task after a set time and continue down the program? Please Help!

The quickest and easiest way to solve this problem is to add a time condition in the while loop (assuming you are using a while loop to wait for the nMotorRunState of a motor to reach runStateIdle, as shown in the sample programs on the ROBOTC wiki: http://www.robotc.net/wiki/NXT_Function ... oderTarget)

 Code:nMotorEncoder[motorB] = 0;                // reset the Motor Encoder of Motor BnMotorEncoder[motorC] = 0;                // reset the Motor Encoder of Motor CnMotorEncoderTarget[motorB] = 360;        // set the  target for Motor Encoder of Motor B to 360nMotorEncoderTarget[motorC] = 360;        // set the  target for Motor Encoder of Motor C to 360motor[motorB] = 75;                       // motor B is run at a power level of 75motor[motorC] = 75;                       // motor C is run at a power level of 75 while(nMotorRunState[motorB] != runStateIdle && nMotorRunState[motorC] != runStateIdle)  // while Motor B AND Motor C are still running (haven't yet reached their target):{  // do not continue}motor[motorB] = 0;                       // motor B is stopped at a power level of 0motor[motorC] = 0;                       // motor C is stopped at a power level of 0

To do this, we first need to choose a timer and clear it before we use it; the timers start tracking time from the start of the program, so any elapsed time up to the point it is used in the program will be returned by the timer. By clearing it, we ensure that we start the timer from a known quantity instead (a zero value). More information on using timers in a program can be found on the ROBOTC wiki: http://www.robotc.net/wiki/VEX2_Functions_Timing.

Clearing the timer can be done with the ClearTimer() command:

 Code:ClearTimer(T1);

Next, we simply need to add this into the while loop's condition with a logical AND (&&) operator:

 Code:nMotorEncoder[motorB] = 0;                // reset the Motor Encoder of Motor BnMotorEncoder[motorC] = 0;                // reset the Motor Encoder of Motor CnMotorEncoderTarget[motorB] = 360;        // set the  target for Motor Encoder of Motor B to 360nMotorEncoderTarget[motorC] = 360;        // set the  target for Motor Encoder of Motor C to 360motor[motorB] = 75;                       // motor B is run at a power level of 75motor[motorC] = 75;                       // motor C is run at a power level of 75ClearTimer(T1);while(nMotorRunState[motorB] != runStateIdle && nMotorRunState[motorC] != runStateIdle && time1[T1] < 5000)  // while Motor B AND Motor C are still running (haven't yet reached their target):{  // do not continue}motor[motorB] = 0;                       // motor B is stopped at a power level of 0motor[motorC] = 0;                       // motor C is stopped at a power level of 0

For this example, I used the time1 command (time in milliseconds) and 5000 as the maximum value. The while loop now checks to make sure that motorB is not in a runStateIdle mode AND motor C is not in a runStateIdle mode AND that the T1 timer is less than 5000. Once one of these conditions becomes false (either by a motor going to the runStateIdle mode or by the T1 timer reaching a value of 5000ms), the motors will stop.

You may need to tweak the time value in order to increase/decrease the amount of time used by while loop. Decrease the value too much, and the loop may exit early. Increase the value too much, and the program will be wasting more time.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.

Thu Nov 14, 2013 1:35 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 2 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 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