# Homer, our robot, gets a little intelligence!

## Comment viewing options

doing the same thing with my bot. did you have trouble dealing with the 0 point  and turning . i need to find a way to tell the robot to tern the shortest distance with a tern grater than 180 degrees , for instant if bot pointing 60 deg and i need it to tern to 350 deg the shortest distance is to tern to the left .mmm just writing that out helped i think .   in short i would like to see your code if that's ok

Zero and 360 deg crossing in movement make it difficult to use a compass for course /heading stabilization. This is why you'll not see many (if any) references on google. However, it's not impossible as the video illistrates.

Keep in mind, this is still a work in progress, that's why I've not posted complete code. I would also recommend setting this up on a test Arduino will a compass (double sided taped) so you can debug with the Serial Monitor. If you use this in a project, please acknowledge this as my code and if you modify it, please share it with me.

My approach was to sample heading whenever I change state to take a heading (setpoint), then as the robot moves repeatedly read it's updated heading and take the absolute difference to setpoint. This error is multipled by some factor to create a correction signal. I then figure out if the difference in heading is above or below the setpoint and apply this to the motor left and right speed respectively.

So ...basically... this should work...

the first routine is just to sample heading.

{

hmc6352.wake();

hmc6352.sleep();

return sensVal;

}

Next while running (polling);

/*-----------------------------------------------------

by Jim Winburn

Appiphania.com

9/2/2011

*/------------------------------------------------------

{

c = 180 - abs(180- abs(Setpoint -Input)); //take the absolute difference

d = c*10; // apply multiplier to achive desired correction response (you can replace this with a proper PID algorithm if needed)

e = (maxspeed-d); // apply correction

if (e<= 0) //if correction < 0 (negative), make it zero

{

e=0;

}

if (Setpoint - Input > 180) //test if the difference is above or below the setopint, compensating for zero and 360 crossing

{

Input +=360;

}

else if (Setpoint - Input < -180)

{

Input -=360;

}

b = Setpoint - Input;

if (b < 0) // = negative ... moving to the right ... correct respective motor speed  based on state

{

if (anfwd == 1)   //forward

{

leftspeed = e;

rightspeed = maxspeed;

}

else if (anrev == 1) //reverse

{

leftspeed = maxspeed;

rightspeed = e;

}

}

else if (b > 0) //= positive ... moving to the left ... correct respective motor speed  based on state

{

if (anfwd == 1)

{

leftspeed = maxspeed;

rightspeed = e;

}

else if (anrev == 1)

{

leftspeed = e;

rightspeed = maxspeed;

}

}

}

i will be glad to give you my code as soon as i can get it to do what i need like your self work in progress having a few issues getting to correct to the left i thinking it's me getting things a bit backwards im going to use the maths for the most part.

thank you very much for your help

I'm working on a set of algorithms for precision turns by degree as well as routines for dead-reckoning based on compass angle and odometry. I'm thinking I may eventually create a "CompassPilot" library based on this work for Arduino.

Jim

Good work in path correction indeed! I like it~

We'll post another video in the next week with all states fully integrated with stabilization. ;-)

There are two micro-controllers. The Rover has an Arduino Duemilanove buit in to the platform and i've added an Arduino Nano.

The Duemilanove takes care of the state machine for remote control (I use Chris the Carpenter's Rocket Bot on the android), the Compass - HMC 6352 http://www.sparkfun.com/products/7915  (mounted in the middle of the plexiglas platform between the Nano and the LCD), and motors drives.

The Nano takes care of processing all other sensors and communicates to the Duemilanove via interupts. If you look closely at the video, when the robot goes to the sides of the video, you'll see blue leds come on ... it's detecting the edge of the table and reversing direction. The interupts are processed via an optical isolator board (I built).

I'll take a few pov photos post on my site.

Thanks,

Jim

I am very impressed with its correction capabilities and you don't seem to have had to really separate the compass module all that much, not that I ever did see it on the platform.

I'll take a couple of close up photos this weekend ;-)

mmm...donuts!