ENGR2210        22 September 2013

Lab 2 - Controlling a Motor

Due: 3/4 October 2013


  After Labs 0 and 1, you’ve encountered Arduino programming, digital and analog input/output, using libraries, servo motor control, and two-way communication with a PC.


  In this lab, you will learn more about controlling motors from scratch. You will pick a motor type, build a mechanical system to generate a reasonable amount of resistive torque and measure the position of said motor, and then create a PID feedback loop using a stock motor controller from Adafruit, the motor you have selected, and a stock potentiometer.

  SPECIAL NOTE: This lab will require you to build a non-trivial test setup, solder together a motor controller from a kit and verify its functionality, and tune a PID loop from scratch - this lab is not for the faint of heart!

  When complete, you will:

Part A - Select a Motor and Load

Brushed DC motor or Stepper Motor

  Select a brushed DC motor (with or without a gearhead) or a stepper motor to control. Find performance characteristics for the motor (i.e. nominal voltage, nominal speed, no-load current, stall current, stall torque, etc.) and figure out how to load the shaft in a way that doesn’t exceed 25% of the stall torque of the motor. Make sure the motor and the load applied to it won’t exceed the capabilities of the motor controller!

Part B - Solder the Motor Controller and Verify Operation

Motor, Motor Controller

  Use the fabrication tutorial provided by Adafruit to solder together your motor controller with stacking headers - please do not assemble the board with standard headers. Download the motor shield library from the tutorial, and install it in the appropriate Arduino library folders. Verify basic operation of your motor controller and motor by running tutorial code with a motor wired into the controller, and get your motor under basic speed control (i.e., you can command no-load speed in an open-loop fashion).

Part C - Build a Test Stand

Motor, 10k Potentiometer, Motor Controller

  Build a test stand that can hold the motor rigidly, hold a potentiometer in-line with the motor’s output shaft, and allow for the load you selected to be applied to the motor shaft. Verify that the motor can lift the load without being attached to the potentiometer, then add the potentiometer and attach it to the output shaft of the motor.

Part D - Determine Physical Constants, Tune a PID Control Loop

  Map the electrical input that you receive from the position of the potentiometer into physical angular constants (i.e., degrees or radians).  Once you have that, develop an appropriate control loop that takes desired angle, subtracts current angle to get an ‘error’, and then commands the motor controller to take action accordingly in the following way.

  1. Multiply the error between desired position and current position by a constant (i.e., create a Proportional term in your control loop) and feed this new signal into the speed control function of the controller. Start small (and make sure the motor and feedback device have the same sign, so the motor doesn’t ‘run away’ from the feedback device), and increase this constant until the motor moves in response to a step-change in error, and oscillates around the desired position.  Please generate a graph of your ideal step change response to your chosen proportional constant.
  2. Use the positions reported by the potentiometer and the millis() or micros() timing functions to determine the instantaneous angular velocity of the motor. Multiply this angular velocity by a constant (i.e., create a Derivative term in your control loop) and add it to the proportional gain. Tune this term so that it significantly dampens the oscillations that resulted from a pure proportional-term-only control loop. Please generate a graph of your ideal step change response to your chosen proportional and derivative constants.
  3. OPTIONAL: If you’re feeling adventurous, determine how to integrate the error signal over time (using the millis() or micros() timing functions) and multiply the integration by a constant (i.e., create an Integral term in your control loop) and add it to the proportional and derivative gains. Tune this term so that it allows you to get all the way to your target position, even under load. Please generate a graph of your ideal step change response to your chosen proportional, derivative and integral constants.

Part E - Generating Output Data, Completing the Lab

  Create and graph the following two cases:


  Please hand in a lab report at the completion of this lab.  Your report should contain, at a minimum: