tech_manual_troy stahley

19
The Top Gun Race Car Technical Manual Troy Stahley Group J ELCT 302: Real Time Control Systems Troy Stahley Spring 2016 Team Jiggly puff

Upload: troy-stahley

Post on 07-Apr-2017

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tech_Manual_Troy Stahley

The Top Gun Race Car Technical Manual

Troy Stahley

Group J

ELCT 302: Real Time Control Systems

Troy Stahley Spring 2016 Team Jiggly puff

Page 2: Tech_Manual_Troy Stahley

PAGE 1

Table of Contents

1 Introduction ..................................................................................... 2

2 Safety Precautions .......................................................................... 3

3 Track Requirements........................................................................ 4

4 Operation ......................................................................................... 5

5 Parts & Design Summary............................................................ 6-9

6 Troubleshooting ............................................................................ 10

7 Schematic Diagrams ............................................................... 11-12

8 FRDM-KL25Z Pin Outs .............................................................. 13

9 Code for MCU ........................................................................ 14-18

Page 3: Tech_Manual_Troy Stahley

PAGE 2

1 Introduction

You just purchased this unique and one of a kind and highly advanced

autonomous race car that is available today so congrats!

In order to have some fun with this autonomous race car, please read

through the manual carefully to increase your knowledge on how it

operates and be aware of the safety precautions that need to be taken

while using the vehicle

Page 4: Tech_Manual_Troy Stahley

PAGE 3

2 Safety Precautions

The vehicle that was engineered uses a battery that is powerful enough to produce

large amounts of currents. When modifying the car always make sure the vehicle is

turned off by using flipping the switch to OFF. If using a breadboard, make sure all

the grounds are connected t0 the breadboard at all times. When making

modifications to the car, make sure the power is always OFF. Be careful and not

touch the circuits when car is ON because this can lead to electrical shock.

While the vehicle is operating, it produces large amounts of power that comes from

very high frequencies so certain subsystems contain integrated circuits that produce

heat dissipations, for example, the voltage regulator LM317 becomes extremely ho,

thus do NOT touch the ICs because it can definably burn some skin

Be careful not to have any kind of liquids next to the vehicle while it is in operation

or even when it is off. Since water is a very good conductor for electricity, and if

your hands contain any kind of liquid or moisture, you can become at risk for

electrical shock do make sure your body parts are dry , specifically your hands since

they are what we work with. Therefore do not operate the vehicle in wet

environmental conditions.

These electric vehicles need to be handled with care. Most components that are not

soldered together or on a pcb are very fragile and can become loose causing your

circuit and car to have malfunctions and become un steady. So ensure all wires are

connected according to the specifications before operation of the electric vehicle.

Do not use a battery that is greater than 15V or less than 7.5V. The voltage source

that is being used to power a control system is 11.1V LiPO battery. This can be used

as a very powerful battery, this should also be handled with care, making absolutely

sure that the leads of this battery are not touched to be touched by someone. This

can result in aching pain and maybe even burns to the skin.

Page 5: Tech_Manual_Troy Stahley

PAGE 4

3 Track Requirements

The electric vehicle navigates a 20kHz, 1A square wave signal

through a wire that is centered in the track that is based on its

inductor voltages that are mounted. The vehicle may not be stable

So the vehicle senses the senses a wire with a 20kHz, 1A square

wave that is applied to the track. The car senses this track signal

using its own sensing circuit that was constructed using resonance

circuits. There’s a sensor for the right and left side that is that is

shown on the

Page 6: Tech_Manual_Troy Stahley

PAGE 5

4 Operation

The task of the “Top Gun Race” design must be explained to understand the

goal that the car is engineered to achieve and the obstacles that a designer(s)

has to overcome. A team was assigned to the task and worked cooperatively

to complete the project. This laboratory experiment explores control systems

in general but specifically targets open-loop and closed-loop control. The car

implements closed-loop control via feedback from various sensors to follow

a path. This particular path contains a wire carrying a 20 kHz square

waveform signal and is periodically marked by reflective tape on its surface.

A challenge was given, along with proper materials, to design a car to follow

the track autonomously as fast as possible. The obstacles include developing

a method to provide effective feedback from the vehicles speed and position

to continuously make adjustments that aid in the precision of the car’s ability

to follow the track. The error between the distance from the car’s lateral

position and the signal carrying wire must ideally be driven to zero. This

error creates problems because if the vehicle is not accurate enough, lap time

will be compromised. Speed must be regulated in correspondence to the

systems stability. Stability describes the ability to reach the desired state

most effectively. Firm understanding of coding and implementing

microprocessors into real-time circuits, control systems (open/closed-loop),

using sensors to generate feedback, voltage regulation and conversion,

simulation software (Matlab, Simulink, and Pspice), comprehensive circuit

analysis, system state logic, and how to work as a team. Using the legend of

the Circuit Diagram, each number indicates a portion of the overall design.

Briefly the parts will be explained so that the functionality and importance

of each is understood.

Page 7: Tech_Manual_Troy Stahley

PAGE 6

5 Parts & Design Summary

5.1 The voltage source, 11.1V DC Battery The battery supplies the system with energy so that the car can perform free from

wired connections. Voltage is provided to the motors, microcontroller, and all of the sub

circuits. Certain devices that are used require a specific/stable voltage. The voltage from

the battery is not currently suitable, therefore it is regulated by the sub circuit indicated

by number 3 of the Circuit Schematic.

5.2 Freescale FRDM-KL25Z Microcontroller (MCU) This integrated circuit is programmable and has several input/output peripherals.

It requires ground and a 5V supply voltage. The operation frequency is 48MHz which is

useful for timely peripheral readings/outputs and fast computation. Logic devised in C++

is compiled onto the MCU to interpret readable input and produce the output that is

intended in the form of digital signals ranging from 0 to 3.3V in amplitude. The

performance of a microcontroller is needed to use feedback to implement a closed-loop

system. Such systems produce error when feedback is compared to a reference input

value and the system will change depending on the specific controllers in used.

Proportional and integral controllers are implemented through code by the MCU. Gain

values for each controller are set manually.

5.3 Voltage Regulator

This circuit takes the supply voltage from the battery and produces a stable output

voltage of 5V. This is used to power the gate driver from the buck converter,

microcontroller, and servomotor. The LM317 chip is used and the resistor values were

calculated to produce 5V from the output.

5.4 Buck converter (DC/DC Step down Voltage) The buck converter is a DC/DC step down voltage converter. The motor is

included in this circuit due to its associated electrical properties. The goal of this circuit is

to regulate voltage supplied to the motor. The microcontroller is utilized to output a pulse

width modulated signal (PWM) to control a transistor. The duty cycle is set by the

variable reference circuit by the potentiometer. The PWM directly influences the period

ON and OFF for the MOSFET transistor. The ON and OFF ratio induces an equivalent

Page 8: Tech_Manual_Troy Stahley

PAGE 7

average voltage across the motor’s terminals. This is important because it provides a

method for controlling the speed of the car.

5.5 Reference Voltage Circuit A voltage divider using a potentiometer is powered by the MCU and sends an

analog output voltage back to the MCU. Turning the potentiometer manually changes the voltage to the MCU and this is used through coding to determine the duty cycle of the

PWM. This step is important so that open-loop control can be established before feedback is implemented.

5.6 Hall Effect Sensor Encoder (Tachometer) This chip, combined with magnets of alternating poles which are along the

circumference of the car’s wheel, produce an output voltage that varies when a magnetic

field’s presence oscillates. The goal of this circuit is to produce a frequency proportional

to the speed of the car’s wheel. This is the first step for the implementation of feedback.

5.7 Frequency to Voltage Converter Using this circuit a frequency produced by the Hall Effect pulse encoder is

converted to a voltage that ranges within the analog voltage threshold that the MCU can

read. The threshold must be a maximum of 3.3V and is determined by the voltage

supplied to pin 5 on the LM2907 chip. With this circuit, feedback can now be used to

regulate the motor voltage/speed.

5.8 Resonance Circuit Sensors & Servomotor With feedback implemented to control the linear speed of the car, now it can be

used to control the lateral position by referencing the signal running through the track. A

circuit that resonates with the signal’s frequency produces a voltage depending on the

distance that separates them. Programmable logic is used after rectifying and smoothing

the induced signal into a DC voltage that the MCU can read. Two sensor circuits placed

on the left and right of the car are compared by the MCU and the current lateral position

is determined. A servomotor then receives a certain PWM to adjust this position by

steering the front wheels as time and distance passes. These sensors provide the feedback

mechanism that is used to control steering. The servomotor is powered by 5V from the

voltage regulator and has a variable angular position based on the PWM sent to it. The

Page 9: Tech_Manual_Troy Stahley

PAGE 8

duty cycle is manipulated between 5 and 10 percent to steer left or right. The MCU

compares the sensors input and computes a duty cycle. Then it is applied to a PWM

signal that the MCU outputs to the servomotor. The servomotor then corrects the error

that the MCU has determined.

5.9 Optical Sensors Navigation of the vehicle is important so that the position can be monitored while

in its course. Optical sensors placed on the left and right sides of the car detect the

occurrence of the reflective tape on the track. The occurrences are read by the MCU and

then used to control the car’s behavior. When the MCU counts the detection of each

sensor, the total detections can be displayed by LED’s. Also an instance when both

sensors detect the tape, an action can be made to stop the car’s progress or allow it to

continue for multiple laps.

5.10 Reset Button State logic is used to control the cars behavior based on the current conditions it is

faced with. This prevents the car from damaging itself if it is too far from the track or

comes into contact with another car. The following diagram shows the conditiona l

behavior controlled by the MCU.

At rest the car is at STOP when reset is 0. Using a circuit that utilizes a push button, the

MCU can change states to WAIT when reset is 1. This is a manual action from the user.

Now the car is waiting for the go ahead to begin by the start value. The MCU reads the

Page 10: Tech_Manual_Troy Stahley

PAGE 9

start value through its capacitive touch slider feature (also a manual action). The car

enters OFF-TRACK when the inductor voltage from the resonance circuits become too

low. This is useful for preventing collisions and damage sustained to the car. High

voltages will send the car back to WAIT and the operator will have to give the start

command once again for the car to proceed.

5.11 Bumpers The car moves to the RUN state when start is 1 remains until bumper is 1. The

bumper circuit sends the car back to STOP when the switch shown by the schematic is

closed. The switch is a physical switch which is located on the front and rear of the car.

Contact with other cars or objects will stop the car to prevent damage. The MCU

interprets the input from this circuit the same way as the reset button circuit.

5.12 LED Counter: The MCU outputs a digital signal to LEDs using the optical sensors to count the

detections from each sensor. The MCU determines the total number of occurrences and outputs a voltage to a combination of 4 LEDs. The number is represented by 4 bits where

each LED is a specific bit being 1, 2, 4, or 8. This circuit creates visual aid to the cars progress around the track.

A fundamental understanding should now be applicable when operating the car because of this brief explanation of the concepts that were employed in the design process of the car. This is merely a summary of the design and the theory behind the

design would require more extensive explanations and evidence. Closed-loop control is exemplified by this laboratory project by the use of feedback to control the speed

and direction of the car. The design utilizes effective methods for handling error by the use of PI and P controllers. It was essential for the gain of the proportional and integral controllers to be calibrated so that stability was achieved.

Page 11: Tech_Manual_Troy Stahley

PAGE 10

6 Troubleshooting

For a vehicle like the one engineered for this project, it has been fined tuned and

tested many times to race around the track, however sometimes something goes

wrong and we need to find out what is it on order for operation again. This leads us to

a troubleshoot process we can use as a guide to find out the problem:

Check the battery and ensure it is connected.

Use a DMM to check the battery level voltage to ensure it’s at a safe

voltage to operate at.

If no power and battery is connected, take out fuse and use DMM to

check for continuity

Check for any loose wires. (disconnected wires)

o Breadboard wiring including ones on the bumpers for any steering

or navigation

o MCU connections by referring to pin layout diagram on page 13

Verify that the vehicle operates properly at all states

Go through these steps and maybe the problem can be found. If not, then ask for help

from one of the professors or the TAs

Page 12: Tech_Manual_Troy Stahley

PAGE 11

7 Schematics of Overall Circuit

Page 13: Tech_Manual_Troy Stahley

PAGE 12

Page 14: Tech_Manual_Troy Stahley

PAGE 13

8 Freescale FRDM- KL25Z Pin-out Diagrams

Page 15: Tech_Manual_Troy Stahley

PAGE 14

9 Full Code Implementation

/*302 Final code to be implmented into the FRDM-KL25Z microcontroller (MCU)*/

/* ----Includes libraries----*/

#include "mbed.h"

#include <iostream>

//#include <Timer.h>

/* ----Define Constant Variables------*/

#define voltage 3300

#define maxSensorVoltageExpected 2000

// Chaning value in millivolts

#define mv1(x) (x*voltage)

#define convert(x) (x/maxSensorVoltageExpected)

AnalogIn analog_value(PTE20); // initialize analog read from A0

AnalogIn speed(PTE21);//Speed Reference

AnalogIn nav(PTE22);

AnalogIn nav2(PTE29);

AnalogIn start(PTC1);

AnalogIn stop(PTC2);

AnalogIn reset(PTE30);

DigitalOut led(LED1); // initialize LED

DigitalOut led1(LED2);

DigitalOut one(PTC17);

DigitalOut two(PTC16);

DigitalOut four(PTC13);

DigitalOut eight(PTC12);

PwmOut motorPin(PTB0); //to gate driver

PwmOut servo(PTB1);

AnalogIn leftSensor(PTB2);

AnalogIn rightSensor(PTB3);

Serial HC06(PTC4,PTC3); //bluetooth

Serial pc(USBTX, USBRX); // initialize Serial to connect to PC

Ticker switches;

int stopped;

int reseted;

void checkSwitch()

{

if(stopped) {

if(start.read()>0.5) {

stopped = 0;

}

} else {

if(stop.read()>0.5) {

stopped = 1;

}

led1 = 0;

led = 1;

Page 16: Tech_Manual_Troy Stahley

PAGE 15

}

}

int main()

