Go Down

Topic: SOLVED: Devantech SD21 servo contr. and desperate programmer, after one year... (Read 4 times) previous topic - next topic

GaryP

Hi all!

This is almost ridiculous, but I have to ask for help.

Our robot is getting close to a point, where the Madam of the house is ready to consider it as member of a family. Well, new born child is smarter and cuter, but hey, beauty is in the eye of the beholder, right?

Anyway, here's the problem.
SD21 takes the value for the servo position in to bytes. I have tested that it works both ways, so the mathematic is probably right.

What happens, is that when I increase the value by one on each round, servo jumps MUCH TOO MUCH when the value goes from 1529 to 1530, an daround 1540-1544 it jumps back to where it actually should be. We have to controllers, same thing. Maybe firmware problem, maybe something that I can't see in this code.

Here is my old faithful test code, this time even shorter, but functioning.

EDIT. Corrected 255 to 256
Code: [Select]

#include <Wire.h>
#define SD21 0x61 //SD21 I2C Address, shifted by one bit from original 0xC2:sta

byte ServoHigh, ServoLow;
int Pos_ms=1400;
int ServoNro=0;
int Luku;


void setup()
{
 Wire.begin();
 Serial.begin(9600);
}

void loop()
{
 Pos_ms=Pos_ms+1;

 if (Pos_ms > 1600)
 {
   Pos_ms=1400;
 }

 ServoHigh   =  byte(Pos_ms / 256);
 ServoLow    =  byte(Pos_ms - ServoHigh);

 Wire.beginTransmission(SD21);
 Wire.send(0);                 //Speed Servo 0
 Wire.send(30);
 Wire.endTransmission();

 Wire.beginTransmission(SD21);
 Wire.send(1);                 // Servo 0, Low Byte to Register 1
 Wire.send(ServoLow);          
 Wire.endTransmission();

 Wire.beginTransmission(SD21);
 Wire.send(2);                 // Servo 0, High Byte to Register 2
 Wire.send(ServoHigh);
 Wire.endTransmission();

 delay(100);
}



Electric is ok, Arduino only controls this module through I2C, controller's power is guarantee. But all servo channels do this.

Problem appears today when we started to fine tune arm positions, step by step incremental with the servo positioning.

As usual, any advice is welcome!
Thanks!

Cheers,
Kari
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"


GaryP

Oh sh...!!!!

Thank you, that was too obvious, and very typical mistakes I do all the time!
And my co-pilot needs to some lecturing too! He is supposed to watch after my coding!!!!

Thank you once more!

Cheers,
Kari
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

GaryP

Justone,
It was a good advice, but only thing that changed was the point where the error appears, it is now from 1535 to 1536 moves ahead, and from 1541 to 1542 brings back.

That's not funny... I just need to sleep over the night and try to figure it out again.
:~

Cheers,
Kari
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

justone

I just did a quick glance at first but now I see you are extracting the low and high bytes from Pos_ms. Why not just use the lowbyte and highbyte functions on your Pos_ms integer.

Go Up