Problem with Propeller Servo Controller USB
I purchased a Propeller Servo Controller USB·to control Parallax's Motor Mount and Wheel Kit with Position Controller.· I am using the [size=-1]Flashlite 386Ex[/size]·by JK Microsystems for the controller.· I am using the C programming language.· I have not been successful in sending commands to the Propeller Servo Controller.· I am using a serial connection.· The servo controller does work fine when I send commands with the Basic Stamp, so I know that the problem is not with the hardware.··I wrote to Parallax and asked if they had·any C programming examples for writing to this controller, and they directed me to this·forum.· Incidentally,·this is a robot project, and I am using [size=-1]eRTOS[/size]·to allow multitasking.·
Post Edited By Moderator (Bean) : 6/10/2010 3:12:56 PM GMT
Post Edited By Moderator (Bean) : 6/10/2010 3:12:56 PM GMT

Comments
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
Also, I believe the BS2 talks to it with "RS232-TTL" signals -- and yes, they may be inverted from what the Flashlite is trying.
As for C code... that's dependent on your hardware and OS. You might want to contact Flashlite and/or eRTOS support?
Post Edited (Mike G) : 6/10/2010 8:48:30 PM GMT
#include <windows.h> #include <stdio.h> #include <stdlib.h> #include <string.h> //Setup the serial port void serialConfig(HANDLE h, long baud); int main(int argc, char **argv) { HANDLE serial_port; /* Handle to the serial port */ long baud_rate = 2400; /* Specified baud rate */ //char port_name[noparse][[/noparse]] = "COM6"; /* Name of the serial port */ // Get PSC version //“!SCVER?” <CR> char pscVer[noparse][[/noparse]] = {"!SCVER?\r"}; unsigned long bytes_written; /* Bytes written to serial port */ // Open up a handle to the serial port //serial_port = CreateFileA(port_name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); serial_port = CreateFile(TEXT("COM6"), GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); // Make sure port was opened if (serial_port == INVALID_HANDLE_VALUE) { fprintf(stderr, "Error opening port\n"); CloseHandle(serial_port); exit(0); } // Set up the serial port serialConfig(serial_port, baud_rate); // Send the PSC version command WriteFile(serial_port, pscVer, sizeof(pscVer), &bytes_written, NULL); printf("\nTransmitted !SCVER? [noparse][[/noparse]%lu bytes]\n", sizeof(pscVer)); DWORD dwBytesRead = 0; char buffer[noparse][[/noparse]13]; buffer[noparse][[/noparse]12] = '\0'; // Read the serial port ReadFile(serial_port, buffer, 12, &dwBytesRead, NULL); printf("\nVersion %s \n", &buffer[noparse][[/noparse]9]); // Close the handle CloseHandle(serial_port); return 0; } void serialConfig(HANDLE h, long baud) { DCB properties; /* Properties of serial port */ /* Get the properties */ GetCommState(h, &properties); /* Set the baud rate */ switch(baud) { case 1200: properties.BaudRate = CBR_1200; break; case 2400: properties.BaudRate = CBR_2400; break; case 4800: properties.BaudRate = CBR_4800; break; case 9600: properties.BaudRate = CBR_9600; break; case 14400: properties.BaudRate = CBR_14400; break; case 19200: properties.BaudRate = CBR_19200; break; case 38400: properties.BaudRate = CBR_38400; break; default: fprintf(stderr, "Invalid baud rate: %ld", baud); exit(0); break; } /* Set the other properties */ properties.Parity = NOPARITY; properties.ByteSize = 8; properties.StopBits = ONESTOPBIT; SetCommState(h, &properties); return; }Post Edited (Mike G) : 6/10/2010 10:17:25 PM GMT
So, again, thanks loads guys for the feedback. I will let you know on the forum of any success.
/**************************************************/
/*·················· << Position Command >>··································*/
/*····················································································· */
/*··················· Written by L. Wendell···································· */
/*··············································································· ····· */
/**************************************************/
#include <rtos.h>
#include <sio.h>
#include <stdio.h>
#include <driver.h>
#include <string.h>
#include <stdlib.h>
//void SendCommand(char [noparse]/noparse);··· //Send command function
void SerXmit(BYTE [noparse]/noparse);········· //Serial xmit function
void Com1Init(void);··········· //Serial port initiate func
void MotorTest(void);·········· //Test Motors using PSCU
/**************** Main Thread ************************/
void main(void)
{
·kdebug = 1;
·rt_init( 200 );
·Com1Init();·· //Initiate camera com port (Com 1 386EX)
·rt_sleep(1000);
·rt_newthread(MotorTest, 1, 2048, 0, "MotorTest");
·do{
··rt_sleep(1000);
·}while(1);
}//End of maiin thread
/************** Com1Init function *********************/
void Com1Init(void){····· //ititiate 386Ex Com 1 for camera
·sio_init(1,0x3F8,4,512,512,NULL,0);···· //These are RTOS functions...
·sio_setup(1,2400,8,0,1,0);
}· //End of cam_sio function
/**************** SerXmit function ********************/
void SerXmit(BYTE string[noparse]/noparse){····· //Sends a string to camera.
·int i = 0;
·do{
··sio_writebyte(1,string[noparse][[/noparse]i]);
··//printf("Sent: %i, %c, \n", string[noparse][[/noparse]i], string[noparse][[/noparse]i]);
··printf("Sent: %i \n", string[noparse][[/noparse]i]);
··i++;
··if (string[noparse][[/noparse]i] == NULL) break;
·}while(1);
} //End of SerXmit function
/************** MotorTest Thread ********************/
void MotorTest(){················· //Pos values of sonar_rot = CW rotation
unsigned int ch = 1, ra = 7, pw; //, lonyb, hinyb;
BYTE buffer[noparse][[/noparse]9], lonyb, hinyb;
·do{
··rt_yield();
··pw = 1100;
··lonyb = pw & 255;
··hinyb =(pw & 65280 ) >> 8;
··printf ("%i, %i \n", lonyb, hinyb);
··buffer[noparse][[/noparse]0] = 33;··· //"!"
··buffer[noparse][[/noparse]1] = 83;··· //"S"
··buffer[noparse][[/noparse]2] = 67;··· //"C"
··buffer[noparse][[/noparse]3] = ch;··· //"Channel "0"
··buffer[noparse][[/noparse]4] = ra;··· //rate "7"
··buffer[noparse][[/noparse]5] = lonyb; //Low Byte pulse width
··buffer[noparse][[/noparse]6] = hinyb; //High Byte pulse width
··buffer[noparse][[/noparse]7] = 13;··· //"\r"
··buffer[noparse][[/noparse]8] = NULL;
··SerXmit(buffer);
··rt_sleep(1500);
··pw = 400;
··lonyb = pw & 255;
··hinyb =(pw & 65280 ) >> 8;
····· printf ("%i, %i \n", lonyb, hinyb);
··buffer[noparse][[/noparse]0] = 33;··· //"!"
··buffer[noparse][[/noparse]1] = 83;··· //"S"
··buffer[noparse][[/noparse]2] = 67;··· //"C"
··buffer[noparse][[/noparse]3] = ch;··· //"Channel "0"
··buffer[noparse][[/noparse]4] = ra;··· //rate "7"
··buffer[noparse][[/noparse]5] = lonyb; //Low Byte pulse width
··buffer[noparse][[/noparse]6] = hinyb; //High Byte pulse width
··buffer[noparse][[/noparse]7] = 13;··· //"\r"
····· buffer[noparse][[/noparse]8] = NULL;
··SerXmit(buffer);
··rt_sleep(1500);
·}while(1);
} //End of MotorTest thread
·