Smartpin mode for parallax feedback servo?
Rayman
Posts: 14,632
in Propeller 2
Want to use a smartpin to automate Capturing feedback signal from parallax feedback servo:
Feedback signal: PWM, 3.3V, 910 Hz, 2.7–97.1% duty cycle
Anybody want to suggest a smartpin mode for this?
Would be great if could just do rdpin and some math to get position…
Comments
You can go down two paths. Asynchronous measuring where pulse width and pulse period are integrated and you need read only one smartpin. Or use synchronous measuring where you precisely measure both the width and period in tandem but this requires two smartpins. Asynchronous is prone to some aliasing but is less resource hungry.
Asynchronous solution would use smartpin mode P_COUNT_HIGHS (%01111) with a sample period larger than two pulse periods. Can be much larger. Divide (use the cordic's QFRAC) it's Z width result by the sample period to find the width fraction.
Synchronous solution could use P_HIGH_TICKS (%10001) to find the width of a single pulse + P_EVENTS_TICKS (%10010) to find the period of that same pulse to the next. Again, divide width by period to get the fraction.
A more precise measurement can be made by combining both of the above. The natural clean precision of synchronous plus the enhancement of the longer sample period used for asynchronous. For this there is two sets of smartpin modes P_PERIODS_HIGHS (%10100) for accumulated widths of multiple pulses + P_PERIODS_TICKS (%10011) for accumulated periods of those pulses, or P_COUNTER_HIGHS (%10110) for widths of pulses + P_COUNTER_TICKS (%10101) for periods of pulses. Same dividing applies as above.
Of course, if period is not officially part of the signal then all you really want is the width. In which case P_HIGH_TICKS will precisely do the job all by itself.
Based on Evan's suggestions I did a bit of experimenting.
Update: Corrected per Evan's comment below.
Ah, sorry, I didn't elaborate on smartpin setup. The correct Y setting for setup of period measure should be a 1 (A-input rise), not 2 (A-input edge).
I'm guessing the singular reading taken was when a very small pulse width was present, so thereby the measured fall-to-rise was almost as long as a full period.
There is quite a lot of duplication of function between the counter modes. Two of P_EVENTS_TICKS sub-modes are covered entirely in P_PERIODS_TICKS, and again in P_COUNTER_TICKS. All counting modes could have been packed into a wider selection of Y settings of a single counter mode. The four basic serial modes have spare X bits for combining them to one mode too. There might be opportunity for more config combinations with the serial.
Fixed. Thanks.
For those C lovers out there here is the same code:
The floating math does not come out the same though.
Mike
Thanks! Feedback seems to be working using @JonnyMac code.
But, servo itself isn't working. Have to check on that...
Ok, servo working. Guess code was set to 1475 us, which servo seems to ignore...
Guess now need some kind of PID loop if want to send servo to a particular angle...
I don't know what you're application is, but you might consider a robotic actuator like the LX-16 -- kind of a hobbyist priced Dynamixel (which are pricey).
-- https://www.amazon.com/LX-16A-Bearing-Durable-Steering-17KG-CM/dp/B073WR3SK9
After trying one I ended up bying the 5-unit kit which comes with a PC interface which I found useful for experimenting.
-- https://www.amazon.com/LX-16A-Bearing-Durable-Steering-17KG-CM/dp/B073XY5NT1
They're easy to use, run on a simple TTL network (one pin for many devices), handle decelerating into a position for you, and can be used in servo and motor modes. In servo mode, position data can be set and read back.
Wow, prices on those are great @JonnyMac
Last I looked into ones like that they were $100 or so, as I recall...
The Dynamixel versions are very expensive. These have really good specs and the price is hard to beat. Now, with the FB360 you know where the device is through 360 degrees, though it takes a bit of work. If you don't need that much range, the LX-16A in servo mode will go 240 degrees and will return position data through a serial command.
If you're using them with a P2, you don't even need to invoke a serial cog if you've got some time in your process loop to deal with messages. I am nearly done with a simple object that uses inline PASM to send and [optionally] receive messages from the LX-16A. That was based on similar work I did with the Dynamixel for a lens focus and zoom controller.
Here's the inline code for talking to the LX-16A. Since the length of a response message is now known there is a 1.5 byte timeout.
I'm planning to use the LX-16A in a couple work projects so I made a P2-style accessory board for it. This lets me work with Dynamixels, LX-16s, and has two servo channels. I have the option to bring in external power so I don't put too much load on the 5v from the Eval board.