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






Reply to topic  [ 6 posts ] 
problem with precise and fast motor movement 
Author Message
Rookie

Joined: Mon Sep 24, 2007 9:16 am
Posts: 3
Post 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.


Mon Sep 24, 2007 9:19 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
Do you want the motors to move together accurately or do you want a motor to go to an encoder target accurately?

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Tue Sep 25, 2007 12:28 am
Profile WWW
Rookie

Joined: Mon Sep 24, 2007 9:16 am
Posts: 3
Post 
i need one motor to get to an encodertarget fast & acucurately


Tue Sep 25, 2007 2:22 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
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]);
}

}

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Wed Sep 26, 2007 12:43 am
Profile WWW
Rookie

Joined: Mon Sep 24, 2007 9:16 am
Posts: 3
Post 
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.


Wed Sep 26, 2007 10:44 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
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-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Wed Sep 26, 2007 6:02 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 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.