ROBOTC.net forums
http://robotc.net/forums/

Motor Encoders
http://robotc.net/forums/viewtopic.php?f=1&t=4495
Page 1 of 1

Author:  goomba5tomper [ Thu May 03, 2012 5:19 pm ]
Post subject:  Motor Encoders

OK I'm trying to learn how to use the motor encoders but everything i have tried has failed.

Can someone tell me how to program them cause everything i try the motor doesn't move at all or it will just keep going and never stop.

even a link would help, but an expert would really be great.

any tips would be helpful.
thanks :)

Author:  NeXT-Generation [ Thu May 03, 2012 5:30 pm ]
Post subject:  Re: Motor Encoders

What do you want to do with them? Can you post some of the code you've tried? Are you using the latest version of RobotC (3.08) and the latest firmware (9.12)?

P.S. Notice my rank (beneath the username) :mrgreen:

Author:  magicode [ Thu May 03, 2012 7:32 pm ]
Post subject:  Re: Motor Encoders

You need to give us more information. What platform are you using? Mindstorms or Vex? If you've tried code post it here as NeXTGeneration suggested. Take a look at the tutorials provided.
VEX: http://www.robotc.net/education/curriculum/vex/
Mindstorms: http://www.robotc.net/education/curriculum/nxt/

Author:  goomba5tomper [ Fri May 04, 2012 10:25 am ]
Post subject:  Re: Motor Encoders

i am using mindstorms

Code:
task main()
{

nMotorEncoder[motorD] = 0;  // Reset encoder
nMotorEncoderTarget[motorD] =1440; // Sets target to one full rotation

while(nMotorRunState[motorD] < 1440)
  {
    motor[motorD] = 75;
  // Wait until encoder value is reached.
}
motor[motorD] = 0;
}



from what i have read this should only be 1 rotation of the motor but it just goes and doesnt stop

Author:  NeXT-Generation [ Fri May 04, 2012 10:41 am ]
Post subject:  Re: Motor Encoders

It looks to me like your using the Hi-Technic motor controller, right? I've no experience with this, but I think that the same rules that apply to MindStorms motors apply to these.

Try this code:
Code:
task main()
{
   nMotorEncoder[motorD] = 0;  // Reset encoder
   nMotorEncoderTarget[motorD] =1440; // Sets target to one full rotation

   while(nMotorRunState[motorD] != runStateIdle)
   {
      motor[motorD] = 75;
      // Wait until encoder value is reached.
   }
  motor[motorD] = 0;
}


And this:

Code:
task main()
{
   nMotorEncoder[motorD] = 0;  // Reset encoder

   while(nMotorEncoder[motorD] <= 1440)
   {
      motor[motorD] = 75;
      // Wait until encoder value is reached.
   }
  motor[motorD] = 0;
}


You see, the problem with your original code is that the nMotorRunState[] doesn't use a number as a condition. If you want to use a number, then just read the encoder value like in my second sample. If you use nMotorRunState[], then wait for it to be equal to runStateIdle.

Do either of these work?

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/