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

1. stand up2. walk forward until it senses a wall3. turn around4. walk back to the chair5. sit down in its original starting positionFinally, output the total number of steps taken.Commands--------In addition to our standard pseudocode commands, you must also use the following robot control commands:sitstandstep (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 wallor alternativelyif not at wallAssumptions-----------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 commentsInitialization and use of at least one variableSequential flow of controlConditional flow of controlIterative flow of controlHandling of any special casesOutput of the total number of steps takenYour solution-------------Your solution must include all of the following:Adequate commentsInitialization and use of at least one variableSequential flow of controlConditional flow of controlIterative flow of controlHandling of any special casesOutput of the total number of steps taken

User Kubra
by
4.3k points

2 Answers

4 votes

Final answer:

The provided pseudocode details a sequence for a robot to stand, walk to a wall, return, and sit, tracking the steps taken for output.

Step-by-step explanation:

Robot Pseudocode Algorithm

To program the robot to accomplish the tasks outlined in the scenario, we must follow the steps carefully, include error handling, and use a variable to track the number of steps taken. Below is the pseudocode with annotations for clarity.

// Initialize step count variable
Var stepsTaken = 0

// Stand up from chair
stand

// Walk forward until a wall is sensed
raise arms
While not at wall
step
stepsTaken = stepsTaken + 1
End While
lower arms

// Turn around to face the chair
turn
turn

// Walk back towards the chair
raise arms
While stepsTaken > 0
step
stepsTaken = stepsTaken - 1
End While
lower arms

// Sit down back in the chair
sit

// Output total steps taken
Output "Total steps taken: " + (initialSteps - stepsTaken)

Firstly, the robot stands up, then it walks towards the wall, raising its arms to sense it. Upon sensing the wall, the arms are lowered, the robot turns 180 degrees to face the chair, and then walks back using the steps taken as a guide. Once the robot reaches the start position, indicated by a step count of zero, it sits down and outputs the total number of steps taken during the process.

User Rohit Jadhav
by
4.8k points
2 votes

Solution :


\text{Algorithm to} stand
$\etxt{up:}$

step
1:
$\text{stand}$

step 2:
\text{raise arms}


\text{Algorithm to} walk
$\text{until it senses}$ a wall:

step
1:
$\text{stand}$

step 2:
\text{raise arms}

step 3:
$\text{wallSensed}$=false

step 4:
$\text{numberOfSteps}$ = 0

step 5: if(
$\text{wallSensed}$==true) then


\text{lower arms}

step

else

if(sense)


$\text{wallSensed}$=true;

else

step


$\text{numberOfSteps}$++;

step 6: display
$\text{numberOfSteps}$ to reach the wall


\text{Algorithm to} turn around:

Step
1: if(
$\text{wallSensed}$==true) then

turn


\text{raise arms}

turn


\text{Algorithm to} walk back
$\text{ to the chair}$:

Step
1:
$\text{turn around}$

Step 2: for i=
1 to
$\text{numberOfSteps}$ do

step


\text{Algorithm to} sit back down:

Step
1: sit

Step 2: Lower arms

User Kahless
by
4.6k points