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

problem with precise and fast motor movement
http://www.robotc.net/forums/viewtopic.php?f=1&t=259
Page 1 of 1

Author:  wertzui [ Mon Sep 24, 2007 9:19 am ]
Post subject:  problem with precise and fast motor movement

i need the motors to move at maximum speed, but at the same time very precisely.
this is the code im currently using:
Code:
task main()
{
   int i;
   int speed = 10;
   int move = 10;
   bFloatDuringInactiveMotorPWM = false;
   for (i = 0; i < 100; i++)
   {
      motor[motorB] = 0;
      motor[motorA] = speed;
      while(nMotorEncoder[motorA] < move);
      motor[motorA] = 0;
      motor[motorB] = speed;
      while(nMotorEncoder[motorB] < move);
      motor[motorB] = 0;
      motor[motorA] = -speed;
      while(nMotorEncoder[motorA] > 0);
      motor[motorA] = 0;
      motor[motorB] = -speed;
      while(nMotorEncoder[motorB] > 0);
   }
   motor[motorA] = 0;
   motor[motorB] = 0;
}


the problem is that whenever i increment the speed, the motor overshoots the desired encodervalue.

Author:  starwarslegokid [ Tue Sep 25, 2007 12:28 am ]
Post subject: 

Do you want the motors to move together accurately or do you want a motor to go to an encoder target accurately?

Author:  wertzui [ Tue Sep 25, 2007 2:22 am ]
Post subject: 

i need one motor to get to an encodertarget fast & acucurately

Author:  starwarslegokid [ Wed Sep 26, 2007 12:43 am ]
Post subject: 

RobotC comes with a command to move to target motor encoder.
The motor will move at whatever speed you choose and stop on or very close to the encoder value.

This code works well if the motor is not undergoing allot of strain, otherwise you will have to go about this a different way.

task main()
{


nMotorEncoder[motorA] = 0; // reset
nMotorEncoderTarget[motorA]=1000; //where you want to move to
motor[motorA] = 100; //move at full speed

while (true)
{
nxtDisplayTextLine(2,"Enc A=%d", nMotorEncoder[motorA]);
}

}

Author:  wertzui [ Wed Sep 26, 2007 10:44 am ]
Post subject: 

this works fine so far, but i need to know when the motor has reached the position, because i need to turn it the other way around back to encoder 0 exactly when it has reached the desired position.
e.g. move it to 20, when it has reached 20, move it to 0 and so on.

Author:  starwarslegokid [ Wed Sep 26, 2007 6:02 pm ]
Post subject: 

task main()
{
nMotorEncoder[motorA] = 0; // reset
nMotorEncoderTarget[motorA]=1000; //where you want to move to
motor[motorA] = 100; //move at full speed

while (nMotorRunState[motorA] != runStateIdle)
{
//nxtDisplayTextLine(2,"Enc A=%d", nMotorEncoder[motorA]);
}
}

When using a motor target, the motor goes through different stages of power output. Ramping up, ramping down, idle, steady state, and holding encoder value.

When in idle, the motor is not moving anymore so it is on or very close to the target.

If you want to read more on these commands, double click on Motors in the Code Templates tool bar and it will bring up descriptions and brief explanations of the different motor commands.

The encoder target works nicely with low motor strain applications, otherwise you have to take a different approach. If you are interested, check out this forum topic too.
viewtopic.php?t=234

Good Luck B-)

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