hi, I am a beginner here. I have a SSC-32 to control my hexapod by using LynxTerm but I have some problems with the software. I tried to program using the macro but it only execute the first line of the commands. So I wondering how am I suppose to solve this problem? Besides I am trying to make this bot autonomous with a PIC controller but have no clue where to start with. Can anybody give some suggestions? Thank you.
I am using SSC-32/DB9
PIC18F452 microcontroller board
12 HS-322 servos
Since PIC microcontroller is using C and asm, I am puzzle how to send command from PIC to SSC-32? Is there any example that will help?
my robot works with lynxterm when i send individual command but when i tried to use macros by sending a few commands together, only the first line being executed. any clue why is this happening? Thanks
loc = sprintf(&buff[0], “#%02dP%d#%02dP%d”, MRHV, 1800, MRK, 1800);
loc += sprintf(&buff[loc], “#%02dP%d#%02dP%d”, MLHV, 1200, MLK, 1200);
loc += sprintf(&buff[loc], “T288\r”);
PutString(buff);
Try the strings to a terminal or terminal program to see if they are correct. MRHV, MRK, MLHV and MLK are out of a BASIC program for ATOM. This is one of the “FLY” steps. The original lines in the BASIC program are commented out here.
I am currently using the SSC-32 to control 12 servos for the hexapod, Ive read through all the manual and managed to program them using Lynxterm.
Problem: I am using the SSC-32 with the PIC18f452 like the user above, but I am not a very competent user of C and the part where I have a problem is actually interfacing the code to SSC-32 using USART. Im not sure how to do this, so if anyone could please help by just giving me a source code of C as an example to actually move 1 servo of channel 1 to any position at any speed is very appreciated (Writing the USART code, and Im sure the baud rate is crucial too)
Once I figure how to send the instruction through to the SSC-32 using USART, I will be fine I think. Thanks in advance.
First, what C compiler are you using? Look at that compiler’s examples! There are always examples for such mundane things as com (USART) support. Look for your basic “Hello World” example.
Don’t forget, you’ll have to initialize the serial port.
Do you have the hardware to try the code out on?
Once you can send a “Hello World”, substitute the above code snippit to send a command to the SSC32. Insure the baud rates match.
"#0P1500T1000"
string will command servo 0 to position 1500 (middle) in 1 second of time.
/*-------------------------------------------------------------------------*/
#define SXTAL40 25000 // Use BRGH = 1
#define SERIAL_XTAL SXTAL40
#define B115K (SERIAL_XTAL/1156)
InitSerial(B115K); /* SPBERG 115,000 baud, BRGH_1 */
/*-------------------------------------------------------------------------*/
void PutString(const char* ptr)
/*
* function to send a string to comm port
*/
{
unsigned char chr;
while(chr = *ptr)
{
PutSerial(chr);
ptr++;
}
}
/*-------------------------------------------------------------------------*/
void PutSerial(unsigned char chr)
/*
* routine to just want for xmit to be empty...BLOCKS!
*/
{
while(!TXIF); /* BLOCKS! */
TXREG = chr;
}
/*-------------------------------------------------------------------------*/
void InitSerial(unsigned char baud)
/*
* Initialize the Serial Port
*/
{
SPBRG = baud;
TXIE = 0; /* Tx ints disabled initially */
RCIE = 0; /* Rx interrupts disabled initially */
TXSTA = TXINIT; /* sets up TXEN=1, BRGH=0 */
RCSTA = RXINIT; /* sets up SPEN=1 CREN=1 */
TXEN = 1; /* enable USART transmitter. */
RCIP = 0; /* assign low priority to USART interrupts */
TXIP = 0;
RCIF = 0; /* clear recieve flag and enable receive interrupts */
RCIE = 1;
TXIF = 0; /* clear xmit flag, enable interrupts LATER */
TXIE = 0;
SPEN = 1; /* Enable serial port. */
}
/*-------------------------------------------------------------------------*/
Im using the C18 compiler for the pic18f452 and yes all hardware is available and ready to be tested on. I actually figured from the Atmel example of the SSC-32 that strings needed to be transmitted using USART to the SSC-32, but after failed trials couldnt figure what went wrong.
Code are as follow: Where the ‘Hello World’ is changed to the SSC-32 code.
Your code looks correct. Can you connect up to a terminal emulator on a PC and see the command? What baud rate is being used? I see a “21”, is that the baud rate word? If you can see you command received by the PC program, then setting the SSC32 to the same baud rate should result in the SSC32 flashing to indicate reception of the command, and servo motion. The servo will have to be powered. You can also send a command from the terminal program to the SSC32 with the same results.
I think we’ve all slightly deviated from the original question. The original question was when you stick multiple lines into a single macro function in the lynxterm, the first command is the only one that gets exectuded. For instance, the following set of commands:
#8 P1510
#8 P1600
#8 P750
is entered into a single macro, only the:
#8 P1510
Is executed. I believe that this is due to timing. When you command the servos to move, it takes a certain transit time to move to that location. During an initial move, the servos tries to scoot to its destination as fast as it can since it does not know the position, if you use the “T” arguement afterwards, it will try to scoot to that position in that time frame, but I digress…
When you are using the macro function of the lynxterm, all three of the above commands gets “shoved” into the SSC-32. To rectify this, you need to add pause statements in between for the servo that is commanded to finish moving.
I generally just shove one-line commands PER macro in ssc-32 and just wait for it to finish then press the macro. I have the gaits set up in Macro 0 through 4, so before I press macro 1 after pressing macro 0, I wait 1 sec because I have the “T1000” arguement at the end.
In a microcontroller, just add a pause statement or create your own using interrupts, polling (querying the servos until the query position equals the commanded position), empty loops, and etc. After you insert these pauses between the servo move commands, you will find that all of the moves that you sent out will be executed in that sequence (unless your servos are jammed and stalled )
I am using the MPLAB to write to code and implement it to the pic board.
It doesnt seemed to be working at all. Whenever I access lynxterm and write the specific code for the SSC-32 board, the servos are working fine.
But when I try to interface the microcontroller to the servo controller with the following code, nothing seems to happen. Ive tried using baud rates of 9600, 38.4 K and 115.2 K (configured both on the servo board and C programming code) but to no success.
When looking at the SSC-32 guide, it says something about the configuration of TTL serial com of SSC-32 and TTL serial com of Botboard. Which I dont think is relevant to mine since Im using the D9 serial cable between the SSC-32 and the pic microcontroller, configured such that jumpers are put between the TX and RX…
The ‘21’ that you see in the code corresponds to baud rate of 115.2 K, inw which using the formula gives Baud Rate = Oscillator Frequency/ (16(X+1))
The ‘21’ corresponds to X when BRGH is high or 1
I tried copy and paste your code, Ive looked through it but couldnt understand some parts of it and when I try to build, it failed.
Any help would be greatly appreciated, and oh here’s the following code that I tried to implement. Its almost the same as before, but I saw the previous code to be wrong so I changed it a little bit. Oh also, the delay should give a delay of 1 second before the next command is executed in which I dont think cause any bug.
Any suggestions is greatly appreciated. Once again Im using the C18 compiler.
Some are required for the USART. You’ll have to select config and TRIS for your chip and pin usage.
As you’re using the DB9, you’ll need it’s jumpers in place. If you can talk to the SCC32 with Lynxterm, then you’re good. Your processor board should be set up to the same speed. It will “look” like a PC as well. Try talking to the the processor board with Lynxterm. You’ll need a null modem cable. You should receive the same strings that were successful with Lynxterm.
I run everything at 115K. You sound good there.
That’s the trouble with porting code to different compilers, you always seem to need another header file, another routine…
Can you do anything else with your board? Maybe flash an LED at the 1 second rate? That would prove out a few things. (Don’t forget to configure the port bits).
Remember, you should be able to connect up your board to a terminal emulator program (Lynxterm or Hyperterm), and see strings out of it. If you can get a “Hello World” up and running, then you should be close!
I did thought of the configuration bits, however most of the time when I program my microcontroller to communicate with another microcontroller the configuration of USART was sufficient. Hence I didnt think I need to setup the Ports A,B, C, D etc especially when all I need is to send strings to another device.
As for your code yes, I think I need different compiler and header scripts for them but will try to implement it on the code as well.
I am seriously thinking that the code Im writing with the string is fine, but the term “\r” at the end isnt a byte code corresponding the carriage return and maybe need to input byte ‘13’ instead for the carriage return ASCII.
As you mentioned previously,my best bet is to communicate with the hyper terminal or lynxterm first. Thanks so much for the suggestion and I will keep you posted with the progress. Thanks again!
I also mentioned the null modem cable. Remember, both your board and the SSC32 want to talk to a PC (DTE). So BETWEEN them, you need a null modem cable.
If your board is talking to a term program (normal way one develops code for a board), then you’re almost there. If the SSC32 is talking to the term program with the same setup, then all the baudrates are correct!
You can also send “\r\n”, the SSC32 will work just fine.