Mahlet Shimellis Assegahegne / Mbed 2 deprecated ObstacleDetectionDevice

Dependencies:   N5110 SRF02 beep mbed

Embed: (wiki syntax)

« Back to documentation index

obstacle.cpp File Reference

obstacle.cpp File Reference

Program Implementation. More...

Go to the source code of this file.

Functions

void error (int code)
 the error signaling for the mbed connections mainly I2C when the acknowlegment bit is not received
void measureExpired ()
 defines the high flag state for the measurement flag
void update_distance_new ()
 Stores the previous distance in the lastDistance variable and updates the newDistance variable.
void rangeExpired ()
 defines the high flag state for the measurement flag
void updateState ()
 function that defines the input of the FSM depending on the distance range from MAX to MIN
void beamExpired ()
 defines the high flag state for the beam flag
double convertDegrees (double angleDegrees)
 hypothenuse
void drawSemiCircle ()
 function that draws a semi-circle depending on the distance measured
void drawBeamLines ()
double lat (double a, double d)
 function that calculates the lateral distance between the sensor center and object at angle a
double hyp (double a, double d)
 function that calculates the hypothenuse distance between the sensor center and object at angle a - this is the longest distance
void wallExpired ()
 Defines the high flag state for the beam flag.
void moveForward ()
 Counts the pixel step in the forward movement.
void turnLeftForward_one ()
 Counts the pixel step in the turnLeftForward_one movement.
void turnLeftForward_two ()
 Counts the pixel step in the turnLeftForward_two movement.
void turnRightForward ()
 Counts the pixel step in the turnLeftForward_two movement.
void beep_zero ()
 intial beep zero move forward
void beep_one ()
 turns on beep one Turn Left
void beep_two ()
 turns on beep two Trun Left and move Forward
void beep_three ()
 Turns on beep three Turn Right.
void beep_four ()
 turns on beep four Turn Right and move Forward
void beep_five ()
 turns on beep five Stop Dead End
void toggle_red ()
 funciton that toggles Red LED
void toggle_yellow ()
 funciton that toggles Yellow LED
void toggle_green ()
 funciton that toggles Green LED
void move ()
 Controls the pixel movement along the maze Combines all of the different stages/sub-movements Combines the buzzer and led tickers for appropriate and timely signaling.
void drawMaze ()
 Draws the sample structure of the maze to reflect the wall follower movement technique Combines drawRect functions with pre-set dimensions.
void buttonPressed ()
void manageScreen ()
 Manages the order of displays on the screen and synchronises it to the number of button presses.
int main ()

Variables

double angleArray [5] = {0,10,20,30,40}

Detailed Description

Program Implementation.

Definition in file obstacle.cpp.


Function Documentation

void beamExpired (  )

defines the high flag state for the beam flag

Definition at line 151 of file obstacle.cpp.

void beep_five (  )

turns on beep five Stop Dead End

Turns on beep five Stop Dead End.

Definition at line 290 of file obstacle.cpp.

void beep_four (  )

turns on beep four Turn Right and move Forward

Turns on beep four Trun Right and move Forward.

Definition at line 282 of file obstacle.cpp.

void beep_one (  )

turns on beep one Turn Left

Turns on beep one Turn Left.

Definition at line 258 of file obstacle.cpp.

void beep_three (  )

Turns on beep three Turn Right.

Parameters:
sound_three- integer set frequency value, local variable for function
time_three- float set time value for each buzz, local variable for function

Definition at line 274 of file obstacle.cpp.

void beep_two (  )

turns on beep two Trun Left and move Forward

Turns on beep two Trun Left and move Forward.

Definition at line 266 of file obstacle.cpp.

void beep_zero (  )

intial beep zero move forward

Controls intial beep zero move forward.

local varaible integer gives specific frequency value for the buzzer

local varaible integer gives specific time for the buzzer

Definition at line 249 of file obstacle.cpp.

void buttonPressed (  )

increments and keepd the value of the buttonFlag counter for every button press

sets the limit value of the buttonFlag before going back to zero => five different flag states to be used for the five different modules

Definition at line 391 of file obstacle.cpp.

double convertDegrees ( double  angleDegrees )

hypothenuse

function that converts angle units

Parameters:
angleDegrees- double
Returns:
angleRadians

uses equivalence of 2pi and 180 degrees

Definition at line 156 of file obstacle.cpp.

void drawBeamLines (  )

draws a beam line for each calcualted value

Definition at line 171 of file obstacle.cpp.

void drawMaze (  )

Draws the sample structure of the maze to reflect the wall follower movement technique Combines drawRect functions with pre-set dimensions.

Parameters:
x,y,width,height

top left filled rectangle-green on report

top middle filled rectangle-orange on report

top right filled rectangle-pink on report

middle filled rectangle-purple on report

bottom filled rectangle-red on report

dead end small filled rectangle-black on report

Definition at line 378 of file obstacle.cpp.

void drawSemiCircle (  )

function that draws a semi-circle depending on the distance measured

Parameters:
radius- equal to the disance measured center at (WIDTH/2,1) on the LCD

int radius = ((30*srf.getDistanceCm())/20); other possibility

x,y,radius,transparent with outline

draws one diameter

Definition at line 162 of file obstacle.cpp.

void error ( int  code )

the error signaling for the mbed connections mainly I2C when the acknowlegment bit is not received

Parameters:
code- integer to classify error type

Definition at line 21 of file obstacle.cpp.

double hyp ( double  a,
double  d 
)

function that calculates the hypothenuse distance between the sensor center and object at angle a - this is the longest distance

Parameters:
a- double angle between center if sensor and object detected
d- double shortest right angle distance between center of center and object detected. this is the distance measured directly in front of the sensor
Returns:
- value of the hypothenuse between sensor center line and beam at angle a from center

Definition at line 184 of file obstacle.cpp.

double lat ( double  a,
double  d 
)

function that calculates the lateral distance between the sensor center and object at angle a

Parameters:
a- double angle between center if sensor and object detected
d- double shortest right angle distance between center of center and object detected. this is the distance measured directly in front of the sensor
Returns:
- value of the lateral distance between sensor center line and beam at angle a from center

Definition at line 179 of file obstacle.cpp.

int main (  )

initTMP102();

normal colour mode

put LED backlight on 50%

indicates that the button has been pressed. button flag rises when button pressed

reset flag

reset flag

same idea with floats

reset flag

character array that stores the values of the newDistance variable

character array that stores the values of the lastDistance variable

reset flag

retrieves the buzzer frequency associated to the currentState from the FSM definition

reset flag

draws the screen backgroung structure

controls the movement and associated signals for the moving pixel point

Definition at line 457 of file obstacle.cpp.

void manageScreen (  )

Manages the order of displays on the screen and synchronises it to the number of button presses.

toggles measureFlag - if the flag is intially low then it goes high for buttonFlag = 0 - first screen view

toggles updateFlag - if the flag is intially low then it goes high for buttonFlag = 1 - first button press - second screen view

toggles rangeFlag - if the flag is intially low then it goes high for buttonFlag = 2 - second button press - third screen view

toggles beamFlag - if the flag is intially low then it goes high for buttonFlag = 3 - third button press - fourth screen view

toggles wallFlag - if the flag is intially low then it goes high for buttonFlag = 4 - fourth button press - fifth screen view

Definition at line 400 of file obstacle.cpp.

void measureExpired (  )

defines the high flag state for the measurement flag

Definition at line 31 of file obstacle.cpp.

void move (  )

Controls the pixel movement along the maze Combines all of the different stages/sub-movements Combines the buzzer and led tickers for appropriate and timely signaling.

Parameters:
pix- integer that sums the movement cnouters and gives an idea of the location of the pixel
Returns:
buzzer sound - output sound signal with frequency depending on the location
LED light - output light signal with color dependent on message/location (go forward, stop etc.)

turn right and move forward- function called every 0.8s

toggle green led function called every 0.76s

Definition at line 312 of file obstacle.cpp.

void moveForward (  )

Counts the pixel step in the forward movement.

Parameters:
k- integer counter from 0 to 22
Returns:
pix - integer counter incremented stores values from 0 to k

sets pixel to move forward

(x,y) starting point of the pixel - here fixed x coordinate - vertical movement

can be considered as the "speed of the movement" because it defines the rate if change of pixel - delay between two k values

increments the pix vlaue for each increase in k

Definition at line 196 of file obstacle.cpp.

void rangeExpired (  )

defines the high flag state for the measurement flag

Definition at line 112 of file obstacle.cpp.

void toggle_green (  )

funciton that toggles Green LED

controls PwmOut pin

toggles green led

Definition at line 305 of file obstacle.cpp.

void toggle_red (  )

funciton that toggles Red LED

controls PwmOut pin

toggle red led

Definition at line 297 of file obstacle.cpp.

void toggle_yellow (  )

funciton that toggles Yellow LED

controls PwmOut pin

toggles yellow led

Definition at line 301 of file obstacle.cpp.

void turnLeftForward_one (  )

Counts the pixel step in the turnLeftForward_one movement.

Parameters:
l- integer counter from 0 to 64
Returns:
pix - integer counter incremented stores values from k to k+l

sets the pixel to turn left forward

(x,22) starting point of the pixel - here fixed y coordinate - horizontal movement

increments the pix vlaue for each increase in l

Definition at line 208 of file obstacle.cpp.

void turnLeftForward_two (  )

Counts the pixel step in the turnLeftForward_two movement.

Parameters:
m- integer counter from 0 to 16
Returns:
pix - integer counter incremented stores values from k+l to k+l+m

sets the pixel to turn right forward -one

(80,y) starting point of the pixel - here fixed x coordinate - vertical movement

increments the pix vlaue for each increase in m

Definition at line 221 of file obstacle.cpp.

void turnRightForward (  )

Counts the pixel step in the turnLeftForward_two movement.

Parameters:
n- integer counter from 0 to 78
Returns:
pix - integer counter incremented stores values from k+l+m to k+l+m+n

sets the pixel to turn right forward -two

(x,38) starting point of the pixel - here fixed y coordinate - horizontal movement- x=80-n because counting down from the end x=80 to he beginning x=2 of the screen

increments the pix vlaue for each increase in n

Definition at line 234 of file obstacle.cpp.

void update_distance_new (  )

Stores the previous distance in the lastDistance variable and updates the newDistance variable.

Returns:
the lastDistance value of the previous measurement
the newDistance value from the new measurement

updates the lastDistance variable by storing into it the previous distance measurement

updates the newDistance variable by adding to it the new distance measurement

Definition at line 103 of file obstacle.cpp.

void updateState (  )

function that defines the input of the FSM depending on the distance range from MAX to MIN

Parameters:
distance- integer measured value by the SRF02 sensor and to be classified as part of a set of five ranges from MAX to MIN
Returns:
rangeState - integer from 0 to 4. defined depending on the distance range in whcih the measured distance belongs
currentState - integer from 0 to 4. depending on the value of the rangeState, the actual current state and the FSM nextState from the structure definition

Definition at line 132 of file obstacle.cpp.

void wallExpired (  )

Defines the high flag state for the beam flag.

Definition at line 191 of file obstacle.cpp.


Variable Documentation

double angleArray[5] = {0,10,20,30,40}

array of angles from the center of the sensor

Definition at line 148 of file obstacle.cpp.