Delta_G:
Yes, you have. These lines:
servo.attach(pin, min, max);
writeAngle(startAngle);
Shouldn't be in the constructor. They need to be in some method you can call from setup.
hmmm i updated my class to this
``class joint {
private:
int angleMax; //upper limit of the servo
int angleMin; // lower limit of the servo
int secMax; // milisecond max
int secMin; // milisecond min
double angle; // current angle
double debug;
double ratio;
Servo servo; //servo object
public:
double getAngle() {
return angle;
}
void writeAngle(double pos) {
angle = floor(pos * 100 + 0.5) / 100; // rounds angle to 2 decimal places
angle = constrain(angle, angleMin, angleMax); //safty to stop angle being greater then where it should move
int value;
value = round(angle * ratio) + secMin; //maps the angle to miliseconds
//debug = value;
servo.writeMicroseconds(value); //writes milis to the servo
}
void writeMicroS(int pos) {
pos = constrain(pos, secMin, secMax); //safty to mkae sure the angle is safe
angle = floor((pos - secMin) / ratio * 100 + 0.5) / 100; //converts milis to anlge
servo.writeMicroseconds(pos);
}
double getDebug() {
return servo.readMicroseconds();
}
void attach (byte pin, int min, int max, double startAngle, int pAngleMin = 0, int pAngleMax = 180) {
//set up for joint
angleMin = pAngleMin;
angleMax = pAngleMax;
secMin = min;
secMax = max;
servo.attach(pin, min, max);
writeAngle(startAngle);
ratio = double(secMax - secMin) / (angleMax - angleMin);
}
};
and called that method in the setup
joint shoulderIn;
joint shoulderOut;
joint upperArm;
joint elbow;
joint wristIn;
joint wristOut;
void setup() {
shoulderIn.attach(13, 500, 2500, 0);
shoulderOut.attach(12, 500, 2550, 90);
upperArm.attach(11, 550, 2400, 0);
elbow.attach(10, 700, 2300, 0, 0, 145);
wristIn.attach(9, 500, 2500, 90);
wristOut.attach(8, 500, 2500, 90);
Serial.begin(9600);
}
but it hasnt seemed to make any difference