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.

Connections:

Concurrency:
For this assignment you must write your code using ProtoThreads 1_2_1.
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.

Building/simulating the 1-DOF sensor/beam/motor
You will construct the hovering device, similar the 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. If you are so inclined, you can verify the period with your cell phone camera. 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.


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 shaft collar to the pot shaft with the beam held in the horizontal position.

The servo potentiometer is attached to a board using 4x40 bolts, or small wood screws.
A small length of brass tubing is glued to a shaft collar using epoxy. The wood should fit tightly into the brass tube.
When gluing:

  1. Clean the shaft collar and brass tubing with isopropyl alcohol.
  2. gently sand the shaft collar and brass tubing to roughen them.
  3. Lay the shaft collar on a piece of paper. If you glue it to the table it will be there a long time.
  4. Be sure to cover the shaft hole with a small piece of tape so that NO epoxy gets into the shaft hole.
  5. Orient the brass tubing to be at right angles to the axis of the set screw.
  6. Mix the epoxy, apply to the shaft collar, press the brass tube into the epoxy, let sit for an hour.


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);


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 July 7, 2017