Shop OBEX P1 Docs P2 Docs Learn Events
Object to Read 6 RC Receiver Channels on Any I/O Pins — Parallax Forums

Object to Read 6 RC Receiver Channels on Any I/O Pins

Duane DegnDuane Degn Posts: 10,588
edited 2012-11-17 09:08 in Propeller 1
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.

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

  • stargazer2050stargazer2050 Posts: 89
    edited 2012-11-16 14:45
    Perfecto!

    I'll look for the helper method tomorrow to move pins, or i can move other stuff around.

    Thankyou so much.

    Eddie
  • stargazer2050stargazer2050 Posts: 89
    edited 2012-11-17 06:34
    How do you unpack an array in spin?
  • Mike GMike G Posts: 2,702
    edited 2012-11-17 06:41
    We need a little more information. How about posting your code and telling us what you are trying to do.

    Use an index to access an array element.
      elem1 := myarray[0]
      elem2 := myarray[1]
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-11-17 07:12
    How do you unpack an array in spin?

    Mike G answered this well.

    In the demo above, I use the code:
    repeat
        repeat result from 0 to Rc#POSSIBLE_CHANNELS - 1
          pulseLength[result] := Rc.Get(result)
          if pulseLength[result] <> previousPulseLength[result]
            ' update pulse length display if the value has changed
            Debug.Position(READING_X, DISPLAY_Y + result)   
            Debug.dec(pulseLength[result])
            Debug.str(string(" us    ")) 
            previousPulseLength[result] := pulseLength[result]
    

    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":
    PUB Get(channel) 
    '' Get receiver servo pulse width in µs. 
      result := pulseTics[channel] / microSecond         
    

    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.
  • stargazer2050stargazer2050 Posts: 89
    edited 2012-11-17 09:08
    Hi,

    Mike g: trying to unpack the array in duane's program above.

    Duane: moving discussion to general forum, which says for programming.
Sign In or Register to comment.