Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write program in C Write a program to control the next step of a semi-autonomous vehicle. We will assume a very simplistic model where the

image text in transcribedwrite program in C

Write a program to control the next step of a semi-autonomous vehicle. We will assume a very simplistic model where the program will control the motors attached to the wheels of the vehicle (left = -1, straight = 0, right = 1) and the speed of the vehicle. The inputs to the program are: A string of directions which indicate to go forward ('F'), turn left ("L'), turn right ('R'), or stop ('S'), The next step in the directions (index into the string of directions), The current speed of the vehicle, and The maximum speed allowed (note, this does not have to be a multiple of 5). Note, from the next step in the set of directions, it is possible to determine the current direction of the vehicle (the value of index - 1). You can assume that the next step in the directions (the index) will be 1 or higher so that you always can determine the current direction (at index - 1). That is, index - 1 will be 0 or higher. The outputs of the program are the motor control and speed. The following rules apply to control the vehicle: Next Direction Forward ('F') Left (L') Action Go straight (motor control is 0) and increase the speed by 5 but do not go above the maximum speed. Go left (motor control is -1). If the current direction is forward, decrease speed by 10. But do not decrease below a speed of 5. Go right (motor control is 1). If the current direction is forward, decrease speed by 10. But do not decrease below a speed of 5. Set the wheels straight (motor control is O) and set the speed to 0. Right ('R') Stop ('S') Example: Inputs: Directions = "FRFFFRRFLFFS" Note, this would be represented in a string with indices as follows: 0 1 2 3 4 5 6 7 8 9 10 11 12 'F' 'R' 'F' 'F' 'F' 'R' 'R' 'F' 'L' 'F' 'F' 'S' '\0' Next step = 5 Current speed = 10 Maximum speed = 42 Outputs: Motor direction = 1 Speed = 5 Explanation: based on the inputs given, the next step in the directions is at index 5 in the given directions string and the current speed is 10. The character at index 5 is an 'R' (shown in red). Since the character at index 4 (5 minus 1) is an 'F', the car is turning from going straight and should slow down by 10. However, since the current speed is 10 and the minimum speed is 5, in this case it will slow down to the minimum speed of 5. Note, if the current speed had been 30, the speed would be 20 (30 minus 10). You should create different test cases to ensure you understand how the program should work and to use as test cases

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 89 2nd Symposium On Mathematical Fundamentals Of Database Systems Visegrad Hungary June 26 30 1989 Proceedings

Authors: Janos Demetrovics ,Bernhard Thalheim

1989th Edition

3540512519, 978-3540512516

More Books

Students also viewed these Databases questions