The Random Function Library - mrp & bmd - Simple

mrp (move relative position) is a function that will move a motor for a set distance at a set speed. This is probably the simplest way to move a lego robot. mrp starts a motor moving. The motor will stop after the wanted distance is achieved, but the CBC will continue going through the program unless you put a bmd. bmd (block motor done) stops the program from going to the next line until mrp finishes. If mrp has already finished, bmd does nothing. Note that you would need two mrp's and two bmd's for a robot with two motors. Only put a bmd if you want the program to halt until the motor is finished. mrp's speed is out of 1000. mrp's distance is measured in "ticks." Approximately 1100 ticks are in a full wheel rotation. This is NOT an exact number because every motor is slightly different, but it is a general rule of thumb. bmd only waits for one motor before continuing. If you have two motors on your robot, you will want two bmd's. mrp and bmd look like this:

mrp's arguments go like this:

  1. mrp(**motor port**, **speed (out of 1000)**, **distance (1100 per rotation)**);

bmd's arguments look like this:

  1. bmd(**motor port**);

An example would look like this:

  1. int main()
  2. {
  3. mrp(0,1000,1100);
  4. mrp(1,1000,1100);
  5. bmd(0);
  6. bmd(1);
  7. }

This will move motors 0 and 1 at full speed for 1100 ticks (about 1 wheel rotation).

Comments

In order to know how to fix

In order to know how to fix connections to bluetooth audio devices and wireless displays in windows 10 you may switch to this platform where you can have all those information by which your work can be all easier to fix connection in windows 10 mobile. So have a visit for once surely you will be having all useful infirmation.

So can we add as many bmd and

So can we add as many bmd and mrp as required by the situation????
Eg:
int main()
{
mrp(0,1000,1100);
mrp(1,1000,1100);
.
.
.
mrp(n, 1000, 1100);
bmd(0);
bmd(1);
.
.
.
bmd(n);
}

Marty Rand's picture

Because every motor is a

Because every motor is a little different, one motor might finish the move before the other. If you just have 1 bmd, you run the risk of the robot being at angle when the move finishes because the slower motor won't have moved the entire amount. This will not be a big issue, but if you want your robot to drive perfectly straight, you should have two bmd's.

-Marty Rand
{
Senior programmer at Norman Advanced Robotics

Former senior programmer at Whittier Middle School

Youth Advisory Council

All around nerd
}

ruler501's picture

How important are the two

How important are the two bmd's? my team has always used one and it seems to work fine for us. I could see this being more useful for turns though.

Marty Rand's picture

True. 850 - 900 has been as

True. 850 - 900 has been as far as I could ever go without inducing major drift. Your results may vary.

-Marty Rand
{
Senior programmer at Norman Advanced Robotics

Former senior programmer at Whittier Middle School

Youth Advisory Council

All around nerd
}

Jeremy Rand's picture

It should be noted that 1000

It should be noted that 1000 is not usually full speed; it's just a random number KIPR made up. The actual full speed depends on the load on the motor. If you use a velocity that's too high, the motor will fall back to open-loop control (essentially the fd() function), and the robot will lose accuracy (including drift).

The correct way to deal with this is the getpwm() function. Watch the value returned by this function as your robot is moving. If it's stuck at the maximum (either 100 or 255, can't remember which), then your velocity is too high. Choose a velocity where getpwm() is not stuck at the maximum (it will fluctuate a bit; this is normal).

As an informal observation, 1000 has been way too high for several robots I've worked on. But you should find out for yourself for every robot you work on.

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS