0% found this document useful (0 votes)
17 views

Homeworkassignment 2

The document contains questions and responses about the code for a robot that moves forward until it hits an obstacle. When it hits an obstacle: 1) It reverses direction for a set amount of time (REV_TIME) 2) It then spins by activating one motor for a set time (SPIN_TIME) 3) It continues moving forward again by activating both motors. Changing the REV_TIME and SPIN_TIME values impacts how long the robot reverses and spins for. Using #define for these constants makes the code easier to understand and modify.

Uploaded by

api-313058499
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Homeworkassignment 2

The document contains questions and responses about the code for a robot that moves forward until it hits an obstacle. When it hits an obstacle: 1) It reverses direction for a set amount of time (REV_TIME) 2) It then spins by activating one motor for a set time (SPIN_TIME) 3) It continues moving forward again by activating both motors. Changing the REV_TIME and SPIN_TIME values impacts how long the robot reverses and spins for. Using #define for these constants makes the code easier to understand and modify.

Uploaded by

api-313058499
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Activity 5.

2 Questions
1) Can you explain its motion based upon the program?
OnFwd(LEFTRIGHT, 75);Bot moves forward at 75% power because both
A and C outputs are turned on in Fwd direction
while(true)
{
until(SENSOR_1==1);Bot continues its movement until the sensor
is pressed when the bot hits an obstacle
OnRev(LEFTRIGHT, 75);Bot then reverses direction at 75% power
Wait(REV_TIME);Bot reverses for 500ms
OnFwd(LEFT, 75);Output A is activated in the forward direction
causing the bot to spin
Wait(SPIN_TIME);Bot spins for 700ms
OnFwd(RIGHT, 75);Output C is activated in the forward direction
which causes the bot to travel straight forward again.
}
2) What is the effect of changing the values of REV_TIME and SPIN_TIME?
Increasing REV_TIME will cause the bot to back up further after
it contacts an obstacle
Decreasing REV_TIME will cause the bot to back up a shorter
distance
Increasing SPIN_TIME will cause the bot to spin for a longer
time
Decreasing SPIN_TIME will cause the bot to spin for a shorter
time
3) Why is it advantageous to use #define to declare these constants?
When these values are used in multiple places in the program
the value can be edited by changing only one line of code. You
can also give the constants a name that makes your program
easier to understand.

Activity 5.3 Questions


1) Why is the mechanical structure better, for Bumpbot 2, in terms of
vehicle dynamics and bumper wear/reliability?
Since the bumper switch starts out in the pressed position and
releases when an obstacle is struck, the switch is not being
smashed every time an obstacle is encountered. This should
cause less wear on the switch. Also if the bumper that actuates
the switch were to fail and fall off when striking an object the
switch would still release and cause the bot to reverse.

2) Alternate control strategy


I changed the until statement in bot 1 program to a while statement
that executes a block of code to reverse the bot after the sensor_1 is
pressed and the value is 1.
#define BUMP IN_1
// motors
#define LEFT OUT_A
#define RIGHT OUT_C
#define LEFTRIGHT OUT_AC
// constants
#define REV_TIME 1000
#define SPIN_TIME 500
task main()
{
SetSensorTouch(BUMP);
OnFwd(LEFTRIGHT, 75);
while(true)
{
while(SENSOR_1==1)
{
OnRev(LEFTRIGHT, 75);
Wait(REV_TIME);
}
OnFwd(LEFT, 75);
Wait(SPIN_TIME);
OnFwd(RIGHT, 75);
}
}

You might also like