Stuck
bboy8012
Posts: 153
I have a C# app that has a trackbar on it I am trying to send the values to the propeller to update pulses, I can see the prop plug getting the data, but nothing is changing. Can I get advice on what I have so far. Thanks for all input.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OBJ servo : "Servo32v3" uart : "FullDuplexSerialPlus" CON _clkmode = xtal1 + pll16x 'Sets clock to 16x input _xinfreq = 5_000_000 'Sets clock to 80MHz (16x 5_000_000) throttlePin = 18 'Sets pin to ESC on prop VAR long uartPulse, stack[noparse][[/noparse]100] PUB Main | oldPulse uart.start(31, 30, 0, 115200) 'Start FDS object for recieving data from com port servo.set(throttlePin, 2200) 'Initializing ESC to full brake servo.start InitESC 'Arming Electrifly ESC as per to manual cognew(servo.set(throttlePin, uartPulse), @stack) ''Loop constantly for a new pulse width repeat uartPulse := uart.rx 'Sets uartPulse to value coming in com port 'uart.StrToDec(uartPulse) 'Convert to dec oldPulse := uartPulse 'Sets oldPulse to uartPulse for comparison if uartPulse <> oldPulse 'If uartPulse changes for set for new pulse servo.set(throttlePin, uartPulse) if uartPulse == oldPulse 'If values dont change throttle stays the same servo.set(throttlePin, oldPulse) PUB RecieveData | throttle ''To be coded PRI InitESC servo.set(throttlePin, 2200) 'ESC full throttle pause(5000) servo.set(throttlePin, 1000) 'ESC full brake pause(2000) servo.set(throttlePin, 2200) 'ESC full throttle pause(2000) servo.set(throttlePin, 1000) 'ESC full brake 'pause(400) PRI pause(ms) waitcnt((clkfreq / 1000 * mS) + cnt)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Comments
Use this:
·Also, is that microseconds or milliseconds? Because you used a value of over 1000 which would pause the chip over a second with your setup.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
The values that are being sent from the trackerbar on my c# app serially are between 1000 and 2200.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Um, I'll just give you my whole library for pause rountines and string to integer conversion and vice versa. It should help get arround that problem for you by doing the conversions necessary. To transfer a string through serial and then convert it back to a number and etc.
Note, that you should not·use it to read directly from the serial buffers of the full duplex object but instead put the bytes received by that object into a local array and then call the conversion on the local array.
Also note that strings need to be terminated with zero you will have problems.
For debugging just test the device with some hard coded calues to se if it is sending and·receiving data propellerly.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
As I mentioned before, the serial data object works in bytes only. If you want a value greater than 255 you should send the data as a string first.
As in form "1005" send "1", "0" "0" "5", 0 - notice the null terminating the string, very important or the library will run on forever converting stuff.
Then you would read all those bytes into a byte sized array in the main memory, and then call the converting function on the array (pass the address of the first element of the array), and the function will then return the value in decimal form.
Notice that in your code you only get one byte from the receiver (you need to get all the bytes in it before you can make the conversion). And remeber the null terminating zero at the end of the string.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
The sThrottle is a string. But I have also tried passing it like this
·The bThrottle is an byte array
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
So... Use this...
And, I really don't know if this will work but it should put you in the right direction. Note, that the number to be sent to the propeller chip needs to be sent with its leading digit first, as in "1" "2"·"3" "4", the zero does not need to follow it as this code has plenty of extra space in its buffer for a zeros (because the vars are cleared to zero on startup).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Post Edited (Kye) : 3/1/2009 3:10:03 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Post Edited (bboy8012) : 3/1/2009 5:59:55 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Now time to figure out how to get the results i want. I will post final code with c# code for others
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If you have turned off the ability to see the little pipe arrows that tell you what an if or repeat statment is linked to I suggest you turn it back on.
I say that because you call the convert to decimal function multiple times instead of once in the code posted due to the way the compiler includes things in loops spacing.
The formating of the code I posted above is critical.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The output from you c# program is wrong. For "2200" you should send the lieral ACSII characters '2' '2' '0' '0' or in decimal 50, 50, 48, 48.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,