None Lab_2

The Challenge

You have learned a lot of FSM design tools and skills and this challenge will require you implement everything you have learned to date to generate a more advanced control system for the zumo gate. This new control system will make use of the LED and Photodiode detector built into your gate base to detect objects.

Fixed Assumptions

  • A momentary button on your workstation will be used as a manual gate activation signal (to take the place of the floor sensor). The gate will begin in a default position of "closed." One Unique Button Press of BUTTON 1 will cause the gate to raise the gate and remain open for 3 seconds after reaching the fully up position. It, will then lower automatically.
  • To protect the motor and gate from impacting the limit switches with too much force, the gate must take AT LEAST 2 seconds to open and 2 seconds to close.
  • If an object is detected in the path of the gate by the photodiode as the gate is lowering, it will reverse and go to the fully up position. The gate will remain open for 3 seconds before lowering again, but only if the object blocking the gate is no longer present. Only objects that will be hit by the gate were it to reach the fully down position should cause the gate to rise.
  • If the object continues to be detected after 3 attempts to close, the gate will raise, the LCD will display "FAULT" and the nothing will happen until the system is manually reset.
  • To protect the motor, the motor will stop running when the gate arm is fully down or fully up.

H-Bridge Upgrade

Having built your own H-Bridge you have likely encountered the challenges of using a breadboard to create a complicated circuit. It is easy for wires to come loose and accidental connections to be made. Now that you understand the components of an H-Bridge and how to operate it, you can take advantage of the fact H-bridges are commonly packaged into integrated circuit chips.

We have installed one on your workstation. You can find its location in the Hardware Resource: ME 480 Portable Workstation

To begin, REMOVE ALL OF THE COMPONENTS AND WIRES YOU ADDED TO THE BREADBOARD IN LAB 1. All of the connections needed to control the on-board H-Bridge are internal to the PCB.

Disconnect the motor wire connector from the MOTOR 1 socket and move it to the MOTOR 2 socket which is wired through the PCB to the H-bridge chip.

You will be using the DRV8837 chip. The instructions on how to control it with the arduino are described in the Hardware Resource: Motor 2 Driver DRV8837 H-Bridge Chip

Modify your code from Lab 1 that operates the gate to make use of the DRV8837 to drive the motor instead of your hand-built H-Bridge ciruit. Don't change the way the gate operates, just how you control the motor.

When it is working, include your modified code in the cell below (PROPERLY FORMATTED USING THE BACKTICKS).

YOUR ANSWER HERE

Model Development: Object Detection

To meet this week's challenge, we'll need a new type of sensor. Something that can detect the distance of an object without contact. For this challenge you will use a combination of an infrared (IR) LED and a photodiode. image.png The IR LED is like the green LED on your workstation that illuminates when you apply power. In this case the light produced is not visible as it is in the Infrared (IR) spectrum. But how does and LED work? Similar to transistors, a light emitting diode uses semiconductors but is actually a bit simpler than a transistor.

In [1]:
%%html
<iframe width="560" height="315" src="https://www.youtube.com/embed/BH9LI973H8w" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

We'll use the IR LED as a source to illuminate an object nearby and a photodetector to capture and light reflected by back from the object. **Photodetectors work almost the same as and LED, just in reverse as described below.

In [2]:
%%html
<iframe width="560" height="315" src="https://www.youtube.com/embed/SyZ3s45StaM" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

The symbols for LEDs and Photodiodes are similar as well. The direction of the arrows, indicating the light either being emitted or absorbed, makes the distinction.

image-3.png

Below is a schematic of the the circuit that is connected to the IR LED and Photodiode installed in your gate module. You don't need to create these circuits. They are already part of your printed circuit board.

For these ciruits, the more light that reaches the photodiode, the more the current will flow "backwards" through the diode (it is made like a diode, it has a symbol like diode, but it behaves differently). As current increases through the 10K resistor, the measured voltage difference across it will increase. The voltage difference can be measured by the arduino using its analog in capability.

image-2.png

Using the Hardware Resource: Arduino Mega Pin Mapping, identify the pin for IR Detector 1. You'll use that pin to measure the voltage difference generated by the photodiode.

