AME 3623: Project 4
- All components of the project are due by Tuesday, March 23rd
at 5 pm.
- Groups are the same as for project 1.
- Discussion within groups is fine.
- Discussion across groups may not be about the specifics of the
solution (general programming/circuit issues are fine to
discuss).
At the end of this project, you should be able to:
- through low-level functions, control the speed and direction of DC motors through an H-bridge circuit,
- use a high-level program to test the functionality of the DC motor control interface, and
- implement a Finite State Machine in code.
Component 1: Micro-controller Circuit
In your project kit, you have one of two types of motor amplifier
boards for this project: dual and single H-bridges.
We will eventually be using one full H-Bridge to control each of the three lateral fans on
board your hovercraft (so, you will need two boards).
Option 1: Dual H-Bridge Board
The amplifier board is composed of two full H-Bridge circuits.
The detailed documentation for the motor control board can be found on the
Pololu Web site.
Below is a picture of the H-Bridge board:
Motor/Power Connections
Add wires to connect the motor control board to the motor and to the
battery:
- You have a cable that connects to your battery with two exposed
wires on the other end (DO NOT CONNECT THIS CABLE TO YOUR
BATTERY UNTIL THE WIRING OF YOUR CIRCUIT IS COMPLETE). You
will need to use wire cutters to cut down the diameter of the
exposed ends of the wires.
- Connect GND and VIN (right side of the board) directly to these thick power cables
(not to your 5V power supply provided by the Teensy board!!!).
Make sure
you do this without the battery plugged in, and have
someone else check your connections before you apply power.
Note: you may need to use a wire stripper to remove the
insulation from these power wires. Remove 1/4 inch of
insulation and twist the strands of the wire together. Insert
the cables into the screw terminal on the side and tighten the
corresponding screw. Once you are done, you must have no
exposed wire; if it is necessary, trim down the length of
your exposed wire and re-connect.
- Your kit contains one DC motor and a cable that connects to
this motor. This cable also has exposed wires opposite from
the connector. Connect this cable to the OUT A/B screw
terminals. Because these are brushed motors, the choice of
which wire connects to which of A or B is arbitrary (only
torque direction is affected).
H-Bridge Control Connections
Connect the H-Bridge board to your breadboard (using the 15 pin
connector on the left side of the board):
- Connect GND and GND to your Teensy's ground
- Connect +5V to the Teensy +5V supply
- Connect PWM to a Teensy pin that generates PWM output.
Possible pins are: 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 20, 21, 22,
23, 29, 30, 35, 36, 37, 38
- INa and INb: connect the H-Bridge to a pair of Teensy
pins on the same digital I/O port (different H-Bridges
can use different ports).
- A pattern of INa/b of "0 1" will result in torque being
generated in one direction
- A pattern of "1 0" will result in torque being
generated in the other direction
- Your choice of PWM/INa/INb must be on the opposite side of the
board from the A/B motor connector.
Option 2: Single H-Bridge Board
This amplifier board has a single full H-Bridge circuit.
The detailed documentation for the motor control board can be found on the
Pololu Web site.
Below is a picture of the H-Bridge board:
Motor/Power Connections
Add wires to connect the motor control board to the motor and to the
battery:
- The same warnings apply as in option 1.
- Connect GND and VIN (right side of the board) directly to these thick power cables
(not to your 5V power supply provided by the Teensy board!!!).
Make sure
you do this without the battery plugged in, and have
someone else check your connections before you apply power.
Note: you may need to use a wire stripper to remove the
insulation from these power wires. Remove 1/4 inch of
insulation and twist the strands of the wire together. Insert
the cables into the screw terminal on the side and tighten the
corresponding screw. Once you are done, you must have no
exposed wire; if it is necessary, trim down the length of
your exposed wire and re-connect.
- Your kit contains one DC motor and a cable that connects to
this motor. This cable also has exposed wires opposite from
the connector. Connect this cable to the OUT A/B screw
terminals. Because these are brushed motors, the choice of
which wire connects to which of A or B is arbitrary (only
torque direction is affected).
H-Bridge Control Connections
Connect the H-Bridge board to your breadboard (using the 8 pin
connector on the left side of the board):
- Connect GND to your Teensy's ground
- Connect +5V to the Teensy +5V supply
- Connect PWM to a Teensy pin that generates PWM output.
Possible pins are: 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 20, 21, 22,
23, 29, 30, 35, 36, 37, 38
- INa and INb: connect the H-Bridge to a pair of Teensy
pins on the same digital I/O port.
- A pattern of INa/b of "0 1" will result in torque being
generated in one direction
- A pattern of "1 0" will result in torque being
generated in the other direction
Component 2
Add the following to your loop:
// Create a task that will be executed once per 50 ms
static PeriodicAction fsm_task(50, fsm_step);
fsm_task.step();
With this implementation, you will ensure that the function
fsm_task() is called once every 50ms
Component 3
Create the function interface that will generate the direction and
PWM signals for each of the inputs to the motor control board.
Implement the following functions:
- float bound(float value, float min_value, float max_value) that returns
- min_value if value is smaller than min_value
- max_value if value is larger than max_value
- value otherwise
- void set_motor(float val) that sets the thrust
magnitude and direction for your motor.
- This function must
ensure that the value falls
within the range of -64... 64. The value does not, then
the offending value
should be bounded to this range. This value corresponds to a
duty cycle of 25%.
- A positive value corresponds to counter-clockwise travel; a
negative value corresponds to clockwise travel.
PWM Interface
Use the following Arduino function to set the duty cycle of a PWM pin:
analogWrite(pin, duty);
where pin is an Arduino pin index and duty is an
integer value in the range 0 ... 255 (though we are limiting the allowable
range for our motor).
Component 4
Implement a Finite State Machine in fsm_step() that does the following:
- If your switch is pressed, initiate the following sequence:
- Slowly ramp the motor up to a duty cycle of 25%
- Slowly ramp the motor down to a duty cycle of -25%
- Slowly ramp the motor up to a duty cycle of 0%
- Once complete, then your FSM should return to waiting for the
switched to be pressed.
Finite State Machine notes:
What to Hand In
- Code:
Submit your ino project file to the project4 area on Gradescope by the
deadline. This program must be properly documented, as discussed in
the project 1 specification.
- Demonstration/Code Review: All group
members must be present. This review must be completed within
five days of the deadline. However, it is better to complete these reviews
as early as possible.
Grading
For this project, we expect:
- A properly configured circuit
- H-bridge installed correctly
- Switch installed correctly
- Properly written software
- Function that sets the motor direction and magnitude
- Finite State Machine implementation
- Properly documented code
- Project-level documentation at the top of the ino file:
name and group number, date and project number
- Function-level documentation above the function
definition. Include an abstract description of what the
function does; a list of the names, types and units
associated with each parameter and return value; and the
effects that the function has on the processor or
connected components.
- In-line documentation inside of functions: individual
lines or small groups of lines have an English
description that describes logically what the code is doing
andrewhfagg -- gmail.com
Last modified: Mon Mar 22 23:47:05 2021