Using ssc-32 and Arduino together

Thank you, I now can move right to the real experiment! About my application, it is an inverted pendulum robot. I have Arduino, SSC-32, IMU, IRs, Ping and 4 reflectors (to set up optical encoders). Servos are going to be 2 continuous rotations, and I could put them on a single Arduino, but to learn the communication system of SSC-32 I am doing this way. Any your comment is very welcome: I am a novice in the field :wink:

My Arduino has a USB, not DB9, and I have to use its output pins of TX and RX. In this case, RX from Arduino, goes to the TX of SSC-32, and TX from Arduino goes to the RX of SSC-32, right? :slight_smile:

I would verify this in the datasheet for the module but those are probably 3.3V TTL level signals. I can’t say for certain, you may need to post on an Adruino specific forum, but if the connections are 5V tolerant then it should be ok to connect them directly to the TX and RX pins of the SSC-32, the ones labeled 14 in the user manual. If they are not 5V tolerant then you will need to put some resistors in series or possibly a buffer of some sort. I can’t say for certain but it is a common enough issue with interfacing different modules together that it should be easy to get an answer in the Arduino support forum if needed. The SSC-32 TTL lines are from a controller running at 5V so just need to be a little careful there and do a little fact checking before just slapping it together.

If I understand the concept of “inverted pendulum robot” then it is something that balances itself on two wheels? You may want to keep in mind when coding that there is a time delay between sending a command and having it acted upon at the motors. This is because the serial communication need to occur and that takes a few hundred microseconds at least and possibly more if a lower end baud rate is used. the other fact to consider is the servos are only updated 50 times a second, i.e every 20mS, so be conscious of that fact when working out your code. the only type of this robot I’ve seen before had direct control of the h-bridges driving the motors and updated at several kHZ rate. this made for a very responsive control of the motor torque, but whether that was necessary or not I do not know. good luck and keep us posted, maybe pictures of your assembly, as you progress.

sure, thank you for valuable comments. Please also let me know, if I put pictures when read, here, or a special part of forum? I didn’t find an exhibition forum index, may be it is called different? :wink:

Well just to make sure again:

I read this:
The Arduino Duemilanove has a number of facilities for communicating with a computer, another Arduino, or other microcontrollers. The ATmega168 provides UART TTL (5V) serial communication, which is available on digital pins 0 (RX) and 1 (TX)…

here:
arduino.cc/en/Main/ArduinoBoardDuemilanove

so that, I can connect the RX/TX from Arduino to TX/RX on SSC-32 right? :slight_smile:

ah sure. hmmm… that’s kind of an odd way to connect stuff (in the schematic of the arduino) as its sort of sharing the TTL serial lines between the USB adapter (FTDI FT232RL, FTW) and ports 0, 1. I see there is a 1K resistor between the connections but just keep in mind if you send something to the Arduino with the SSC-32 attached (and powered) then it is going to see the characters as well, and if the SSC-32 isn’t powered it might drag down those lines such that the PC can’t talk to the Arduino boot loader or whatever it’s using. Depending on how often you plan on re-programming the Arduino it might be worthwhile to put a two-pole switch in series with the TXD and RXD lines between the SSC-32 and Arduino. Something like a Radio Shack 275-407 or 275-403 would work fine.

Ok, well, first I tried and I was wrong in my programming and nothing worked! then I found this tutorial that helped to understand what you say better, so I put the link here may be helpful to others too :slight_smile:

learnhub.com/lesson/page/7448-mo … an-arduino

If here something is not right, please tell me:

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

void loop() {
  move(1, 2000, 100);
  move(1, 1000, 100);
}

void move(int servo, int position, int time) {
  Serial.print("#");
  Serial.print(servo);
  Serial.print(" P");
  Serial.print(position);
  Serial.print(" T");
  Serial.println(time);
  delay(time);
}

