I am trying to figure out how to use the full range (180 degrees) of the servo on my robot using the Maestro Micro 6-channel Servo Controller. I have been doing various tests in a simplified environment so that I can learn what I need to do. I started with DavidEGrayson’s code from this forum post: Pololu maestro and arduino again.
David mentions that this code assumes a target range between 4000 and 8000. I’m not sure where the 4000 to 8000 comes from or how it’s applied in the code. I assume it may be for a servo that is controlled with a range of 1000 to 4000 milliseconds. In my case, I have a Hitech Servo HS-422 (servocity.com/html/hs-422_super_sport_.html), which has an input range of 600 to 2400 microseconds for 0 to 180 degrees
Here is my code.
void setup()
{
Serial3.begin(9600); // set up Serial communication with Maestro Micro 6-channel Servo Controller
// Serial Port #3 on Arduino Mega 2560
}
void loop()
{
set_target(1,0);
delay(1000);
set_target(1,180);
delay(1000);
}
void set_target(unsigned char servo, unsigned int servo_position){
int target = map(servo_position,0,180,2400,9600);
//Send a Pololu Protocol command
Serial3.print(0xAA,BYTE); //start byte
Serial3.print(0x0C,BYTE); //device id
Serial3.print(0x04,BYTE); //command number
Serial3.print(servo,BYTE); //servo number
Serial3.print(target & 0x7F, BYTE);
Serial3.print((target >> 7) & 0x7F,BYTE);
}
Note that I’m using an Arduino Mega and I’m using the hardware serial #3. Also, I’m feeding an angle in degrees (0 to 180 degrees) into the function and then mapping it to the quarter-microseconds.
This sketch (and all the other variations I’ve tried) causes the servo to move 90 degrees rather than 180. Plugging in 4000 to 8000 microseconds (i.e. after removing the map function) also causes it to travel 0 to 90 degrees.
I don’t know how to change this little sketch to correspond to my 600-2400 microsecond range servo (2400 to 9600 quarter-micro-second range).
Can someone help me?