— Move to Relative Position (MRP)

As previously mentioned, the “move to relative position” function is one of the ways we can move our motors with more fine-tuned control.

Remember how the mav() function used two parameters: port and velocity?

The mrp() function has three: port, speed, and position.

  • The port number is the same as in the motor function and mav function.
  • The ‘speed’ has the same units as velocity in the mav function: up to 1000 ticks/second.
  • The position is in ticks: 1 per 1100th‘s of a rotation, or 360/1100 degrees/tick.    (the polarity of the position determines the direction of the speed)

So let’s modify our move forward program using mrp(). [Plugging our motors into ports 0 and 3]

int main()

{

mrp(0,500,500);

mrp(3,500,500);

msleep(1000);

ao();

}

So this program will still make the robot go straight forward, but this time it will only go until the wheel has rotated 500/1100 times – almost half-way around. At that point the motors will hold position until the sleep function completes and the motors turn off.  What happens if you double the stop position without changing the sleep value?   To allow the motors to finish the move we can use another function, bmd(x), where ‘x’ is the motor port.  This stands for “Block until Motor is Done” , and can replace the msleep() delay.  In this program bmd is only needed for one motor, since they are both moving at the same speed to the same position, but you can block the processor for both motors to be safe.  Try it with one motor stopping at a bigger position change.

To calibrate the relation between physical motion and ‘ticks’ select the ‘Opening Screen’ display – ‘Sensors/Motors’,  then ‘Motor’/’Test’

MotorTest

First select the motor port # using the arrows in the upper left (0 shown) and select ‘position’ (as shown).

Then select the target speed (a pop-up pad will be provided to enter a value) and a target position ( with a second pop-up).  Hit ‘Clear’ in the lower left, and ‘GO’ to run the motor.  The robot will pivot about the other wheel until the position (in ticks) is reached.  Adjust the position and repeat until the robot rotates 180 degrees (pi radians).  You can then calculate the physical position covered, which is  an arc of 1/2 the circumference, or pi*r, where r=the radius, or the axle distance between the wheels.  For example if the wheels are 15 cm apart, the arc distance will be 47 cm for a pivot of 180 deg.  Hit Clear again and the robot will pivot another 180 degrees, or hit the GO button again (which turned into a ‘stop’ sign) to stop.

Thus the pivot turn calibration is <#of ticks entered>/47, in ticks/cm  [this calibration constant also applies to straight motion if both motors at the same rate.]

– or <#of ticks>/180  for the angle calibration in ticks/deg

To use a spin turn, since a spin has both wheels moving,  the bot turns at twice the rate :

                                                <# of ticks>*2/180 = <#of ticks>/90  ticks/deg.

If you have want to turn as a veer the turn rate depends upon radius of the inner and outer wheel and is determined by the wheel (motor) speeds:  For example, if the inner wheel follows a radius that is same as the distance between the wheels, then the outer wheel follows twice that radius, and the outer wheel turns at twice the rate of the inner one.  If the inner wheel is controlled by the mrp to a position calibrated for a 180 deg. turn, then the outer motor should be set at twice the speed, using mav and the total rotation would be 180 deg.

However, if inner and outer radius is kept at the same values, with same ratio of 2 over the inner radius, and the outer motor is controlled by mrp to same position, then the inner motor must be set to half the speed with mav, and the total turn would be just 90 deg. [try it.]  The same result could be had by controlling the inner motor to 1/2 the position, using the same control as above.  Which method should be more accurate?

NEXT: Sensing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s