I'm wanting to drive two servos using the SlowMotionServo Library:
This library built is on top of Servo.h and drives the speed and angle of the servo. Instead of specifying the angle of the servo it wants a decimal value between 0 and 1.
I want to drive the servos from a floating point dual array as seen in the sketch below ( this is a simplifed example of a larger and more complex sketch but drives at the issue I'm having).
I'm I not doing something proper to pass the floating point value from the array to the write servo function servoY.goTo(). When I run the sketch my serial monitor (using ATTiny84) show that the array value passed to the servo write function is 0.00 ?
servo Y value = -0.0000000000
array table position =1
servo X value = 0.0000000000
servo Y value = 0.0000000000
array table position =2
servo X value = 0.0000000000
servo Y value = 0.0000000000
array table position =3
servo X value = 0.0000000000
servo Y value = 0.0000000000
array table position =4
servo X value = 0.0000000000
servo Y value = 0.0000000000
array table position =5
servo X value = 0.0000000000
servo Y value = 0.0000000000
array table position =6
servo X value = 0.0000000000
servo Y value = -0.0000000000
array table position =7
servo X value = 0.0000000000
servo Y value = 0.0000000000
array table position =8
servo X value = 0.0000000000
servo Y value = 0.0000000000
array table position =9
servo X value = 0.0000000000
servo Y value = 0.0000000000
Do I need to convert the floating point array value or characterize it in some manner for it to read the proper floating point value?
#include <SendOnlySoftwareSerial.h>
SendOnlySoftwareSerial mySerial(1); // Tx pin
#include <Servo.h>
#include <SlowMotionServo.h>
SMSSmooth servoX; // create servo object to control a servo with sinusoidal trajectory
SMSSmooth servoY;
const int servoPinX = 5; // X axis (left/right) the digital pin used for the servo
const int servoPinY = 6; // Y axis (Spin on Y) the digital pin used for the servo
int servo_table_position;
float servoX_value;
float servoY_value;
int table_array_positions = 10;
const float movement_table[2][10] PROGMEM = {
//1st table value is servoY postion, 2nd table value is myservoX position
/* 0 */ { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 },
/* 1 */ { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0 },
};
void setup() {
mySerial.begin(9600);
delay(700);
servo_table_position = 0;
servoY.setPin(servoPinY);
servoX.setPin(servoPinX);
servoY.setMin(544); //The value can range from 544 to 2400.
servoY.setMax(2400); //A value lower than 544 will be reset to 544 and a value greater than 2400 will be reset to 2400.
servoX.setMin(544);
servoX.setMax(2400);
servoY.setSpeed(3.5);
servoX.setSpeed(3.5);
servoX.setReverted(false); // Reverse the movement. By default reverted is false. If set to true, the trajectories are mirrored across an axis at time = 0.5.
servoY.setInitialPosition(90); // servo at 90 degrees
servoX.setInitialPosition(0); // servo at 90 degrees
SlowMotionServo::update();
}
void loop() {
servoX_value = movement_table[1][servo_table_position];
servoX.goTo(servoX_value); // X axis servo sweep
mySerial.print("servo X value = ");
mySerial.println(servoX_value,DEC);
servoY_value = movement_table[0][servo_table_position];
servoY.goTo(servoY_value); // X axis servo sweep
mySerial.print("servo Y value = ");
mySerial.println(servoY_value,DEC);
if (servo_table_position > table_array_positions - 1)
servo_table_position = 0;
mySerial.print("array table position =");
mySerial.println(servo_table_position);
SlowMotionServo::update();
servo_table_position++;
delay(1000);
}