I have one more question:
Well my servo is continuous rotation. If I want it to go forward for 10 seconds, and then, say, backward for 15 seconds, how should I code it?

thank you :slight_smile:

generally speaking continuous rotation servos are normal servos where the feedback pot has been disconnected from the output shaft and replaced with a voltage divider that approximates 0 degrees position. what this means in english is sending 1500ms should be a stopped condition for the motor because the servo control board in the servo thinks the shaft is at 0 degrees. if you give the servo a slight longer or shorter pulse the servo control board will attempt to position the motor at the new angle, however becaue the voltage that represents that angle is a hard-wired constant the motor will just continue to turn. usually the range of 0rpm to full speed is fairly small in terms of change from 1500ms… I think I recall it being as low as +/- 100.

for your example, granted here I don’t know which adjustment direction is CW vs CCW, just pick CW to be +100 and CCW to be -100. Thus you would send 1400, delay for the 10 seconds, then send 1600, delay for 15 seconds, then send 1500 to stop moving.

The Hitec servo motors have a positive pule to direction relationship. ~1500 will stop the motor, shorter pulses will rotate CCW, longer pulses will rotate CW.

Lets assume “forward” is CW rotation, you would send this.

#0 P1500 cr #0 P2000 T10000 cr (pause for 10 seconds) #0 P1000 T15000 cr (pause for 15 seconds)

Actually Jim that code will accelerate for 10 seconds, then decelerate for 15 seconds. It will take well over a second for it to get moving at top speed, then it will take well over a second to decelerate back to 0 and another again well over a second to accelerate back up to full speed in the opposite direction. Maybe it was your intention to introduce ramp up / ramp down in your example by way of adding the T parameter to the string. It is an important difference though from what I posted which will just bang from stop to full CW to full CCW to stop. :wink:

Doh! That’s what I get for posting before I’m fully awake. lol

You’re right. :blush: Sorry for the confusion.

#0 P1500 cr (motor stopped waiting for command to move forward) #0 P2000 cr (pause for 10 seconds) #0 P1000 cr (pause for 15 seconds)

Hey Eddie, you’re starting a lot of posts with “actually Jim” lately :slight_smile: I need to pay better attention. lol

Sorry. No disrespect intended. :frowning:

Ah, none taken! I have just been burning the candle at both ends lately. lol

I really appreciate the help! :smiley:

well would you please explain for non-English people, what is:

…burning the candle at both ends lately
please? )

Um, well it’s an idiom for working long hours with little rest. Not sure of the origin.

it makes more sense in the non-abridged version of “burning the candle at both ends of the day”, which in the old days meant it was before dawn when you got up to go to work and after twilight by the time you got home. Of course this time of year the people living way north kind of experience that effect implicitly anyway. :wink:

Um, Eddie you forgot “actually Jim” lol :smiley:

That makes a lot more sense now, thanks. :wink:

“Actually jim”, LOL,
I tried to implement the code you recomended:

#0 P1500 cr
#0 P2000 T10000 cr
(pause for 10 seconds)
#0 P1000 T15000 cr
(pause for 15 seconds)

in this way with Arduino:

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

void loop() 
{ 
    Serial.println("#0 P1500"); 
    Serial.println("#0 P2000 T10000"); 
    delay(10000);
    Serial.println("#0 P1000 T15000");     
    delay(15000); 
}

But it does not work as I expect! the speed of motors in different turning in the loop are different, but my power source is not a battery to say that it falls down.

Well, all of my effort to lean ssc 32 is for my aim is to study Kalman filtering, where my KF code is ready, but I can’t command motors with ssc 32 so that the robot passes a square of 50cm, again and again.

considering the Arduino structure as I provided above, how do you code it? may be you know how to do it right?
Thank you!!!

Not you too! Doh!

Actually arash, that was my first incorrect code. This is the corrected code.

#0 P1500 cr
#0 P2000 cr
(pause for 10 seconds)
#0 P1000 cr
(pause for 15 seconds)