Code Foundation for ROS - Prerequisite exam Autocorrect problem

Hello,

I have just finished the prerequisites exam but I got an error for this question and i cant seem to find the problem. Please can you help me review this?

For the task2.sh bash script of the linux_exam, see my code below;

#!/bin/bash

ARG1 = $1

if [ "$ARG1" == "small_square" ]; then

    echo "small square movement";

    rosrun linux_exam small_square.py

elif [ "$ARG1" == 'medium_square' ]; then

    echo "medium square movement";

    rosrun linux_exam medium_square.py

elif [ "$ARG1" == "big_square" ]; then

    echo "big square movement";

    rosrun linux_exam big_square.py

else

echo "Please enter one of the following;

small_square

medium_square

big_square"

fi

When i run this, i get this error and then when i tried to submit, i was marked wrong for this question.

./task2.sh: line 4: ARG1: command not found

Please enter one of the following;
small_square
medium_square
big_square

Please I need your help, thank you.

Make sure you have made the big_square.py file exacutable using chmod +x, use a rosrun manually on all your scripts to make sure they do run rosrun linux_exam big_square.py make sure you have all your spacing correct. Finally don’t submit until you have it working check each one to make sure they all work, if one doesn’t work for you it won’t work when you submit. You can also go to Advanced Utilities 1 and look at the scripts especially ex3_4_script.sh it’s a great example it’s basically what your trying to do take notes copy it down for reference, if your not taking notes yet start, every OS has a good program for keeping notes and organizing them.

1 Like

Thank you @hskramer. My scripts performed the square well, i only noticed that the turn was not exactly 90 degrees. I think the grader has an issue as it fails this one and the python exam get_highest_lowest.

user:~/catkin_ws/src/linux_exam$ ./task2.sh
./task2.sh: line 4: ARGUM1: command not found
./task2.sh: line 5: ARGUM2: command not found
./task2.sh: line 6: ARGUM3: command not found
small square movement
[INFO] [1626632283.037105, 83.902000]: Cmd Published
[INFO] [1626632286.038952, 86.690000]: Cmd Published
[INFO] [1626632294.047519, 94.186000]: Cmd Published
[INFO] [1626632297.049709, 97.019000]: Cmd Published
[INFO] [1626632305.061529, 104.497000]: Cmd Published
[INFO] [1626632305.061529, 104.497000]: Cmd Published
[INFO] [1626632308.068142, 107.326000]: Cmd Published
[INFO] [1626632316.077336, 114.779000]: Cmd Published
[INFO] [1626632319.081509, 117.647000]: Cmd Published
[INFO] [1626632327.090185, 125.191000]: shutdown time! Stop the robot
[INFO] [1626632327.091071, 125.192000]: Cmd Published
[INFO] [1626632327.091481, 125.192000]: ######## Finished Moving in a Square
[INFO] [1626632327.092525, 125.193000]: shutdown time! Stop the robot
[INFO] [1626632327.093197, 125.193000]: Cmd Published
medium square movement
[INFO] [1626632328.420597, 126.457000]: Cmd Published
[INFO] [1626632334.427126, 132.165000]: Cmd Published
[INFO] [1626632342.435897, 139.719000]: Cmd Published
[INFO] [1626632348.441468, 145.264000]: Cmd Published
[INFO] [1626632356.449786, 152.378000]: Cmd Published
[INFO] [1626632362.453462, 158.051000]: Cmd Published
[INFO] [1626632370.462114, 165.546000]: Cmd Published
[INFO] [1626632376.468487, 171.280000]: Cmd Published
[INFO] [1626632384.477323, 179.006000]: shutdown time! Stop the robot
[INFO] [1626632384.478129, 179.007000]: Cmd Published
[INFO] [1626632384.479776, 179.008000]: ######## Finished Moving in a Square
[INFO] [1626632384.480652, 179.009000]: shutdown time! Stop the robot
[INFO] [1626632384.481054, 179.009000]: Cmd Published
big square movement
[INFO] [1626632385.821501, 180.264000]: Cmd Published
[INFO] [1626632397.834714, 191.844000]: Cmd Published
[INFO] [1626632405.841583, 199.580000]: Cmd Published
[INFO] [1626632417.854378, 211.097000]: Cmd Published
[INFO] [1626632425.863010, 218.787000]: Cmd Published
[INFO] [1626632437.876047, 230.217000]: Cmd Published
[INFO] [1626632445.884627, 238.022000]: Cmd Published
[INFO] [1626632457.897633, 249.757000]: Cmd Published
[INFO] [1626632465.906051, 257.588000]: shutdown time! Stop the robot
[INFO] [1626632465.906632, 257.588000]: Cmd Published
[INFO] [1626632465.907379, 257.588000]: ######## Finished Moving in a Square
[INFO] [1626632465.908322, 257.588000]: shutdown time! Stop the robot
[INFO] [1626632465.908768, 257.588000]: Cmd Published
user:~/catkin_ws/src/linux_exam$

Hi @Yelaina ,

for the problem

The problem is in the space before and after “=” in the code below:

When assigning values to variables in bash script, you cannot leave spaces.

To solve this error the correct way of defining the variable would be like as follows:

#!/bin/bash

ARG1=$1

Please let us know if you have any other problems.

Thank you so much "ralves. It graded me correctly after removing the space.

1 Like

Thank you @Ralves. It works.

1 Like

I’m happy to hear it works, @Yelaina.

Cheers.

Hi Ralves,

Please can you also help me look at this? it gives me good values when i run it but the grader marks me wrong everytime. This is the python exam for task1 to get highest and lowest position of laser values. My code is below;

from robot_control_class import RobotControl

def get_highest_lowest():

r1 = RobotControl()

l1 = r1.get_laser_full()



lowest = l1[0] #first input

highest = l1[0] #first input



#for minimum



for i in l1:

    if i != float("inf") and i != float("-inf")  :

        if lowest > i:

            lowest = i

min_index = l1.index(lowest)



#for maximum



for i in l1:

    if i != float("inf") and i != float("-inf")  :

        if highest < i:

            highest = i
 max_index = l1.index(highest)



return max_index, min_index

get_highest_lowest()

Hi Ralves,

Please dont bother with my question, I figured that the call to the function should not be there. It works now, thank you.

1 Like