Hi,
I’ve been trying for a while to control 8 servomotrs GS9025MG from goteck for a quadripod.
I’m using an arduino and a Micro Serial Servo Controller (8-channel) from pololu.
I found loads of different code to send command to the SSC (confusing between Micro SSC and Maestro) especially to stop the servomotors.
I finally got something nearly working but I cannot achieve full postion range with the servomotors. Also because of some jittering issue with the servos, I’d like to stop sending pulse when servo has reached the target.
Two questions to summarize:
-
Is there any mistake in my code that could explain why the servomotors doesn’t reach extreme position?
-
I tried several power supply from AA batteries to LiPo batteries and even a 0.7A charger but nothing seems to resolve the jittering issue. What should I use for 8 or more servomotors?
Thanks in advance for your help.
Xukyo
Here is the Arduino code
#include <MicroSSC.h>
MicroSSC maestro(10,11,9600);
int nbServo=8;
void setup()
{
Serial.begin(9600);
}
int FU[8]={3000,1000,3000,3000,3000,3000,1800,3000};
int BD[8]={4500,3000,1500,1500,1500,5000,3800,1000};
void loop()
{
Serial.println("Servo MIN : 1000");
for(int i=0;i<nbServo;i++){
maestro.setTarget(i, BD[i]);//6000);
maestro.stop(i);
}
delay(1000);
Serial.println("Servo MAX : 4000");
for(int i=0;i<nbServo;i++){
maestro.setTarget(i, FU[i]);//6000);
maestro.stop(i);
}
delay(2000);
}
And here is the library I wrote
//Libraries
#include "Arduino.h"
#include "MicroSSC.h"
#include "SoftwareSerial.h"
// Pin assignement
// Variables
// Parameters
#define DELAY_WRITE 30
//set up MicroSSC configuration
#define deviceId 0x01 //12
#define startByte 0x80 //
// Command list
#define setCmd 0x00 //
#define targetCmd 0x04 //
/******************************************************************\
* PRIVATE FUNCTION: Constructor
*
* PARAMETERS:
* ~ void
*
* DESCRIPTIONS:
* object constructor
\******************************************************************/
MicroSSC::MicroSSC(int pinRx, int pinTx, unsigned int baudrate)
{
pinMode(pinRx, INPUT);
pinMode(pinTx, OUTPUT);
_pinRx = pinRx;
_pinTx = pinTx;
_MicroSSCSerial = new SoftwareSerial(pinRx,pinTx);
_MicroSSCSerial->begin(baudrate);
}
/******************************************************************\
* PRIVATE FUNCTION: begin
*
* PARAMETERS:
* ~ baudrate (serial port speed)
*
* DESCRIPTIONS:
* Initialize serial port
\******************************************************************/
void MicroSSC::begin(unsigned int baudrate)
{
_MicroSSCSerial->begin(baudrate);
}
/******************************************************************\
* PRIVATE FUNCTION: setTarget
*
* PARAMETERS:
* ~ servo ID number, target specified with integer
*
* DESCRIPTIONS:
* Send sequence of command so that the MicroSSC board send the right
* pwm value to set servo to the desired position
\******************************************************************/
void MicroSSC::setTarget(unsigned char servo, unsigned int target)
{
_MicroSSCSerial->write(startByte); //start byte
_MicroSSCSerial->write(deviceId) ; //device id
_MicroSSCSerial->write(targetCmd); //command number
_MicroSSCSerial->write(servo); //servo number
if(target==0){
_MicroSSCSerial->write((byte)target); //
_MicroSSCSerial->write((byte)target); //
}else{
_MicroSSCSerial->write((target & 0x1f80) >> 7); //
_MicroSSCSerial->write(target & 0x7f); //
}
delay(DELAY_WRITE);
//_MicroSSCSerial->write(target & 0x7F); // Send first 4bits
//_MicroSSCSerial->write((target >> 7) & 0x7F); // Send last 4bits
}
/******************************************************************\
* PRIVATE FUNCTION: stop
*
* PARAMETERS:
* ~ servo ID number
*
* DESCRIPTIONS:
* Send sequence of command so that the MicroSSC send nothing to the
* the servo
\******************************************************************/
void MicroSSC::stop(unsigned char servo)
{
_MicroSSCSerial->write(startByte); //start byte
_MicroSSCSerial->write(deviceId); //device id
_MicroSSCSerial->write((byte)0x00); //command number
_MicroSSCSerial->write(servo); //servo number
_MicroSSCSerial->write((byte)0x0F); //
//_MicroSSCSerial->write((byte)0x00); //
delay(DELAY_WRITE);
// 7 6 5 4 3 2 1 0
// bit 7 0 always
// bit 6 0 off 1 on
// bit 5 direction default 0
// bit 0-4 range
// 0 0 0 1 1 1 1 1
}