View unanswered posts | View active topics It is currently Wed Aug 27, 2014 9:53 am






Reply to topic  [ 14 posts ] 
Doesn't Equal Command 
Author Message
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post 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
Profile WWW
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post 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
Profile WWW
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post 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
Profile WWW
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post 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
Profile WWW
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post 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
Profile WWW
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post 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
Profile WWW
Rookie

Joined: Mon Jan 03, 2011 10:52 pm
Posts: 22
Post 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
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post 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
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 14 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  



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