Motor control from an ultrasonic with Talon

We have a motor that will tilt a platform up down. If 0deg is flat we may tilt it up/down 45 degree or so. We may want to control the tilt based on an ultrasonic looking up at the platform from below.

The ultrasonic sensor will output a 0-10V signal that is proportional to the platform distance. This motor would be controlled with a Talon. We will put together a simple resistor voltage divider to scale the 10V signal to the 3.3V input range of the Talon. Then we would have the Talon run a PID to control the motor to bring the sensor value to the target.

The ultrasonic position versus motor rotation is not linear but has a cos(theta) term to it. Our control sensitivity will change depending on the angle. Controlling a rotation with a linear measurement is a bit odd, but does it change anything fundamental about the PID? Is there anything special about this sensor configuration that changes the control loop?

If I have read this correctly, what you are proposing is illegal. Only the roborio is allowed to drive a motor through a motor controller. Check rules R712 and R714. Also from the inspection checklist:

Pretty sure they just want to use an analog ultrasonic sensor as feedback for a Talon. That is a legal use case.

1 Like

The Talon analog input is only a sensor reading. The roborio is controlling the Talon via CAN by sending it config info such as the PID constant values, motor limits, and the sensor target setpoint.

The question is if there is anything unusual in the Talon programming for this ultrasonic sensor control versus the rotary controls that are common?

I don’t believe there’s anything special you need to do. Just be careful in your PID tuning.

It appears to be simply an analog ultrasonic sensor, and the Talon SRX is capable of using a connected analog sensor as input for PID.

If I understand the geometry correctly, the sensor is looking vertically and the platform centers on being horizontal. If so, this is really a sin \theta function. Over a span of \pm 45 ^{\circ} the non-linearity is less than 30%.

We did that a couple of years ago with an IR distance sensor. The only difference I can think of is the US tends to be rather slow to respond compared to IR. At shorter distances they work faster, though. Sometimes you can change settings for sensor range and sensitivity/accuracy.

1 Like

I will say an encoder (possibly even an absolute
encoder) would seem to be your best bet here. Instead of using an ultrasonic to indirectly measure your angle and do PID on.