50 likes | 219 Views
Design of Control Strategy. Environmental Disturbances. Control Strategy. System Dynamics. Goal. Output. Sensors. Feedback. Linebot. Goal Follow the path defined by the black line Strategy Drive left and right treads at same speed
E N D
Design of Control Strategy Environmental Disturbances Control Strategy System Dynamics Goal Output Sensors Feedback
Linebot • Goal • Follow the path defined by the black line • Strategy • Drive left and right treads at same speed • If left light sensor drops below threshold turn right. • If right light sensor drops below threshold turn left.
//define motor outputs #define LEFT OUT_A #define RIGHT OUT_B #define THRESH int dir=0; task main() { // configure the sensor SetSensor(LEYE, SENSOR_LIGHT); SetSensor(REYE, SENSOR_LIGHT); start decision; start motion_control; } We will introduce a global variable dir. If dir = 0 we will travel straight. A negative value for dir will cause us to turn left and a positive value of dir will cause us to turn right. Two sensors LEYE and REYE are defined. Two parallel tasks are started. Task decision will read the sensors and decide if we should go straight, turn left, or turn right. It will set the global variable dir to 0, -1, 1 depending on the readings of the sensors. Task motion_control will have access to the global variable dir and based on the value actuate the motors. Linebot Implementation
task decision() { // write the statements for this task } task motion_control() { // write the statements for this task } Task decision must continuously monitor the sensors (forever). It sets the global variable dir to -1,0,1 depending upon the sensor readings. This will depend on the value of the defined constant THRESH. Task motion_control has a fast loop which cycles forever. It accesses the global variable dir and adjusts the motor signals. Linebot Implementation
LEFT_EYE RIGHT_EYE x L W High value Threshold value Low value X -W/2 W/2 The Decision RIGHT_EYE AND LEFT_EYE both below threshold go straight RIGHT_EYE below threshold turn right LEFT_EYE below threshold turn left