View unanswered posts | View active topics It is currently Thu Apr 24, 2014 12:37 am






Reply to topic  [ 5 posts ] 
Reversing return value of nMotorEncoder 
Author Message
Rookie

Joined: Fri Jul 26, 2013 4:29 pm
Posts: 5
Post Reversing return value of nMotorEncoder
Hi everyone.

I'm trying to do the Ring it Up challenge, and I was curious as to if there was a way to reverse the value that nMotorEncoder returned. I'm having a problem where the reversed motors (on the left side of the scissor bot) will run "forwards" while the encoder still reads as if it is going backwards.

Thanks


Fri Aug 09, 2013 10:02 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 187
Post Re: Reversing return value of nMotorEncoder
Hi sifu,
Just put a "minus" sign in front of it. For example:

Code:
-nMotorEncoder[leftMotor]


Cheers,
--Ryan

_________________
Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Fri Aug 09, 2013 10:05 pm
Profile
Rookie

Joined: Fri Jul 26, 2013 4:29 pm
Posts: 5
Post Re: Reversing return value of nMotorEncoder
Thanks for the response, but there is anyway to permanently reverse the value, similar to reversing a motor in the setup. Otherwise it makes the code a bit harder to write.


Sat Aug 10, 2013 3:04 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: Reversing return value of nMotorEncoder
Mount the motor in reverse :)

= 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]


Sat Aug 10, 2013 3:34 pm
Profile WWW
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 187
Post Re: Reversing return value of nMotorEncoder
sifu wrote:
permanently reverse the value


I don't know of any way intrinsic to the ROBOTC, but you could make your own wrapper on nMotorEncoder that accomplishes this. You could make a nicer, general form if ROBOTC supported preprocessor token pasting, but here's an idea that will work:

Code:
#define getLeftMotorEncoder() (-nMotorEncoder[leftMotor])
#define setLeftMotorEncoder(val) (nMotorEncoder[leftMotor] = -(val))


Then you can use them like:

Code:
task main()
{
  //Clear Encoders
  setLeftMotorEncoder(0);

  while(getLeftMotorEncoder() < 1800)  // While less than 5 rotations on the leftEncoder...
  {
    //...Move Forward
    motor[rightMotor] = 63;
    motor[leftMotor] = 63;
  }

}


You can define similar sets of macros for each of your motors.

Cheers,
--Ryan

_________________
Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Mon Aug 12, 2013 2:18 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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.