Auto grader on quiz 1

Hey,
my robot successful moved around the wall. However, when I check the solution I got a 7/10. I made sure the robot had no view of the wall at the end. Does anyone know what might be going wrong? I have attached my code below.

Cheers,

Josh

#! /usr/bin/env python

import rospy
from geometry_msgs.msg import Twist # Import twist messages for velocity control
from sensor_msgs.msg import LaserScan # Import LaserScan to read values

Grab the middle sensor reading

left = 0
straight = 0
right = 0
def callback(msg):
global left
global straight
global right
right = msg.ranges[260]
straight = msg.ranges[360]
left = msg.ranges[460]
print("Left: " , left)
print("Right: ", right)
print(ā€œStraightā€, straight)

rospy.init_node(ā€˜Topic_quiz_nodeā€™)
sub = rospy.Subscriber(ā€™/kobuki/laser/scanā€™, LaserScan, callback)

#Make the robot move
pub = rospy.Publisher(ā€™/cmd_velā€™, Twist, queue_size=1)
rate = rospy.Rate(2)
move = Twist()

while not rospy.is_shutdown():
if left > 1.5 and straight > 1.5 and right > 1.5: # no object detected
move.linear.x = 0.5
move.angular.z = 0
else: # object detected
move.linear.x = 0
move.angular.z = 0.5

pub.publish(move)  # puplish to topic in order to move the robot
rate.sleep()       # sleep to keep rate at 2 hz
1 Like

Hi @josho.wallace,
first of all welcome to the community :slight_smile:

Where exactly is your robot at the end? has it passed the wall? or is it just not looking at it anymore? You might have misinterpreted the instructions. It has to pass the wall, not just not look at it. Otherwise you could just turn 180 degrees and be done. If you havenā€™t looked at the solution, you get one more try at the quiz. Make sure to test your script before correction.

2 Likes

Thanks!

It goes past the wall into the distance but at an angle. Do I want it to go around the wall?

2 Likes

That should not be a requirement. What correction step failed?
@bayodesegun perhaps you can take a look at this.

2 Likes

While I was waiting for the auto grader to complete I got a warning about not having a subscriber. However, I did have a subscriber otherwise the robot would have gone straight into the wall.

2 Likes

I donā€™t quite understand how your code is working for you. I tried it myself and it doesnā€™t work. You are constantly calling the subscriber after completing the callback, so anything below
sub = rospy.Subscriber(ā€™/kobuki/laser/scanā€™, LaserScan, callback)
does not get executed.

2 Likes

I have a similar issue, the robot is avoiding the wall and I am getting the points for this. But I am not getting the points for the subscriber and the publisher. I have tested them with ā€˜rostopic infoā€™ while my node is running and they are both there and as they should be.

Perhaps the problem was that I was terminating the node when the robot was not anymore in front of the wall. Unfortunately I have no other trials to check if it is so.

2 Likes

So I reran the code. The first time it did not work, but after resetting the simulation and launching the package again, everything worked as before(Four times in a row). I even put a print statement below the subscriber line to see if everything was running below and it worked. I donā€™t understand why I would be constantly calling the subscriber after completing the callback. All the examples I have seen in unit 2 set up the subscriber the same way. Thank you for the help and I appreciate your patience!

1 Like

Hello there!

@micha132003 and @josho.wallace Letā€™s do one thing. Can you send me the package/s you are using for this Quiz? I will test them here with the autocorrection system, and see whatā€™s going on. You can send them to aezquerro@theconstructsim.com

Best,

1 Like

Hey Alberto,

I am not exactly sure how to extract the package from the construct simulation. Is there a simple way to do this?

Cheers,

Josh

1 Like

Just right click on your package, and there is an option to download it to your local pc.

1 Like

Hello Alberto,

I have sent you my package in your email on October 4th. Do you have already any results?

Best wishes
Michail

Hello there!

Iā€™ve just had the chance to review your packages, and hereā€™s what Iā€™ve found:

For @micha132003 : In your case, the problem is that your program is ending too quickly. It takes just a few seconds to execute, so when the autocorrection system looks for the laser subscription, your program has already ended (thus thereā€™s no subscription). This is because of the approach you used to solve the problem, which is to just rotate the robot until it doesnā€™t have the wall in front of it. I think thereā€™s a lack of information in this Quiz, so Iā€™m going to update it in order to add more specific instructions and avoid these kind of issues in the future.

For @josho.wallace: In your case, the problem is in the name of the ROS node. In the Quiz itā€™s specified that this name has to be topics_quiz_node. In your program, though, the name of the node is Topic_quiz_node. Furthermore, in the launch file you rename the node to robot_age (remember that the node name in the launch file overwrites the one in the script). So, at the end, the name of your node is robot_age. Because of this, our autocorrection system doesnā€™t detect it. You have to rename your node to topics_quiz_node. This is why itā€™s so important to follow the specifications in the Quiz.

Best,

2 Likes

Hello Alberto,

thank you for the detailed information.

I think you have mixed the cases. My program is the one that ends in few seconds. Actually is what I was also thinking, but after I used my two attempts. Do I gain one more trial as the instructions were not specific :innocent: ?

Best wishes
Michail

1 Like

Hey @albertoezquerro,

Thank you for the response. I corrected the naming of the nodes and it fixed the problem.

Cheers,

Josh

1 Like

Okay, weā€™re giving you one more trial for this :).

Best wishes on your next trial!

1 Like

Thank you!
I have changed my program, so that it will not terminate too quickly and I received all points.

2 Likes