Task2.sh and task1.py

Regarding task2.sh, I don’t know why the code runs correctly (calling the correct function, but the evaluation keeps putting it wrong. Not sure if I understood what was asked.

#!/bin/bash

read opcion

if [ $opcion == "small_square" ]; then
    rosrun linux_exam small_square.py;
elif [ $opcion == "medium_square" ]; then
    rosrun linux_exam medium_square.py;
elif [ $opcion == "big_square" ]; then
    rosrun linux_exam big_square.py;
else
    echo "choose other option"
    exit 1
fi

For the case of task1.py, also i don’t know what’s wrong with it since the code does return the highest and the lowest indexes, and the code does not show errors

from robot_control_class import RobotControl


def get_highest_lowest():
    control = RobotControl()
    tupleallvalues = control.get_laser_full()
    allvalues = list(tupleallvalues)
    

    for i in range(len(allvalues)-1, -1, -1):
        if allvalues[i] == float('inf'):
            del allvalues[i]


    max = allvalues[0]
    for i in range(len(allvalues)-1):
        if max < allvalues[i]:
            max = allvalues[i]
    poshigh = allvalues.index(max)

    min = allvalues[0]
    for i in range(len(allvalues)-1):
        if min > allvalues[i]:
            min = allvalues[i]
    
    
    poslow = allvalues.index(min)

    

    return poshigh, poslow

Hi @valerialoera ,

Welcome to this Community!

Regarding Task2.sh:

I think the way you are running the bash file is wrong.
You need to set executable permissions to the bash file and run the bash file without bash keyword.
This is what you do:

# cd to the directory containing task2.sh
chmod 755 ./task2.sh
./task2.sh <small/medium/big>_square

Regarding Task1.py:

Your algorithm is wrong.
You are getting all laser scan values as a tuple and converting it into list - this is fine.
Then you are deleting the values that are equal to “inf” - this is wrong step.
You should instead avoid reading “inf” values in your for loops.

By deleting the “inf” values in the list, you are essentially shortening the list elements.
So if the highest value was in index 250 (for example), and you have a total of 500 elements out of which 200 are “inf” values, when you delete all the “inf” values, you are reducing your 500 element list to a 300 element list.
So the highest value index, which was originally at 250, now gets reduced to a value less than 250.
Therefore, the solution will ALWAYS yield wrong answer.

I hope you understood my response. Don’t hesitate to reply if you still need help.

Regards,
Girish

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.