Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Scenario: A robot is sitting in a chair with its arms facing down. Write an algo

ID: 3674792 • Letter: S

Question

Scenario: A robot is sitting in a chair with its arms facing down. Write an algorithm, using pseudocode, to make the robot:

stand up

walk until it senses a wall

turn around

walk back to the chair

sit back down in the origin starting position

Finally, output the total number of steps taken.

Commands:

In addition to our standard pseudocode commands, you must also use the following robot control commands:

sit

stand

step (one step forward)

raise arms (parallel to floor)

lower arms (pointing to floor)

sense (only if arms are raised)

turn (90 degrees right)

Immediately after issuing a sense command, you can check whether the robot is at the wall as follows:

if at wall
or alternatively
if not at wall

You should use comments, sequence, comparison, iterative instructions in this project.

Assumptions

You must assume the following facts:

The robot's initial sitting position is directly facing the target wall.

There are no obstacles between the robot and the wall.

The wall is 1 or more exact steps from the chair.

The wall is sensed when it is less than 1 step from the robot's arms.

The length of the robot's arms are slightly less than the length of 1 step.

Your solution

Your solution must include all of the following:

Adequate comments

Initialization and use of at least one variable

Sequential flow of control

Conditional flow of control

Iterative flow of control

Handling of any special cases

Output of the total number of steps taken

Your pseudocode must conform to the course pseudocode guidelines.

Explanation / Answer

Hi below i have explained the algorithm logic and pseudocode to make the robot perofrm the action for your reference,

Pseudocode Performance:

isStanding (Boolean) = false
isTouching (Boolean) = false
turnLeft (number) = 90

Pseudocode:
if isStanding not true then isStanding = true (stand up)

do while isStanding is true & isTouching is not true
take step (this loop will run until the robot touches the other chair)

ifTouching is true then turnLeft*2

if isStanding is true then isStanding = false (sit down)

We don't know how far the ROBOT is from the wall. The obvious way to solve this problem is to count the number of squares to the nearest wall and then enter the program with the correct number of steps. A program that causes the ROBOT to stop at the wall if it is three squares away would be:

In other words, we could just instruct the ROBOT to take the correct number of steps and then stop. There are at least two difficulties with this: First, it won't work if the ROBOT is more than 31 steps from the nearest wall and second it it not very general. It will work only with a specified number of steps. We would have to write a separate program for every possible number of steps the ROBOT can be from the wall. A good algorithm or solution to the problem should be general.

What we are after is a single program that will work in all circumstances. Let's attack the problem of not knowing how many steps from the wall the ROBOT is to begin with. What if we could put one 00000000 (STEP) instruction in the program and get the ROBOT to repeat STEP until it gets to the wall? That way we wouldn't need to know exactly how far from the wall the ROBOT is to begin with. We need a way to make the ROBOT repeat an instruction. What we have in mind is called a loop.

The ROBOT has an instruction that will cause it to repeat some earlier instructions in a program. The opcode 101 (GOTO), followed by a five-bit address, causes the ROBOT to repeat a sequence of instructions starting at that address. Let's try the following program.

It certainly is short! The instruction at 00000 caused the ROBOT to step (does it always?), and the instruction at 00001 caused the ROBOT to go back and do step 00000 over again. Then the instruction at 00010 causes the ROBOT to stop. Well it sounds good. What's wrong with this program? Hint: There is more than one thing wrong!

Our second try certainly overcomes the objection to our first try regarding the distance to the wall. The second program does not put a limit on the number of times the 00000000 (STEP) instruction is carried out - and there is its difficulty. The first two instructions in this trial solution will be executed over and over and over and over and... This is an example of an infinite loop. There is no way to escape from the loop. Running this program is going to be hard on the ROBOT's batteries! Besides, when the ROBOT does reach a wall (and it could do that at any time), it will wear out its wheels tryin trying to take steps that are impossible.

We now seem to be caught in a dilemma. We need a loop to account for different distances to the wall, yet our proposed solution loops forever! We need some way to have the ROBOT stop as soon as it reaches the wall. Let's look back at everything we know about the ROBOT and see if there is any way it can "know" when it gets to a wall.

Reviewing the commands or opcodes in the table of instructions given earlier, we see that the opcode 010 (RAISE) causes the ROBOT to turn on its light if it is against the wall - just what we're after! In describing the ROBOT's characteristics, we promised that the ROBOT's warning light would give it a decision-making capability. Great, that's just what we need - a way to identify the wall and a way to decide when to escape from the loop.

Recall the way the warning light works: Once the light is turned on, the ROBOT ignores all instructions except for 11000000 (LIGHT). The 110 opcode tells the ROBOT to turn off the light. If the warning light is on for any reason, this is the only opcode that has any effect.

Getting the ROBOT Out of a Loop

Now, let's attack the problem again by using the 010 (RAISE) opcode to solve our dilemma. To get the ROBOT out of its deadly loop, one of the instructions inside the loop must sooner or later cause the warning light to be turned on. That instruction contains the 010 (RAISE) command. The ROBOT tries to raise its arms and cannot (because it is up against a wall), so the light goes on. When that occurs, the 101xxxxx (GOTO) instruction, which normally causes the ROBOT to begin repeating the loop (assuming the loop begins at a step number xxxxx), will be ignored because the light is on. The ROBOT will then execute the instruction following the 101xxxxx instruction, thereby escaping from the loop!

Here's the new program with both the binary machine language and the English language explanation about what the instructions do.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote