I can't get my head around this one -Robot control

Howdy,

I am hacking an app that allows users to doodle onto an LCD shield and the get a robot to draw it out using pens.

The robot is a 2 wheel device and to make a turn it has to rotate x degrees.

For example:

They press up 4 times, right 6 times they get this:

I fill up an array with the following. m = 1111333333

m = moves 1 = fwd 3 = right

I can then play this back by looping over the array and all seems good. The functions for fwd and right are called in sequence to drive the motors.

Now this is where I become unstuck!

Going fwd is fine, when the bot encounters a right turn it has to rotate 90 degress, ok so far. But the command set is issuing right commands because the LCD was updated in the X axis, so the bot will do 6 right truns.

I need to create some rules that look at the last and current command. So the above example would look like

1111311111 do 4 fwds, 1 right turn, 5 fwds.

I have tried to set a variable that contains the last run command, and getting the current instruction to make a decision based on that. I can't seem to figure out how to create the rule.

Any ideas?

Cheers :-)

But the command set is issuing right commands because the LCD was updated in the X axis, so the bot will do 6 right truns.

I think I was understanding things until this sentence.

Soz, I did wonder about that when I typed it.

Because I am drawing on the LCD in x,y coords afwd will always = 1 and a right = 3

Y1 X3 X3 X3 X3 X3 X3

Y1

Y1

Y1

Going fwd is fine, it is doing one right turn and going fwd, rather than the 6 right turns it will do.

eg. This is my current code for parsing the array.

if (m == 1)
{
goForward();
} *
else if (m == 3)
_
{_
goRight();
_
} _
else if (m == 2)
_{
goBack();
}
else if (m == 4)
{
goLeft();
}
else if (m = 5)
{
goStop();
}*_

Could try separating the straight running from the turns. so, straight 6, right, straight 5, and so on.

I would think about it like this:

The 3 doesn't represent a turn, it represents movement in a different direction. The turns are represented by the change from one value to another in the array. If the user enters 5 1's and 5 3's then they want to move 5 spaces, turn, and move 5 more spaces. If you are interpreting the first 3 as a turn you will only move 4 spaces after the turn unless you work that into your logic.

I would use logic like such:

look at the element of the array that you are on, and compare it to the last element, if they are different then figure out which direction to turn (1 to 3, 3 to 1, etc), do the turn, and then process the element as forward movement.

You could also rework the drawing method to only store a 3 when there is a turn, and store 1's for the X movements, but I think that it would be more complex that way.

HTH, Rob