Does anyone know how write the Basic code for the CH3-R in C? Or give me some pointers on how to go about writing the program. I have the Basic code, and I have been trying to understand it, but it is not working well for me. I have assembled the robot for a while now and I have a microcontroller that uses C or assembly that I want to use instead of the Basic Atom.
a couple of pretty basic questions… first are you looking to replace both the atom and the ssc-32 or are you retaining the ssc-32 and just want to use your own controller?
second question is based upon the latter configuration, have you managed to write application code that can send serial strings to an ssc-32 and demonstrate simple control over the servos in your CH3-R?
I am keeping the SSC-32 and replacing the basic atom, yes I have my own controller, but it is a PS2 controller. No I have not written any codes yet that can send serial strings to the SSC-32, and also the microcontroller that I am using is the ATmel 168.
You can write the same algorithms in C that are in the CH3-R program. What you won’t get is the PS2 interface code.
You’ll also need to write a simple RTOS, that is. you’ll need an interrupt driven by one of the timers to allow you to run some tasks in the background.
Ask your questions about the CH3-R code, and we’ll tell you how it operates. What C code have you been written so far?
I have an 18F4620 in C running my hexapod.
Alan KM6VV
Does anyone understand what this portion of the basic code for the CH3-R and how to write it in C.
serout SSC32,i38400,"#", |
RRHH,RRHH2,“po-33 #”,RRHV,RRHV2,“po0 #”,RRK,RRK2,“po0 #”, |
MRHH,MRHH2,“po0 #”,MRHV,MRHV2,“po0 #”,MRK,MRK2,“po0 #”, |
FRHH,FRHH2,“po0 #”,FRHV,FRHV2,“po0 #”,FRK,FRK2,“po0 #”, |
RLHH,RLHH2,“po0 #”,RLHV,RLHV2,“po0 #”,RLK,RLK2,“po0 #”, |
MLHH,MLHH2,“po-100 #”,MLHV,MLHV2,“po0 #”,MLK,MLK2,“po93 #”, |
FLHH,FLHH2,“po100 #”,FLHV,FLHV2,“po0 #”,FLK,FLK2,“po0”,13]
I understand from the basic manual that i = inverted, 38400 is the baud rate, and I think it is suppose to send some kind pulse to the ssc32 at that particular baud rate, but the rest is confusing to me.
You might try something like this. The code uses a buffer, and an offset (loc) to write to the buffer (64 bytes). It uses the USART of the PIC (18F4620) 9600 baud (?), not a bit-banged port. Assumes RS-232 buffer chip.
Two code snips, set all pulse widths, and update the legs.
char const ServoStr0] = "#%02dP%d";
char const ServoStr1] = "#%02dP%d#%02dP%d";
char const ServoStr2] = "#%02dpo0";
char const ServoStr4] = "#%02dP%d#%02dP%d#%02dP%d";
/* set all pulse widths */
for(servo = loc = 0; servo < 16 + (MAX_LEGS * 2); servo += 4)
{
if(servo == MAX_LEGS * 2) /* LEFT LEGS ( > 16) */
servo = 16;
for(leg = 0; leg < 3; leg++)
{
if(PulseWidth == 0)
loc += sprintf(&buff[loc], ServoStr2, servo + leg, PulseWidth); /* Po0 turn off servo */
else
loc += sprintf(&buff[loc], ServoStr0, servo + leg, PulseWidth); /* P#n set a position */
}
}
if(Time != 0)
{
loc += sprintf(&buff[loc], "T%d\r", Time); /* matches delay to follow */
DelayMilisec(Time); /* delay if specified */
}
PutString(buff); /* send to serial port */
/*-------------------------------------------------------------------------------*/
/* update the legs */
loc = sprintf(&buff[0], ServoStr1, RRHH, HipH_Pulse[RR_LEG], RRHV, HipV_Pulse[RR_LEG]);
loc += sprintf(&buff[loc], ServoStr1, RRK, Knee_Pulse[RR_LEG], FRHH, HipH_Pulse[FR_LEG]);
loc += sprintf(&buff[loc], ServoStr1, FRHV, HipV_Pulse[FR_LEG], FRK, Knee_Pulse[FR_LEG]);
loc += sprintf(&buff[loc], ServoStr1, MLHH, HipH_Pulse[ML_LEG], MLHV, 3000 - HipV_Pulse[ML_LEG]);
loc += sprintf(&buff[loc], ServoStr1, MLK, 3000 - Knee_Pulse[ML_LEG], MRHH, HipH_Pulse[MR_LEG]);
loc += sprintf(&buff[loc], ServoStr1, MRHV, HipV_Pulse[MR_LEG], MRK, Knee_Pulse[MR_LEG]);
loc += sprintf(&buff[loc], ServoStr1, RLHH, HipH_Pulse[RL_LEG], RLHV, 3000 - HipV_Pulse[RL_LEG]);
loc += sprintf(&buff[loc], ServoStr1, RLK, 3000 - Knee_Pulse[RL_LEG], FLHH, HipH_Pulse[FL_LEG]);
loc += sprintf(&buff[loc], ServoStr1, FLHV, 3000 - HipV_Pulse[FL_LEG], FLK, 3000 - Knee_Pulse[FL_LEG]);
loc += sprintf(&buff[loc], "T190\r"); /* loop time of program */
PutString(buff); /* send to serial port */
This assumes a standard LM leg arrangement.
Alan KM6VV