Object to Read 6 RC Receiver Channels on Any I/O Pins
Duane Degn
Posts: 10,588
I've been using an object by Jason Dorie (I think he modifed some other object) to read six RC receiver lines with a Prop.
The only problem was the object could only use I/O pin 0 through 5.
I'm pretty sure Jason has since made another modification to the code to allow other pins but before seeing Jason's most recent object I had modified his object myself.
The object I'm attaching uses a pin mask as the parameter of the Start method. I've added a helper method it case it's easier to list the pins instead of using a mask. The helper object "BuildMask" will return a mask based on the pins used in the method's parameters.
While I've had this object around for a while, I hadn't tested it before today.
I included the demo program I used to test it.
Here's the output from the demo program.
I like to think it's easy to use.
Edit(3/11/15): Warning, the code attached is an old version. There are likely better options available.
I plan to upload this program or an improved version to my GitHub account
If there isn't code similar to what is attached here on my on GitHub, send me a message and I'll make and check for any improved versions of the code.
The only problem was the object could only use I/O pin 0 through 5.
I'm pretty sure Jason has since made another modification to the code to allow other pins but before seeing Jason's most recent object I had modified his object myself.
The object I'm attaching uses a pin mask as the parameter of the Start method. I've added a helper method it case it's easier to list the pins instead of using a mask. The helper object "BuildMask" will return a mask based on the pins used in the method's parameters.
While I've had this object around for a while, I hadn't tested it before today.
I included the demo program I used to test it.
Here's the output from the demo program.
RC Receiver Demo channel #0 = 1117 us channel #1 = 1508 us channel #2 = 1507 us channel #3 = 1506 us channel #4 = 1607 us channel #5 = 1507 us
I like to think it's easy to use.
Edit(3/11/15): Warning, the code attached is an old version. There are likely better options available.
I plan to upload this program or an improved version to my GitHub account
If there isn't code similar to what is attached here on my on GitHub, send me a message and I'll make and check for any improved versions of the code.
Comments
I'll look for the helper method tomorrow to move pins, or i can move other stuff around.
Thankyou so much.
Eddie
Use an index to access an array element.
Mike G answered this well.
In the demo above, I use the code:
To fill the array "pulseLength" with values returned by the method "Rc.Get".
The variable "result" is the index of the array in this case. The first value of result will be zero and it will increment each loop until it reaches 5 which is the last element of the array to be filled. In this example the array is imediately filled again. Normally you perform some action based on these values (drive your robot) rather than just displaying them. I keep track of the previous value (in a second array) so the data in the terminal window doesn't flicker as it is continuously refreshed.
The method "Rc.Get":
Accesses the appropriate element in the array "pulseTics" and does the required math to convert clock cycles to microseconds.
BTW, The variable "result" is the only local variable cleared to zero when a method is called. If the variable result isn't used as a return value, it may be used as a temporary variable without requiring any additional memory. (I learned this from reading Kye's objects.)
I noticed in the "Similar Threads" section a thread about "Polling 8 RC-receiver channels". This thread includes code by JonnyMac. I haven't looked at Jon's code yet, but I intend to do so. I'm curious which method of capturing pulses is more accurate, the "poll" method or the "waitpxx" method used in the object I attached. Again, I didn't write the original PASM code for capturing the pulses in the object I attached.
Mike g: trying to unpack the array in duane's program above.
Duane: moving discussion to general forum, which says for programming.