Go Down

Topic: Need help sending commands to a servo controller (Read 545 times) previous topic - next topic

Xenophage

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: [Select]

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")));
}

UKHeliBob

#1
Feb 10, 2013, 09:58 am Last Edit: Feb 10, 2013, 10:02 am by UKHeliBob Reason: 1
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.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Krodal

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.

zoomkat

Do you have a link to the command protocol for the mysterious servo controller?
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Krodal

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


Xenophage

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.

Go Up