Pages: [1]   Go Down
Author Topic: Need help sending commands to a servo controller  (Read 476 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone!

I have an Arduino Mega, and a servo controller that can control up to 16 servos. The arduino is sending commands through a Tx pin 18 to the servo controller. This servo controller also plugs in to my computer via USB port. I have fine tuned the code on the computer, its using Processing (Arduino is based off this, I think). There are a few subtle differences between Processing and Arduino. One difference is Arduino doesn't seem to have a way to convert hex to char or whatever else. Below is a piece of code from Processing, and the last line has the 'unhex' function. This code works fine in Processing and will control the servos. Basically the proper syntax for controlling the servos through this controller has many parts and types of variables. The 0D originates from $0D which seems to be an old representation of 'Carriage Return'. I put the position of the servo I want in to 'servopwm' and the servo I want to control in to 'servoCh', a range of 0 - 15. Since Arduino doesnt have the 'unhex', does anyone have any ideas how I might go about converting 0D so the servo controller understands it as a 'Carriage Return' without using 'unhex'. I have tried a number of things already. I tried 'char(13)', 'char(int("0D"))'. I have also verified that the source controlling the servos is passing data properly, and the little data LED on the servo controller is flickering. I'm certain its getting data, just not in the proper format. I'm sure there's a way around this. Any help is greatly appreciated! Thanks!

Code:
void zxservo() {
  servopwm = constrain(servopwm, 250, 1250);
  int highBytes = int(servopwm / 256);
  int lowBytes = servopwm - (highBytes * 256);
  char lowChar = char(lowBytes);
  char highChar = char(highBytes);
  com2.write("!SC" + servoCh + servoRa + lowChar + highChar + char(unhex("0D")));
}
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4258
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does the unhex() function turn "0D" into ?  Can't you simply put that at the value of the string that you create ?

Carriage Return is represented by \r on the Arduino if that is any help.
« Last Edit: February 10, 2013, 04:02:42 am by UKHeliBob » Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The reference shows the byte and bit manipulation functions: http://arduino.cc/en/Reference/HomePage
Like lowByte() and highByte.

The Arduino uses C++ and C code. You can use the character '\r' or a constant 0x0D or "\x0D" in a string.
Logged

0
Offline Offline
Tesla Member
***
Karma: 144
Posts: 9614
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you have a link to the command protocol for the mysterious servo controller?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Edison Member
*
Karma: 9
Posts: 1016
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm guessing it is a Parallax Servo Controller : http://www.parallax.com/Store/Accessories/MotorServos/tabid/163/CategoryID/57/List/0/SortField/0/Level/a/ProductID/595/Default.aspx

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I will try '\r' as a carriage return! I think that might do the trick. Here is a link to the PDF detailing the servo controller. I really appreciate the help!

http://www.robotshop.com/content/PDF/manual-zxservo16u.pdf

Also I did notice the first time I copied the code into Arduino, the lowByte and highByte were showing as functions, so I just changed them to lowBytes and highBytes so I could use them as variables. I will look further into how to use them as functions.
Logged

Pages: [1]   Go Up
Jump to: