Note: This is a minor rewrite of an existing PIC32 lab for ECE 4760 created by Bruce Land.
In this lab, you will construct and control of a one-degree-of-freedom helicopter. A small ducted is rigidly attached to the end of a lever-arm, the other end of which is attached to a hinge. The drone motor can lift the arm, and the angle of the arm is estimated via a complementary filter of accelerometer and gyro measurements from an onboard IMU. The user can select a target arm-angle and a PID controller will drive the arm to that angle.
The target and measured angle are displayed on the oscilloscope or the VGA screen and the user specifies new target angles through a serial interface to the RP2040.
Key concepts: I2C communication, PID control, electrical isolation of DC motors, optical isolators, PWM, complementary filters, gyroscopes, accelerometers, gyro bias, mechanical assembly, navigating sensor datasheets, UART, VGA, digital low-pass filtering
A demo is shown below.
Experience shows that students prefer these webpages short. For that reason, please find the reading and background materials on the webpages linked below. Please note that the information in these readings will be critical for completing the lab.
- Complementary filters: A method for estimating angle from gyroscope and accelerometer measurements. This is a great algorithm for your toolbox. Quick, easy, and effective.
- Phenomenological introduction to PID controllers: This document focuses on building a phenomenological understanding of PID controllers through demos. The hope is that this document will help you debug your system based on the behavior that you observe in lab, and the one below will help you understand that behavior.
- Analytical introduction to PID controllers: This document focuses on building an analytical understanding of these controllers. The hope is that the phenomenological document will help you debug your system based on the behavior that you observe in lab, and this one will help you understand that behavior.
- Mechanical contruction of the lever arm: This webpage provides instructions for the mechanical construction of the lever arm.
- Motor circuit and PWM: This webpage describes the circuit that you will construct to safely drive the DC motor, and how to generate PWM.
- Data display: This webpage describes the data that you must visualize in realtime, and some strategies for visualizing that data.
- I2C communication: You will communicate with the IMU via an I2C channel. An understanding of the I2C protocol will help you debug that connection.
- RP2040 datasheet: See chapters on PWM and I2C.
- RP2040 C SDK: See chapters on PWM and I2C.
You may organize your program however you like. Here is a suggestion:
- Clears the interrupt flag
- Reads the IMU to get raw accelerometer/gyro measurements
- (Possibly, low-passes the accelerometer measurements)
- Estimates angle by menas of a complementary filter of accel/gyro measurements
- Runs the PID control loop at 1000/sec using the angle estimates from the complementary filter
- Sets a hardware PWM signal using output-compare unit to control the motor using the command:
pwm_set_chan_level(slice_num, PWM_CHAN_X[A or B], pwm_on_time);
.- (possibly) communicates measured angle and low-passed control input to DAC
- Takes user input from the serial interface to setup PID parameters and the desired angle.
- (possibly) diplays measured angle and low-passed control input on VGA display
Note that these checkpoints are cumulative. In week 2, for example, you must have also completed all of the requirements from week 1.
By the end of the lab session in week one of the lab you must have:
By the end of the lab session in week two of the lab you must have:
- Set the desired beam angle
- Set the PID proportional gain
- Set the PID differential gain
- Set the PID integral gain
- The new values should take effect immediately
- One set of coefficients should produce stable behavior over the range of desired hover angles
- Before time=0, while holding the button, the beam should be hanging vertically down (motor off)
- When the button is released at time=0, target angle should be set to horizontal
- At time=5 seconds, target angle should be set to approximately 30 degrees above horizontal
- At time=10, target angle should be set to approximately 30 degrees below horizontal
- At time=15, target angle should be set to horizontal
You will demo all of the features above to a course staff member. You program should not need to be reset during the demo.
Your written lab report should include the sections mentioned on the policy page, and: