View unanswered posts | View active topics It is currently Tue Feb 09, 2016 9:56 am

 Page 1 of 1 [ 14 posts ]
 Print view Previous topic | Next topic
Doesn't Equal Command
Author Message
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Doesn't Equal Command
Here is the code that I am using currently.

 Code:void goDrive(const int nDistanceLeft, const int nDistanceRight, const int speedVariableLeft, const int speedVariableRight){  nMotorEncoder[leftMotor] = 0; // reset left motor shaft encoder  nMotorEncoder[rightMotor] = 0; // reset right motor shaft encoder  while(nMotorEncoder[leftMotor] < (132.96 * nDistanceLeft) && nMotorEncoder[rightMotor] > -(132.96 * nDistanceRight)) // while left shaft encoder is less than distance value and right shaft encoder is greater than distance variable to action  {    motor[leftMotor] = speedVariableLeft; // set motor speed based on variable when it meets the criteria of the while    motor[rightMotor] = speedVariableRight; // set motor speed based on variable when it meets the criteria of the while  }}

My question is that I want to be able to set the encoders to be 'not equal to' rather than 'less than' or 'greater than'. Is this possible (I was thinking that != would work) but I wanted to check...

Mon Jan 03, 2011 10:57 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3618
Location: Rotterdam, The Netherlands
Re: Doesn't Equal Command
Your assumption is correct. != means not equal to.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Tue Jan 04, 2011 12:32 am
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Re: Doesn't Equal Command
My next question:

How likely is that to work how I want it to... i.e. once it gets to that point it stops. I believe the motors should be on a break, but considering that the robot will be moving, I believe that it is most likely that it could just get to it, momentum rolls it past the point and then it continues.

*I will be testing it for sure tonight* But any insights or tips are appreciated.

Tue Jan 04, 2011 10:08 am

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3618
Location: Rotterdam, The Netherlands
Re: Doesn't Equal Command
Well, I think a range is a much better thing to use If you miss it by a fraction, the robot will continue as if it never happened.

Have you considered using nMotorEncoderTarget[]?

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Tue Jan 04, 2011 10:55 am
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Re: Doesn't Equal Command
I'm not too familiar with how the nMotorEncoderTarger[] works, and since im at work I can't exactly play with the code.

If I use this target, what would the code need to look like? Would I just set the target and and motor power? Would this be the code?

 Code:void goDrive(const int nDistanceLeft, const int nDistanceRight, const int speedVariableLeft, const int speedVariableRight){  nMotorEncoder[leftMotor] = 0; // reset left motor shaft encoder  nMotorEncoder[rightMotor] = 0; // reset right motor shaft encoder  nMotorEncoderTarget[leftMotor] = (132.96 * nDistanceLeft)  nMotorEncoderTarget[rightMotor] = -(132.96 * nDistanceRight)  {    motor[leftMotor] = speedVariableLeft; // set motor speed based on variable when it meets the criteria of the while    motor[rightMotor] = speedVariableRight; // set motor speed based on variable when it meets the criteria of the while  }}

Tue Jan 04, 2011 12:01 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3618
Location: Rotterdam, The Netherlands
Re: Doesn't Equal Command
More like this:
 Code:void goDrive(const int nDistanceLeft, const int nDistanceRight, const int speedVariableLeft, const int speedVariableRight){  nMotorEncoderTarget[leftMotor] = (132.96 * nDistanceLeft);  nMotorEncoderTarget[rightMotor] = (132.96 * nDistanceRight);  motor[leftMotor] = speedVariableLeft;   motor[rightMotor] = -speedVariableRight;  while ((nMotorRunState[leftMotor] != runStateIdle) && (nMotorRunState[rightMotor] != runStateIdle)) {    EndTimeSlice();  }}

Target is always relative and positive. A negative value means that it will "float" the motor when the target is reached. The speed determines the direction. If you do insist on resetting the tachos, be sure to add a 100ms wait between the reset and the setting of a new target.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Tue Jan 04, 2011 12:10 pm
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Re: Doesn't Equal Command
So since the target is relative, it doesn't matter the direction that I am going, it takes the absolute value of the rotations?

I didn't know this, this surely makes life a touch easier for me.

Tue Jan 04, 2011 12:23 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3618
Location: Rotterdam, The Netherlands
Re: Doesn't Equal Command
Why do all the work when you can have the FW do it for you

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Tue Jan 04, 2011 12:24 pm
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Re: Doesn't Equal Command
 Code:void goDrive(const int nDistanceLeft, const int nDistanceRight, const int speedVariableLeft, const int speedVariableRight){  nMotorEncoder[leftMotor] = 0;   nMotorEncoder[rightMotor] = 0;   while(nMotorEncoder[leftMotor] < (132.96 * nDistanceLeft) && nMotorEncoder[rightMotor] < (132.96 * nDistanceRight))   {    motor[leftMotor] = speedVariableLeft;     motor[rightMotor] = -speedVariableRight;   }}

 Code:void goDrive(const int nDistanceLeft, const int nDistanceRight, const int speedVariableLeft, const int speedVariableRight){  nMotorEncoderTarget[leftMotor] = (132.96 * nDistanceLeft);  nMotorEncoderTarget[rightMotor] = (132.96 * nDistanceRight);  motor[leftMotor] = speedVariableLeft;  motor[rightMotor] = -speedVariableRight;  while ((nMotorRunState[leftMotor] != runStateIdle) && (nMotorRunState[rightMotor] != runStateIdle)) {    EndTimeSlice();  }}

Ok... so both of these codes should do the exact same thing... or do they? If the encoder target goes past what the target actually is (as was my concern earlier), will it reverse direction to bring it back in line with the target? (this is more for finding a spot on the field and staying where I want to)... or would this need to be done with an if statement, etc.

Tue Jan 04, 2011 1:32 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3618
Location: Rotterdam, The Netherlands
Re: Doesn't Equal Command
No, it will actually make sure that the motors get to the exact position you instructed them to. It will stop them at the correct spot.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Tue Jan 04, 2011 2:07 pm
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Re: Doesn't Equal Command
OK! Thanks! Sorry for so many posts this morning. Time to change this up on my lunch break and test it tonight.

Thanks!

Tue Jan 04, 2011 2:13 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3618
Location: Rotterdam, The Netherlands
Re: Doesn't Equal Command
Why be sorry? If you have questions, ask them and if I think I have an answer, I'll give it to you

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Tue Jan 04, 2011 2:16 pm
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Re: Doesn't Equal Command
Xander,

I've made the necessary changes. I will test them tonight and let you know how everything goes!

Thanks for the help.

Tue Jan 04, 2011 4:12 pm

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3618
Location: Rotterdam, The Netherlands
Re: Doesn't Equal Command
No worries, let me know how it goes.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Tue Jan 04, 2011 4:15 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 14 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    2014 Robotics Academy Summer of Learning    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