Write an arduino program to read the voltage from the photodiode and output the measured voltage to the serial monitor. You'll need to use your Arduino Resource: Common Functions to find a command to read the voltage of an analog input.

With the code running, move an object (your hand or your zumo) closer and further from the sensor and see the range of values. Review the use of Serial Print and capturing data with Realterm in the Arduino Resource notebook.

For quick real-time observation of the behavior, you can show the serial output on the Serial Plotter. The plotter is found in the TOOLS menu of the Arduino software right next to the Serial Monitor. In order to use the plotter, you must format your data to print in columns by printing spaces or tabs in between each number and using Serial.println() to create a new line after each "moment" in time.

Model Validation: Object Detection

Capture a data set which shows the highest voltage the photodiode can return and the voltage that it returns when an object (this can just be your hand) is at the edge of the region of interest (about a gate blade's length). Use the OCTAVE cell below to plot the data. OCTAVE was designed to be similar to MATLAB, so you can use standard MATLAB commands to define a vector, cut/paste the data from the serial monitor into that vector and then generate a plot. Indicate on your plot, or in the code output using the disp() function, the measured value for each of the two positions you tested and the threshold value you select to allow a boolean variable to represent when something IS or IS NOT below the gate.

In [3]:
% YOUR CODE HERE
error('No Answer Given!')
error: No Answer Given!

Put your code in the cell below using the format characters provided in the template.

void setup(){
    //hello
}

void loop(){
    //world
}

YOUR ANSWER HERE

Controller Validation: Timers

You will need new programming capability for this challenge and one of those elements is a timer. Adopting the mindset that you should take steps that have managable risk and can be readily assessed for success, it is a fairly large risk to take on the whole challenge along with the addition of new programming tools.

Therefore, to take a step that we can see more clearly and better assess, we use the working gate operation code and add just one element: the basic timer functionality. This way we can focus on understanding and implementing the timer class introduced in W02A FSM TimersCounters: Controller Validation: Arduino Code.

Now modify your gate code so that the when the gate is down and the button is pressed, it waits 1 second before it raises.

Controller Validation: Counters

Once your timer is working, add a counter so the number of times the gate activates the upper limit switch is displayed on the Liquid Crystal Display (LCD). Sample code to display on the LCD is shown in your W02A FSM TimersCounters: Controller Validation: Arduino Code.

Once your code with the timer and counter is working, enter your PROPERLY FORMATTED code in the cell below.

YOUR ANSWER HERE

Place a link to a video showing the operation of the timer and counter in the cell below.

YOUR ANSWER HERE

Controller Design and Validation: Gate with Detector

Using the validated model of your emitter/detector and your validated knowledge of timers/counters, design, implement and test a controller that meets the design criteria described in the fixed assumptions of the challenge.

Controller Design: State Transition Diagram

YOUR ANSWER HERE

Controller Design: State Transition Table

YOUR ANSWER HERE

Controller Validation: FSM Arduino Code

Include in the cell below a copy of your completed Arduino code in the cell below (Properly Formatted).

YOUR ANSWER HERE

Controller Validation: FSM Video

Upload a video of your working gate FSM and provide the link to the video in the cell below.

YOUR ANSWER HERE

Controller Design and Validation: Velocity Control

With the state transition logic working for your gate controller, an additional assumption is added by request of the customers for your gate system. They do not like how the gate's speed is not consistent between opening and closing. You can see the difference in the time it takes to complete each movement. Therefore, you need to modify your code to be consistnt with the following additional fixed assumption

  • Adjust the angular velocity of the gate arm to be as similiar as possible throughout both the opening and closing.

Save your existing code and create a copy to modify. Change the code in any way you see fit to approximate as best as possible a constant velocity rotation up and down with as little bounce at the limit switches as is possible.

Controller Design: Velocity Control

In the cell below, explain your approach to generating a constant velocity gate arm motion.

YOUR ANSWER HERE

Controller Validation: Arduino Code

Include in the cell below a copy of your PROPERLY FORMATTED updated Arduino code.

YOUR ANSWER HERE

Controller Validation: FSM Video

Upload a video that demonstrates the effectiveness of your velocity control and provide a link in the cell below.

YOUR ANSWER HERE