Servo controlled by the heading of the digital compass.

I'm having an idea of modifying the servo to be controlled by the heading of the digital compass on an autonomous robot car. I saw several projects on youtube about GPS autonomous cars but they are either two servo wheels that either changes the speeds on the turn which is controlled by the heading.
my idea is..I'm having a single (180 degrees) servo attached to a dc motor. the dc motor just provides propelling motion(drive). The servo is used here to turn the dc motor to the direction of heading in that if the destination is on certain coordinates, the digital compass here controls the servo to turn the dc motor to drive towards the coordinates (heading).
So what do you think about the idea and how I could go about it.

Learn to read the compass, using the library.
Input direction (angle).
Compare both values, if both are equal make servo straight (90°).
If unequal, decide to move the servo left or right for a turn.

Make sure that the compass is not influenced by the motors or other EM sources!

Add some control for the DC motor, so that your robot can start and stop.

It seems to me that the difficult part is working out what compass direction you need to give to get to a specified location if you only have its coordinates. At all times you will need to know the current coordinates/location of the car and then keep adjusting your heading depending on that. I'm not sure how you plan to do that part but it sounds like an interesting project.

Steve

slipstick:
It seems to me that the difficult part is working out what compass direction you need to give to get to a specified location if you only have its coordinates. At all times you will need to know the current coordinates/location of the car and then keep adjusting your heading depending on that. I'm not sure how you plan to do that part but it sounds like an interesting project.

Steve

My car is equipped with a GPS module with a digital compass for the heading. Once it receives the coordinates, its when the compass controls the servo during the turn to be taken to that destination

Steering a vehicle towards a given heading is easy and has been done many, many times. Your project is different only in the steering mechanism, but you have not explained it well.

Post a clear diagram and explanation showing how the steering will work.

The steering mechanism looks simple to me: a three wheeler with the driven and steered wheel turned left/right by a servo.

I think there are projects for autonomous airplanes that involve something I think called "ardupilot" that involves the arduino. You might look for those projects and see if they are a fast source of info and code.

DrDiettrich:
The steering mechanism looks simple to me: a three wheeler with the driven and steered wheel turned left/right by a servo.

yes.

Hi,
Can you post a picture of your project please, showing us how you have the servo and motors connected and layed out?

Thanks.. Tom. :slight_smile:

DrDiettrich:
Learn to read the compass, using the library.
Input direction (angle).
Compare both values, if both are equal make servo straight (90°).
If unequal, decide to move the servo left or right for a turn.

Make sure that the compass is not influenced by the motors or other EM sources!

Add some control for the DC motor, so that your robot can start and stop.

start and stop is to be controlled by line follower which controls the motor to move along the line while guided towards the coordinates.

What's the use of a compass for a line follower?

DrDiettrich:
What's the use of a compass for a line follower?

knowing the desired destination or stop point.

I've also tried to come up with a code for heading controlling the servo.i would like your views about it.anything that should be added or removed or any ideas about it.

void controlServo(int direction)
{int headingAngle;
float headingDegrees;
   headingAngle=headingDegrees;
  if(headingAngle=0){
    myservo.write(90);
  }
  else if(headingAngle=headingDegrees){
    myservo.write(headingDegrees);
  }
}

Understand that "=" denotes an assignment while "==" denotes a comparison.

Why not simply

   myservo.write(headingDegrees-headingAngle+90);
void controlServo(int direction)
{int headingAngle;
float headingDegrees;
   headingAngle=headingDegrees;

At this point the value of headingDegrees is undefined.

TheMemberFormerlyKnownAsAWOL:

void controlServo(int direction)

{int headingAngle;
float headingDegrees;
  headingAngle=headingDegrees;


At this point the value of headingDegrees is undefined.

Yes,i yet dont know the headingDegrees unless i have the digital compass in action

DrDiettrich:
Understand that "=" denotes an assignment while "==" denotes a comparison.

Why not simply

   myservo.write(headingDegrees-headingAngle+90);

would you please give a brief explanation about your code statement?

   myservo.write(headingDegrees-headingAngle+90);

Hi,
What model Arduino are you using?

Tom... :slight_smile:

TomGeorge:
Hi,
What model Arduino are you using?

Tom... :slight_smile:

Arduino Mega 2560