Question

In: Computer Science

Write a program that allows the robot to do a 90-degree turn (the direction of the...

  1. Write a program that allows the robot to do a 90-degree turn (the direction of the turn can be your choosing). There are two way of accomplishing this, the first is to move only one wheel, while the other is to move both wheels simultaneously in opposite directions. Micro:bit Block Coding

Solutions

Expert Solution

#pragma config(CircuitBoardType, typeCktBoardUNO)

#pragma config(UART_Usage, UART0, uartSystemCommPort, baudRate200000, IOPins, dgtl1, dgtl0)

#pragma config(Sensor, dgtl2, rightEncoder,   sensorQuadEncoder)

#pragma config(Sensor, dgtl7, leftEncoder,    sensorQuadEncoder)

#pragma config(Motor, servo_10,        rightServo,    tmotorServoContinuousRotation, openLoop, reversed, IOPins, dgtl10, None)

#pragma config(Motor, motor_11,        leftServo,     tmotorServoContinuousRotation, openLoop, IOPins, dgtl11, None)

//*!!Code automatically generated by 'ROBOTC' configuration wizard              !!*//

void turnLeftDeg(int degrees, int power)

{

//Reset encoders

SensorValue[leftEncoder] = 0;

SensorValue[rightEncoder] = 0;

//Determine tickGoal

int tickGoal = (23 * degrees) / 10;

//Start the motors in a left point turn.

motor[leftServo] = -1 * power;

motor[rightServo] = power;

//Since the wheels may go at slightly different speeds due to manufacturing tolerances, etc.,

//we need to test both encoders and control both motors separately. This may result in one motor

//going for longer than another but it will ultimately result in a much more accurate turn.

while(SensorValue[rightEncoder] < tickGoal || SensorValue[leftEncoder] > -1 * tickGoal) {

    if(SensorValue[rightEncoder] > tickGoal) {motor[rightServo] = 0;}

    if(SensorValue[leftEncoder] < -1 * tickGoal) {motor[leftServo] = 0;}

}

//Make sure both motors stop at the end of the turn.

motor[leftServo] = 0;

motor[rightServo] = 0;

}

void turnRightDeg(int degrees, int power)

{

//Reset encoders

SensorValue[leftEncoder] = 0;

SensorValue[rightEncoder] = 0;

//Determine tickGoal

int tickGoal = (23 * degrees) / 10;

//Start the motors in a left point turn.

motor[leftServo] = power;

motor[rightServo] = -1 * power;

//Since the wheels may go at slightly different speeds due to manufacturing tolerances, etc.,

//we need to test both encoders and control both motors separately. This may result in one motor

//going for longer than another but it will ultimately result in a much more accurate turn.

while(SensorValue[leftEncoder] < tickGoal || SensorValue[rightEncoder] > -1 * tickGoal) {

    if(SensorValue[leftEncoder] > tickGoal) {motor[leftServo] = 0;}

    if(SensorValue[rightEncoder] < -1 * tickGoal) {motor[rightServo] = 0;}

}

//Make sure both motors stop at the end of the turn.

motor[leftServo] = 0;

motor[rightServo] = 0;

}

task main()

{

//Turn right 90 degrees with power 30

turnRightDeg(90,30);

//Wait a bit so the robot's momentum does not effect the next turn

wait1Msec(500);

turnLeftDeg(50,40);

wait1Msec(500);

turnRightDeg(160,20);

wait1Msec(500);

turnLeftDeg(200,30);

}


Related Solutions

Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number...
Write a MATLAB program to do the following: 1- Allows the user to enter unlimited number of data set. 2- Allows the user to exit the program at any time by entering zero. 3- Calculates and displays the following statistics for the entered data set: a- Count of positive, negative, and total numbers. b- Maximum and Minimum numbers. c- Sum and Average of positive numbers. d- Sum and Average of negative numbers. e- Overall Sum and overall average of all...
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
A robot moves in rectilinear motion along the ? axis to the positive ? direction. The...
A robot moves in rectilinear motion along the ? axis to the positive ? direction. The motion starts from rest at x = 0 at time t = 0. During the time interval 0 … 6 s the acceleration of the robot is (in units of m/s2, when t is in seconds) a(t)=2t, when t=0...2s a(t)=-t+6, when t=2...6s Give the corresponding expressions for a) the velocity v(t) and b) the position x(t) of the robot as functions of time in...
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
Write a program that allows the user to navigate the lines of text in a file....
Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program...
Write a program that allows the user to navigate the lines of text in a file....
Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program...
what is the flowchart in RAPTOR for the following: Write a program that allows a tax...
what is the flowchart in RAPTOR for the following: Write a program that allows a tax accountant to compute personal income tax. Your program will ask for a filing status (0 for single, 1 for married filing jointly, 2 for married filing separately) and a taxable income. The program will compute the tax. Please use the following chart to find the tax rate to use to compute the tax:  (0) Single: o $0 - $33,950 --> 10% o $33,951...
Write a program to run on your Arduino and PortMaster board that will sequentially turn on...
Write a program to run on your Arduino and PortMaster board that will sequentially turn on and off the LED segments, so it resembles Cylon eyes (https://youtu.be/UajcgzK2shQ). Use the millis() construct shown in lecture rather than delay(). The traverse from one side to the other should take about 1 second.
WRITE CODE IN JAVA it is now your turn to create a program of your choosing....
WRITE CODE IN JAVA it is now your turn to create a program of your choosing. If you are not sure where to begin, think of a task that you repeat often in your major that would benefit from a program. For example, chemistry unit conversions, finding the area for geometric shapes, etc. You can also create an interactive story that changes based on the user input/decisions. The possibilities are endless. The program must include instructions for the user. Be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT