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...
Write in Python and as 2 seperate programs Write a program that allows the user to...
Write in Python and as 2 seperate programs Write a program that allows the user to enter the total rainfall for each of 12 months into a LIST. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest rainfall amounts. Data: January 7.9 inches February 10.1 inches March 3.4 inches April 6.7 inches May 8.9 inches June 9.4 inches July 5.9 inches August 4.1 inches September...
Objective: Write a program that simulates a robot running a queue of commands to move around...
Objective: Write a program that simulates a robot running a queue of commands to move around a board with obstacles. Requirements: The board is composed of spaces that are either empty (“_”) or have an obstacle (“X”). Also the board is assumed to be 10x10 spaces. The robot (“O”) has an x and y position corresponding to its location on the board, and four commands: move up, move down, move left, and move right. Both the board and the robot’s...
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...
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...
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 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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT