Question

In: Computer Science

Write a C program to control an autonomous robot. It runs on two wheels, each wheel...

Write a C program to control an autonomous robot. It runs on two wheels, each wheel connected to a DC motor. If both wheels run at the same speed, robot moves forward. If the right wheel runs slower, robot makes a right turn. There are two sensors mounted on the robot that can detect an obstacle, one in the front, one on the right.

Once the robot is turned on, it moves forward at 80% of the maximum possible speed. When an obstacle is detected in front, if there is nothing blocking on the right side; it slows down to 40% of maximum speed and then it makes a right turn. Unless there is an obstacle on the right side too, then the robot will stop.

You must use PWM to control the wheels. The sensor outputs are digital, the mbed board will detect low when no obstacle and will detect high, when there is an obstacle. This is pin connections for this robot.

Device LPC1768 mbed pin

Right wheel pin 21

Left wheel pin 22

Front sensor pin 10

Right sensor pin 11

Use a flowchart to show the algorithm of your program.

Solutions

Expert Solution

Above is the flowchart for the question and below is the c program for the same problem

#include <stdio.h>
int right_wh = 0; //value can be 0 to 255 (where 0 is 0% speed and 255 is 100% speed)
int left_wh = 0; //value can be 0 to 255 (where 0 is 0% speed and 255 is 100% speed)
char front_sen = 'L'; //value can be L or H (where L is low and H is high)
char right_sen = 'L'; //value can be L or H (where L is low and H is high)
int main()
{
while (front_sen !='H' && right_sen !='H'){
right_wh=left_wh=255*.80; //increasing speed to 80%
if (front_sen =='H'){
if (right_wh=='H'){
break;
}
else{
right_wh=left_wh=255*.40; //reducing speed to 40%
right_wh=255*.20 //reducing speed of right wheel to make a right turn
break;
}
}
}
return 0;
}


Related Solutions

A slot machine has 3 wheels; each wheel has 20 symbols; the three wheels are independent...
A slot machine has 3 wheels; each wheel has 20 symbols; the three wheels are independent of each other. Suppose that the middle wheel has 11 cherries among its 20 symbols, and the left and right wheels have 2 cherries each.    a. You win the jackpot if all three wheels show cherries. What is the probability of winning the jackpot? b. What is the probability that the wheels stop with exactly 2 cherries showing among them?
A slot machine has 3 wheels; each wheel has 20 symbols; the three wheels are independent...
A slot machine has 3 wheels; each wheel has 20 symbols; the three wheels are independent of each other. Suppose that the middle wheel has 11 cherries among its 20 symbols, and the left and right wheels have 2 cherries each.    a. You win the jackpot if all three wheels show cherries. What is the probability of winning the jackpot? b. What is the probability that the wheels stop with exactly 2 cherries showing among them?
Write a C program that runs on ocelot for a mini calculator using only the command...
Write a C program that runs on ocelot for a mini calculator using only the command line options. You must use getopt to parse the command line. Usage: minicalc [-a num] [-d num] [-m num] [-s num] [-e] value • The variable value is the starting value. • Value should be validated to be an integer between 1 and 99. Error message and usage shown if not. • -a adds num to value. • -d divides value by num. •...
Write a program in C (NOT C++ or C#) The program inputs 5 elements into each...
Write a program in C (NOT C++ or C#) The program inputs 5 elements into each of 2 integer arrays. Multiply corresponding array elements, that is, arrayOne[0] * arrayTwo[0], etc. Save the product into a third array called prodArray[ ]. Display the product array.
Write a C program that asks the user to enter any two integernumbers, and each...
Write a C program that asks the user to enter any two integer numbers, and each number consists of four-digits. Your program should check whether the numbers are four digits or not and in case they are not a four digit number, the program should print a message and exit, otherwise it should do the following:Print a menu as follows:Select what you want to do with the number 1-3:1- Print Greatest Common Divisor (GCD) of the two numbers.2- Print sum...
Write a C++ program to perform the addition of two hexadecimal numerals each with up to...
Write a C++ program to perform the addition of two hexadecimal numerals each with up to 10 digits. If the result of the addition is more than 10 digits long, then simply give the output message "Addition overflow" and not the result of the addition. Use arrays to store hexadecimal numerals as arrays of characters. Input Notes: The program reads two strings, each a sequence of hex digits (no lowercase, however) terminated by a "q". Example: 111q AAAq Output Notes...
Write a program that allows the robot to do a 90-degree turn (the direction of the...
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
Question: Write a complete C++ program that runs multiple tests and calculations using switch statement. Based...
Question: Write a complete C++ program that runs multiple tests and calculations using switch statement. Based on your input and the selection from the keyboard, the program does the followings. If the selection is 1, the program should test the input if it’s positive, negative or zero. For example, the output should be “The selection is 1 to test the input value if it’s positive, negative or equal to zero. The input value 7 is positive” If the selection is...
write C++ program using functions (separate function for each bottom) Write a program to find if...
write C++ program using functions (separate function for each bottom) Write a program to find if a number is large word for two given bottom base - bottom1 and bottom2. You can predict that a number, when converted to any given base shall not exceed 10 digits. . the program should ask from user to enter a number that it should ask to enter the base ranging from 2 to 16 after that it should check if the number is...
An example of a PIC C program code for line following and obstacle avoiding robot? For...
An example of a PIC C program code for line following and obstacle avoiding robot? For it move forward and avoid an obstacle? PIC18F86722
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT