Hi, I have a Lab to learn how to move a robot and check the speed... the equatio
ID: 3880785 • Letter: H
Question
Hi, I have a Lab to learn how to move a robot and check the speed... the equation is V(velocity)= distance / time. There are some mistakes,, and I'm not sure how to write the code... we might need to assume the distance one foot square but I'm not sure.
/**
* Drive the 3pi robot forwards a fixed distance and then stop.
*
* @param distance how far to drive [ft]
*
* @modifies the power being supplied to the robot's motors (on, then off)
*/
void driveForwards(double distance);
int main()
{
// Display battery level for 1s: 76
printBatteryLevel(76);
wait(1000);
// Wait for button B to be pressed before proceeding further:
clear();
moveCursor(0, 0);
print("Press B");
moveCursor(1, 0);
print("to drive");
waitForButton(BUTTON_B);
// Some values that we will need to drive the robot:
feet = 2; // how far we want to drive (in feet)
// Drive a fixed distance forwards and stop:
driveForwards(0 /*TODO: Fix this argument*/);
startMusic(SUCCESS);
clear();
print("Done!");
// Wait for the 'SUCCESS' tune to finish before exiting:
wait(2000)
// Required at the end of main():
return 0;
}
// TODO: Write definition for driveForwards
void driveForwards(double distance)
{
int DUTY = 40; //can range from 0 (0%) to 255 (100%)
double time = 1000; //in ms
setMotorPower(DUTY, DUTY);
wait(time);
setMotorPower(0, 0);
}
Explanation / Answer
The correct code is given below. Any value can be assigned to the variable feet depending on how much you want your robot to move.
* Drive the 3pi robot forwards a fixed distance and then stop.
*
* @param distance how far to drive [ft]
*
* @modifies the power being supplied to the robot's motors (on, then off)
*/
void driveForwards(double distance);
int main()
{
// Display battery level for 1s: 76
printBatteryLevel(76);
wait(1000);
// Wait for button B to be pressed before proceeding further:
clear();
moveCursor(0, 0);
print("Press B");
moveCursor(1, 0);
print("to drive");
waitForButton(BUTTON_B);
// Some values that we will need to drive the robot:
double feet = 2.0; // how far we want to drive (in feet)
// Drive a fixed distance forwards and stop:
driveForwards(feet /*TODO: Fix this argument*/);
startMusic(SUCCESS);
clear();
print("Done!");
// Wait for the 'SUCCESS' tune to finish before exiting:
wait(2000)
// Required at the end of main():
return 0;
}
// TODO: Write definition for driveForwards
void driveForwards(double distance)
{
int DUTY = 40; //can range from 0 (0%) to 255 (100%)
double time = 1000; //in ms
setMotorPower(DUTY, DUTY);
wait(time);
setMotorPower(0, 0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.