Hi,
I connected the four MeArm (Turnigy TG9e) servos to the Arduino board using pins 6, 9, 10, and 11 as shown in the MeArm instructions.
The Arduino board is powered by USB and the servos are powered using a 6V power supply with 3A.
I wrote a program to generate smooth position profiles to output to the servos. The Arduino main program (mearm.ino) connects the USB serial I/O and the servo output to the rest of the code:
#include <Servo.h>
#include "../calibration.hh"
#include "../controller.hh"
#include "../curve.hh"
class Controller: public ControllerBase
{
public:
Controller(void) {}
void setup(void) {
for (int drive=0; drive<DRIVES; drive++)
m_servo[drive].attach(SERVOPIN[drive]);
}
int offset(int drive) { return OFFSET[drive]; }
float resolution(int drive) { return RESOLUTION[drive]; }
int lower(int drive) { return MIN[drive]; }
int upper(int drive) { return MAX[drive]; }
void reportTime(void) {
Serial.print(millis());
Serial.write("\r\n");
}
void reportAngle(float angle) {
Serial.print(angle);
Serial.write("\r\n");
}
void reportPWM(float pwm) {
Serial.print(round(pwm));
Serial.write("\r\n");
}
void writePWM(int drive, int pwm) {
m_servo[drive].writeMicroseconds(pwm);
}
protected:
Servo m_servo[DRIVES];
};
unsigned long t0;
Controller controller;
void setup() {
controller.setup();
Serial.begin(9600);
t0 = millis();
}
void loop() {
int dt = millis() - t0;
if (Serial.available())
controller.parseChar(Serial.read());
if (dt >= 20) {
controller.update(dt);
t0 += dt;
};
}
Each call to the method "controller.update(dt)" causes the "writePWM" method to be called once for each servo. The servo to pin mappings and calibration values are specified in calibration.hh:
// BASE, SHOULDER, ELBOW, GRIPPER
const int SERVOPIN[] = {11, 9, 10, 6};
const int OFFSET[] = {1380, 1357, 1589, 1327};// normally around 1500
const int MIN[] = {544, 856, 544, 544};// must not be below 544
const int MAX[] = {2400, 2246, 1786, 2022};// must not be above 2400
const float RESOLUTION[] = {11.12222, 11.12222, 9.8888, 15.44444};
const float BOUND = 0.000015;
The other files (controller.hh and curve.hh) only contain platform-independent code for parsing user input and interpolating curves for the servos.
Everything works fine except after some time (ca. 15 minutes) the gripper servo will suddenly jerk and stop moving (not shown in the video above). The other servos continue to work. After power cycling the Arduino board, controlling the gripper works again. I wonder whether anybody can help? Has anybody experienced similar issues?
The full source code repository is here: GitHub - wedesoft/arduino-mearm: Arduino MeArm USB-serial terminal using Vim-like shortcuts.
arduino-mearm.zip (13 KB)

