ECE 4760: Laboratory 4

One DOF helicopter

Introduction.

You will build a one degree-of-freedom hovering device which allows the user to select the hover angle then controls the lift-motor with user-selectable parameters to maintain constant angle as the load changes. The motor output signal and actual angle will be displayed as waveforms on the oscilloscope. You will use ProtoThreads and write your program as tasks, the the control loop will need to run in an ISR. A video of a prototype is running here, and with waveform output, and stepping angles with tuned PID.


Procedures.

A 2017 solution video of the system built by Kristen Marie Vilcans and Ramita Pinsuwannakub.
Lectures from 2017 describing the control system.
Lecture 18 PID
.
Lecture 19 PID approximations.
Lecture 20 ADC and debugging details.

Connections:

Concurrency:
For this assignment you must write your code using ProtoThreads 1_2_1 or later.
I suggest the following thread layout, but you can use anything that works for you:

Angle sensor:
The angle sensor is a 10K potentiometer which costs over $20! Therefore you will ALWAYS limit current through the potentiometer by connecting a resistor in series with the wiper (pin 2), as shown below! The MCP6242 opamp acts as a unity-gain buffer for the anti-aliasing low-pass filter. You will pick C to be the appropriate low-pass filter for the sample rate you choose. You will connect the output of the opamp to one of the ADC channels on the PIC32.

Motor Control:
You will need to control the lift-motor from the mcu. DC motors can cause nasty inductive spikes to wipe out the transistors in the mcu port. The circuit shown below is fairly safe. An optoisolator completely isolates the MCU from the motor. The diode placed across the motor shorts out spikes when the motor is turned off on every PWM pulse. The resistor grounding the base of the phototransistor should be set for best falltime, probably around 1Mohm. The motor capacitor should start around 0.1uf. Increase it if there is too much spike noise on the analog input, but be sure to use ceramic capacitors, not electrolytic. Electrolytic capacitors are too slow. The pinout of the 4N35 optoisolator and 2SK4017 are also shown. Note that the bandwidth of the 4N35 is very small, so use a low PWM frequency, perhaps about 1000 Hz. Pin 1 on the 4N35 is marked with a "Y".

Building/simulating the 1-DOF sensor/beam/motor
You will construct the hovering device, similar to the images below.
Remember that your group gets ONE sensor potentiometer to use, so be careful.

Estimate the natural period and damping coefficient of the beam/motor/sensor that you built. You need these values for the system modeling and tuning. The natural period is approximately the simple pendulum natural period. T=2⋅π⋅√(L/g). Where L is the distance from the pivot to the motor, and g is gravitational acceleration. Using the DAC output to the scope, you can estimate the natural period. Also count the number of full cycles that the actual beam makes before it stops, and adjust the damping coefficient in the matlab code (DD) until the undriven pendulum matches the number of cycles. There are two versions of the matlab code. The first is a simulator using radian measure (with some guesses about motor thrust scaling). The second simulator uses angles measured in ADC units and motor control in PWM units, as shown below. The red line is the target angle.

The ADC will probably be set up to measure the 10Kohm servo potentionmeter from zero volts to Vref, resulting in ADC units of 0 to 1023 representing the resistance range of 0 to 10kohm. According to the potientiometer datasheet, the 10K resistance range occurs over 340 degrees of rotation. The useful range of angles for this lab will be 180 degrees (hanging down to vertical above pivot point). The resistance range you can use is therefore 180/340*10Kohm=5.29Kohm, so the raw ADC range will be about 5.29/10*1024=542 counts for 180 degrees rotation. If we set up the potentiometer to read about 520 ADC counts when the beam is hovering at horizontal position, then when hanging straight down the resistance will be about 520-271=249, and when directly over the pivot point about 790.


Building the 1-DOF device:

  1. Hot glue a motor to one end of the wooden beam.
    NOTE: Orient the motor shaft to be at right-angles to the rotation shaft of the knob.
    (motor: Coolplay Propellers Rotor Set & 4pcs Motor Set for Cheerson CX-10 CX-10A RC Quadcopter)
  2. Roughen the knob surface using sandpaper. Be sure to remove the plastic film.
  3. Hot glue the other end of the wooden beam to the knob surface.
  4. Solder a pair of wires (from ribbon cable) to the motor and tape them to the beam.
    NOTE: Use only stranded wire peeled off from ribbon cable
    The wires themselves can add weight and torque to the beam. Route them close to the potentiometer shaft to minimize torque.
  5. Screw the potentiometer bracket to a chunk of wood big enough that you can use a book to weight it down.
    Use #4 wood screws, as shown in this image.
    Hot gluing the bracket to the wood will cost you 10 points on the lab.
  6. The potentiometer mounting hole on the bracket is slightly too small for the potentiomenter sleeve. You will need to
    use the rat-tail (round) file to enlarge the hole.
  7. When attaching the potentiometer to the mounting bracket be sure the the locating pin (see data sheet) is in the appropriate sheet metal slot. The shaft on these potentionmeters is freely rotating. Therefore, when attaching the beam to the potentiometer shaft you need to check the whole range of shaft motion for continuous resistance. I suggest adjusting the pot to 1/2 full resistance, then attach the knob to the potientiometer shaft with the wooden beam held in the horizontal position.
    -- Be sure to use pliers to tighten the potentiometer on the bracket.
    -- Use a 1/16 hex wrench to tighten the knob onto the shaft. Hot gluing the knob to the potentiometer will cost you 20 points on the lab.

  8. Solder three wires (from ribbon cable) to the potentiometer.

  9. Figure out how to put a rotation-stop on the beam so that the beam cannot go past vertical.
    I suggest a piece of wire, or a coffee stir-stick or a drinking straw. One of my favorites from last
    year is below. Plastic fork from Mattens.


Data Display
The DAC A/B channels will display beam angle and motor control on the scope. This will be useful for debugging and is required for the demo and the writeup. The top trace is the actual angle. You will note that the PID algorithm is poorly tuned in this image. There is an initial jump when the PIC32 is turned on with the beam hanging straight down, followed by oscillating convergence to the horizontal position. The bottom trace is the motor control signal used to drive the PWM. If you use a very large derivitive term in the PID controller to stabilize the oscillations, you may need to lowpass filter the motor signal to display on the scope. I used a first order IIR, digital lowpass, with a time constant of about 16 PWM samples, given by:
motor_disp = motor_disp + ((pwm_on_time - motor_disp)>>4);


Week one required checkpoint:
By the end of lab session in week one of the lab you must have:

Assignment

Write tasks using ProtoThreads, plus an ISR, and construct a circuit which will:

You will demo all the features above to your TA.
Your program should not need to be reset during the demo.

Your written lab report should include the sections mentioned in the policy page, and :


Copyright Cornell University April 9, 2019