View unanswered posts | View active topics It is currently Sat Sep 19, 2020 12:01 pm

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Stop encoder loop after a set time?
Author Message
Rookie

Joined: Mon Dec 15, 2014 9:48 pm
Posts: 16
Stop encoder loop after a set time?
Hi,

Our robot sometimes can run into the wall and get stuck in autonomous, because it uses encoders and it tries to keep going until the encoder tics reach the set amount.

Here is some of our code now:

//Set the motor encoders to zero
nMotorEncoder[motorC] = 0;
nMotorEncoder[motorD] = 0;
nMotorEncoder[motorE] = 0;
nMotorEncoder[motorF] = 0;

//move forward
while ((nMotorEncoder[motorE] + nMotorEncoder[motorF]) / 2 < 600)
{
motor[motorC] = -40;
motor[motorD] = -40;
motor[motorE] = 40;
motor[motorF] = 40;
}
motor[motorC] = 0;
motor[motorD] = 0;
motor[motorE] = 0;
motor[motorF] = 0;

We want to make the current while encoder loop stop after a set time so that the program will continue to the next one even if it gets stuck. I would think that putting this inside a while(time1(T1) < 2000) loop wouldn't work, because it would get stuck on the encoder while loop and not read the time loop. Here is another way we though of doing it: Would this work the same way?

//Set the motor encoders to zero
nMotorEncoder[motorC] = 0;
nMotorEncoder[motorD] = 0;
nMotorEncoder[motorE] = 0;
nMotorEncoder[motorF] = 0;

//move forward
while (((nMotorEncoder[motorE] + nMotorEncoder[motorF]) / 2 < 600) || time1(T1) < 2000)
{
motor[motorC] = -40;
motor[motorD] = -40;
motor[motorE] = 40;
motor[motorF] = 40;
}
motor[motorC] = 0;
motor[motorD] = 0;
motor[motorE] = 0;
motor[motorF] = 0;

Thanks for any help!

Mon Feb 09, 2015 10:01 pm
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Re: Stop encoder loop after a set time?
 Code://Set the motor encoders to zeronMotorEncoder[motorC] = 0;nMotorEncoder[motorD] = 0;nMotorEncoder[motorE] = 0;nMotorEncoder[motorF] = 0;clearTimer(T1);//move forwardwhile (((nMotorEncoder[motorE] + nMotorEncoder[motorF]) / 2 < 600) && time1(T1) < 2000){    motor[motorC] = -40;    motor[motorD] = -40;    motor[motorE] = 40;    motor[motorF] = 40;}motor[motorC] = 0;motor[motorD] = 0;motor[motorE] = 0;motor[motorF] = 0;

Mon Feb 09, 2015 11:34 pm
Rookie

Joined: Mon Dec 15, 2014 9:48 pm
Posts: 16
Re: Stop encoder loop after a set time?
MHTS wrote:
 Code://Set the motor encoders to zeronMotorEncoder[motorC] = 0;nMotorEncoder[motorD] = 0;nMotorEncoder[motorE] = 0;nMotorEncoder[motorF] = 0;clearTimer(T1);//move forwardwhile (((nMotorEncoder[motorE] + nMotorEncoder[motorF]) / 2 < 600) && time1(T1) < 2000){    motor[motorC] = -40;    motor[motorD] = -40;    motor[motorE] = 40;    motor[motorF] = 40;}motor[motorC] = 0;motor[motorD] = 0;motor[motorE] = 0;motor[motorF] = 0;

Ok thanks! But will this make the robot wait two seconds even if the set encoder tics has been reached?

Tue Feb 10, 2015 2:08 pm
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Re: Stop encoder loop after a set time?
The code said while it hasn't reached target AND it's within 2 seconds, keep running. It means it will exit the loop if either it has reached target OR 2 seconds have expired.

Tue Feb 10, 2015 5:08 pm
Rookie

Joined: Sat Aug 15, 2015 5:37 am
Posts: 1
Re: Stop encoder loop after a set time?
thanks for the code worked for me

_________________
http://frecked.com/ The List

Sat Aug 15, 2015 5:43 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 5 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.