{

stopped = 0;

//switches.attach(&checkSwitch, .5);

float meas1; //value from the pot

float meas2; //value from the tachometer

float tau = .0015; //wait time

float navigation; //Left Arrow Head Sensor

float navigation2; //Right Arrow Head Sensor

float turn = .075; //PWM value for Servo

const float middle = 0.075; //Center Bias

float bias = 0.02172;//Kp for right

float bias2 = 0.02172;//Kp for left

float bias_max_left = 500;//Can change during operation

float bias_max_right = 500;//Create a full 0 to 1 value

float left = 0; //Left sensor value

float right = 0;//Right Sensor Value

int n=0;//LED Count

int alreadyCounted = 0;//Previous ArrowHead Measurements

pc.baud(9600); //Keep Same

pc.printf("\nAnalogIn example\n");//PC Communication

motorPin.period_us(050.0);//Motor switch frequency

servo.period_ms(20);//Servo PWM frequency

led1 = 0;//Default Green

led = 1;

while(1) {

//Time to Loop

while(stopped) {//Wait

led1 = 1;//LED red

led = 0;

motorPin = 0;

if(start.read()>0.5) {//Start Button Pressed

stopped = 0;

led1 = 0;

led = 1;

}

wait(1);

}

if(stop.read()>0.5) {//Bumper hit

reseted = 1;

}

while(reseted) {//Stop

stopped = 1;

led1 = !led1;

led = !led;

motorPin=0;

if(reset.read()>0.5) {//Reset

reseted = 0;

Page 17: Tech_Manual_Troy Stahley

PAGE 16

}

wait(1);

}

meas1 = analog_value.read(); // Converts and reads the analog input value (value from 0.0 to

1.0)

left = leftSensor.read(); //Read Left Sensor

right = rightSensor.read(); //Read Right Sensor

meas2 = speed.read(); // Reads the voltage from the F2V converter

//sets the duty cycle of the motor pin

navigation = nav.read(); //Read Left Arrow Head

navigation2 = nav2.read(); //Read Right Arrow Head

if(navigation < 0.5 && navigation2 < 0.5) {//At start: Reset counter

n=0;

alreadyCounted=1;

} else if(navigation < .5) {//Left Side Arrow Head

if(alreadyCounted==0) {//If not already counted count

n++;

alreadyCounted=1;

}

} else if(navigation2 < .5) {//Same for Right

if(alreadyCounted==0) {

n++;

alreadyCounted=1;

}

} else {//Get ready for next read

alreadyCounted=0;

}

if(n>11) {//Saturation Limit

n=0;

}

left = mv1(left); //Converts to 3300 millivolt Range

right = mv1(right);

//running maximum

if(bias_max_left<left) {//Running Maximum

bias_max_left = left;

}

if(bias_max_right<right) {//Running Maximum

bias_max_right = right;

}

//while loop for wwhen car runs off track

while(left<600&&right<600) {//Off track Detected

led1 = 0;

led = 0;

motorPin = 0;

stopped = 1;

left = mv1(leftSensor.read());

right = mv1(rightSensor.read());

wait(1);

}

Page 18: Tech_Manual_Troy Stahley

PAGE 17

left = left/bias_max_left;

right = right/bias_max_right;

turn = middle-left*bias2+right*bias;//u = K_p(R-L) + B

if(turn>0.09) {//Saturation Limits

turn=0.09;

} else if(turn<0.06) {//Saturation Limits

turn=0.06;

}

if(turn>middle) {//Proportional Speed Controller

meas1=meas1-meas1*(turn-middle)*70;

} else if(middle>turn) {

meas1=meas1-meas1*(middle-turn)*70;

}

if(turn>.073&&turn<.077) {//Close enough to center: Might take out

turn=middle;

}

motorPin = meas1;//Set Motor Speed

servo = turn;//Set Servo Speed

/*This next Section Can be used to control the car by section of the track if wanted*/

if(n==1) {//Controlling LEDs

one=1;

two=0;

four=0;

eight=0;

} else if(n==2) {

one=0;

two=1;

four=0;

eight=0;

} else if(n==3) {

one=1;

two=1;

four=0;

eight=0;

} else if(n==4) {

one=0;

two=0;

four=1;

eight=0;

} else if(n==5) {

one=1;

two=0;

four=1;

eight=0;

} else if(n==6) {

one=0;

two=1;

four=1;

Page 19: Tech_Manual_Troy Stahley

PAGE 18

eight=0;

} else if(n==7) {

one=1;

two=1;

four=1;

eight=0;

} else if(n==8) {

one=0;

two=0;

four=0;

eight=1;

} else if(n==9) {

one=1;

two=0;

four=0;

eight=1;

} else if(n==10) {

one=0;

two=1;

four=0;

eight=1;

} else if(n==11) {

one=1;

two=1;

four=0;

eight=1;

} else {

one=0;

two=0;

four=0;

eight=0;

}

wait(tau); //wait time of 1.5ms

}

}