SSC-32 QP returning wrong servo position

Hey,

I was hoping someone might be able to help me. I am using an SSC-32 (the old style with the serial port) and an Arduino Nano.

I am trying to control all 32 servos and have them activated by a sensor.

The code runs fine for a couple of minutes but after that the QP seems to go out of sync somehow. I am not much of a coder but I think the code is OK.

The code is below:

[code]class Sensor {
private: byte anaPin;
public: int triggerValue;

public: Sensor(byte anaPin_) {
anaPin = anaPin_;
}
int query(){
return analogRead(anaPin);//reading;
}
};

class Flower{
private: int sscPin, startTime;
public: byte posit;
public: boolean isMoving;

public: Flower(byte sscPin_){
sscPin = sscPin_;
}
byte query(){
Serial.print(“QP”);
Serial.println(sscPin);
startTime = millis();
do {} while ((Serial.available() == 0) && millis() - startTime <1000);
posit = Serial.read();
}

Serial.print(" PULSE pulse ");
Serial.println(posit);

//delay(20);
return posit;
}
void move(int targetPosition, int targetTime){

Serial.print("#");
Serial.print(sscPin);
Serial.print(“P”);
Serial.print(targetPosition);
Serial.print(“T”);
Serial.println(targetTime);
isMoving = true;
//delay(50);
}

void moving(boolean state){
isMoving = state;
}
};

// START MAIN //

static const int openPos = 1270;
static const int closedPos = 2250;
Sensor *sensors[8];
Flower *flowers[32];
int timer, frameTime, triggerValue, count, flowerIndex, seedNumber, tolerance;
byte pulse;
boolean mov;

void setup() {
Serial.begin(9600);
triggerValue = 150;
tolerance = 1;
count = 0;
for (int i = 0; i < 8; i++) {
sensors = new Sensor(i);
}
for (int i = 0; i < 32; i++) {
flowers = new Flower(i);
}
Serial.println(“Set Up”);
for (int i = 0; i <32; i++){
flowers -> move(openPos, 1000);
//delay(200);
}
}

void loop() {

for (int i = 0; i < 1; i++){
if (sensors -> query() > triggerValue) {
//seedNumber = ceil(random(4)) + i*4;
//seedNumber = 2;
flowerIndex = ceil(random(4));//seedNumber + 2 * ( ( round((seedNumber%/2)+1 ) %3 -1);
pulse = flowers[flowerIndex] -> query();
// mov = flowers[flowerIndex] -> isMoving;
if (pulse >= closedPos/10){
flowers[flowerIndex] -> move(openPos,500);
}
}
}

pulse = flowers[count] -> query();

if(pulse >= closedPos/10 || pulse <= openPos){
flowers[count] -> moving(false);
}

if ( pulse <= openPos/10 ){

mov = flowers[count] -> isMoving;
if (!mov){
flowers[count] -> move(closedPos,650);// snap back
}
}

count = (count + 1) % 4;//2;
}
[/code]****

Any help would be gratefully received.****

I am powering the servos with 6V and the ssc-32 and Arduino with 12V.

The code is a bit messy but I have added a few lines to help debug.

After a couple of minutes say the Arduino sent a move #2 P2250 T1000

The query in the flower class prints the current position to the serial. It seems that QP3 is returning the position that servo 2 is at.

I know I could use timers in the code so I don’t need to make the queries but I would really like to get to the bottom of this.

Many thanks.

I have written some simple code to show the problem more clearly.

int triggerVal, count, startTime;
boolean isMoving[4];
int posit[4];

void setup() {
Serial.begin(9600);
triggerVal = 150;
count = 0;
isMoving[0] = isMoving[1] = isMoving[2] = isMoving[3] = false;
}

void loop() {
//Cycle through servos 0 to 3 and update position
Serial.print(“QP”);
Serial.println(count);
startTime = millis();
do {} while ((Serial.available() == 0) && millis() - startTime <1000);
posit[count] = Serial.read();
Serial.print("POSITIONNNN ");
Serial.println(posit[count]);
if (posit[count]>=225 || posit[count]<=125){
isMoving[count] = false;
}

//read sensor and open servo 0
if (analogRead(0)>= triggerVal){
if (posit[0]>=225){
if (!isMoving[0]){
Serial.print("#");
Serial.print(0);
Serial.print(“P”);
Serial.print(1250);
Serial.print(“T”);
Serial.println(650);
isMoving[0] = true;
}
}
}

//Check servo position and close if open
if ( posit[count] <= 125 ){
if (!isMoving[count]){
Serial.print("#");
Serial.print(count);
Serial.print(“P”);
Serial.print(2250);
Serial.print(“T”);
Serial.println(650);
}
}

count = (count + 1) % 4;

Again this works fine for a couple of minutes but then QP3 is returning the position of servo 0.

From the serial monitor after a few minutes:

POSITIONNNN 225
QP1
POSITIONNNN 225
#0P1250T650
QP2
POSITIONNNN 225
QP3
POSITIONNNN 225
QP0
POSITIONNNN 225
#0P1250T650 //Trigger sent
QP1
POSITIONNNN 225
QP2
POSITIONNNN 225
QP3
POSITIONNNN 225
QP0
POSITIONNNN 225

#0P1250T650
QP1
POSITIONNNN 225
QP2
POSITIONNNN 225
QP3
POSITIONNNN 194 //QP3 position changing and not QP0 as expected
QP0
POSITIONNNN 225
QP1
POSITIONNNN 225
QP2
POSITIONNNN 225
QP3
POSITIONNNN 179
QP0

Hi,

We will be investigating your issue and get back to you soon.

In the meantime, could you please provide us with one or more clear pictures of your SSC-32U and its setup/connections/etc. Make sure to clearly show all wires, power cables, jumpers, etc.

Also, please note that you are using the hardware serial interface to both connect to the SSC-32U and the USB virtual serial port at the same time. While this may work, it can certainly also cause issues.
Please connect the SSC-32U to your Arduino using a software serial connection (library details here). This is what is done with all Lynxmotion kits to allow for a proper serial connection between the BotBoarduino and SSC-32U and also allow for debugging and control by the USB virtual serial interface simultaneously.

Sincerely,

Thanks very much for your reply. I tried the software serial but the same thing is happening I am afraid.

I will send a photo tomorrow, I don’t have access to a decent camera at the minute.

Thanks again.

I should have mentioned I am using the old SSC-32

lynxmotion.com/p-395-ssc-32- … oller.aspx

not the SSC-32U.

Many thanks.

Hi,

Sorry about the mention of SSC-32U. We meant SSC-32 but are simply used to typing the other that we added a ‘U’ by habit.

We wait for your picture(s) tomorrow.

Sincerely,

I have taken the photos. Hopefully you can see. The jumpers I am using are both on the baud (I changed the rate to 115200) and the VS1=VS2 jumpers. The RX,TX are connected to pins 10,11 on the Arduino and the ground to the ground on the Arduino. The supply voltages are reading 5.02V for the servos (the red wire) and 11.55 for the boards (the yellow wire).http://i65.tinypic.com/35iugp5.jpghttp://i65.tinypic.com/3fvrt.jpghttp://i67.tinypic.com/20h24y0.jpghttp://i67.tinypic.com/59zyh.jpg