Parallax USB Servo avoiding the Javelin Stamp Code using C++
Tyrone
Posts: 7
Hi
I am interfacing C++ code into·a Parallax USB Servo # 28823 avoiding the Javelin Stamp Code. I can control the servo· but not efficiently from position 250-1250.
I understand that I need to send the following data:
!SC [noparse][[/noparse] SERVO ] [noparse][[/noparse] RAMP ] [noparse][[/noparse] LOW POSITION BYTE ] [noparse][[/noparse] HIGH POSITION BYTE ] [noparse][[/noparse] 0x0D ]
"!SC" I understand I need to send as ASCII in the data type of CHAR. The rest I understand that I have to send as an INT which will be passed on as decimals to the COM Port.
I am using the following code to write the data using Writefile().
(Code to send "!SC" is ASCII)
char szMessage[noparse]/noparse = "!SC";
int nBytesSent = serial.SendData(szMessage, strlen(szMessage));
(Code to send "SERVO")
int szMessageNumber = 00;
nBytesSent = serial.WriteCommByteNumber(szMessageNumber);
(Code the send "RAMP")
szMessageNumber = 00;
nBytesSent = serial.WriteCommByteNumber(szMessageNumber);
(Code to send "LOW POSITION BYTE")
szMessageNumber = 100;
nBytesSent = serial.WriteCommByteNumber(szMessageNumber);
(Code the send "HIGH POSITION BYTE)
szMessageNumber = 1;
nBytesSent = serial.WriteCommByteNumber(szMessageNumber);
(Code to send CARRIAGE RETURN)
szMessageNumber = 13;
nBytesSent = serial.WriteCommByteNumber(szMessageNumber);
I have not been able to move it from position 250-1250 a notch at a time. The only possible way I can make a 180 degree turn is if I change the HIGH POSITION BYTE from 1 - 4. That is if I change the HIGHBYTE from 1 to 2, the servo moves 45 degrees, and then another 45 degrees if the HIGHBYTE is changed to 3 and also 4 eventually making a full 180 degree turn. 5 strains the servo.
What am I doing wrong? Can you clarrify how one would use and/or manipulate the HIGHBYTE·and LOWBYTE.·I eventually burnt an expensive servo.... I'm a junior. How does Javelin pass these values onto the controller.
Thanks
Tyrone
I am interfacing C++ code into·a Parallax USB Servo # 28823 avoiding the Javelin Stamp Code. I can control the servo· but not efficiently from position 250-1250.
I understand that I need to send the following data:
!SC [noparse][[/noparse] SERVO ] [noparse][[/noparse] RAMP ] [noparse][[/noparse] LOW POSITION BYTE ] [noparse][[/noparse] HIGH POSITION BYTE ] [noparse][[/noparse] 0x0D ]
"!SC" I understand I need to send as ASCII in the data type of CHAR. The rest I understand that I have to send as an INT which will be passed on as decimals to the COM Port.
I am using the following code to write the data using Writefile().
(Code to send "!SC" is ASCII)
char szMessage[noparse]/noparse = "!SC";
int nBytesSent = serial.SendData(szMessage, strlen(szMessage));
(Code to send "SERVO")
int szMessageNumber = 00;
nBytesSent = serial.WriteCommByteNumber(szMessageNumber);
(Code the send "RAMP")
szMessageNumber = 00;
nBytesSent = serial.WriteCommByteNumber(szMessageNumber);
(Code to send "LOW POSITION BYTE")
szMessageNumber = 100;
nBytesSent = serial.WriteCommByteNumber(szMessageNumber);
(Code the send "HIGH POSITION BYTE)
szMessageNumber = 1;
nBytesSent = serial.WriteCommByteNumber(szMessageNumber);
(Code to send CARRIAGE RETURN)
szMessageNumber = 13;
nBytesSent = serial.WriteCommByteNumber(szMessageNumber);
I have not been able to move it from position 250-1250 a notch at a time. The only possible way I can make a 180 degree turn is if I change the HIGH POSITION BYTE from 1 - 4. That is if I change the HIGHBYTE from 1 to 2, the servo moves 45 degrees, and then another 45 degrees if the HIGHBYTE is changed to 3 and also 4 eventually making a full 180 degree turn. 5 strains the servo.
What am I doing wrong? Can you clarrify how one would use and/or manipulate the HIGHBYTE·and LOWBYTE.·I eventually burnt an expensive servo.... I'm a junior. How does Javelin pass these values onto the controller.
Thanks
Tyrone
Comments
You should·be able to figure out the send and receive byte sequences from that code.
I am assumimg the psc usb version uses the same byte sequences.
regards peter
int position = 878;
int lowbyte = position & 255;
int highbyte = (position >> 8) & 255;
position range is 250 to 1250, centerposition is 750
regards peter
http://www.crustcrawler.com/software/psc/index.php
regards peter
In your suggestion:
int position = 878;
int lowbyte = position & 255;
int highbyte = (position >> 8) & 255;
What is the & 255 and the >>8 for?
I haven't got past the 4th chapter of C++.... haha Maybe that is why I burnt my servo!
int lowbyte = position & 255;
int highbyte = (position >> 8) & 255;
1.) 878 (decimal) = 1101101110(binary)
2.) Performing a BitWise Shift Right 8 places will leave a byte looking like 0000000011 which is 3 in decimal. So this explains why I could only use values 1-4 on the HIGHBYTE without BitWise operators.
3.) The & "255" takes the binary representation (1101101110) of the decimal value 878 and does a calculation against the binary value of 255 (11111111)
For example: 878 = 1101101110
255 = 11111111
________
0001101110 = 110
OR
878 = 1101101110
255 = 11111111
________
1101101100 = 876
(THIS IS WHERE I GET LOST BECAUSE I AM NOT SURE HOW THE CALCULATION IS DONE WITH A 8-BIT AND 10-BIT BIT-STREAM.)
in other words: keep lower 8 bits only
878 = 1101101110
255 =·0011111111
________
······· 0001101110 = 0x6E = 110 decimal
regards peter
Off to buy another servo and will post the results here.
BitWise Operators work like a charm!
I can control the servo any which way I want to.
Peter thanks....
serialPort.WriteLine("!SCVER?")
and it responds !SCVER?
i dont suppose anyone knows what im doing wrong?
Find sample code to open the COM port but it should not be that different from previous versions of Visual C++.
I dont have any of my code anymore, so I can't help with sample code right now. I'm a beginner in C++.
regards peter