This is an error report.
Screenshot of the error
Error details
I am unable to pass the chapter 3 quiz because the grading bot is claiming that I did not subscribe to "/odom" topic although I am clearly using it in my code additionally I successfully ran my code and was able to pass the quiz requirments
Hello, could you please provide the whole code you have wrote in for the node. So that I can check it for you if you are missing something.
1 Like
First, I see that you attempted the quiz four times before contacting us. You should contact us after the second trial, max, if you think the grader is wrong.
Second, did you check the points highlighted by the grader? One of them was:
Did you use the right node name? It should be topics_quiz_node
Your node name was topics_quiz instead of topics_quiz_node. Please review the chapter and the quiz again, and ensure you follow all guidelines for the quiz. The grader will fail you if you don’t follow the guidelines, even if your code works.
import rclpy
import numpy as np
import time
# import the ROS2 python libraries
from rclpy.node import Node
# import the Twist module from geometry_msgs interface
from geometry_msgs.msg import Twist
# import the LaserScan module from sensor_msgs interface
from nav_msgs.msg import Odometry
from sensor_msgs.msg import LaserScan
from rclpy.qos import ReliabilityPolicy, QoSProfile
class topics_quiz(Node):
def __init__(self):
# Here you have the class constructor
# call the class constructor
super().__init__('topics_quiz')
# create the publisher object
self.publisher_twist_ = self.create_publisher(Twist, 'cmd_vel', 10)
# create the subscriber object
self.subscriber_odom_ = self.create_subscription(Odometry, '/odom', self.Odometry_callback, QoSProfile(depth=10, reliability=ReliabilityPolicy.RELIABLE))
self.subscriber_laser_ = self.create_subscription(LaserScan, '/scan', self.laser_callback, QoSProfile(depth=10, reliability=ReliabilityPolicy.RELIABLE))
# define the timer period for 0.5 seconds
self.timer_period = 0.2
# define the variable to save the received info
self.laser_forward = 0
self.odom_raw = 0
self.odom_filter = 0
self.status = 'idle'
self.master_goal = False
self.goal1 = False
self.goal2 = False
self.goal3 = False
self.goal4 = True
self.roll = 0
self.pitch = 0
self.yaw = 0
self.y =0
# create a Twist message
self.cmd = Twist()
self.timer = self.create_timer(self.timer_period, self.motion)
self.rotation = 0
time.sleep(3)
def euler_from_quaternion(self, quaternion):
x = quaternion.x
y = quaternion.y
z = quaternion.z
w = quaternion.w
sinr_cosp = 2 * (w * x + y * z)
cosr_cosp = 1 - 2 * (x * x + y * y)
roll = np.arctan2(sinr_cosp, cosr_cosp)
sinp = 2 * (w * y - z * x)
pitch = np.arcsin(sinp)
siny_cosp = 2 * (w * z + x * y)
cosy_cosp = 1 - 2 * (y * y + z * z)
yaw = np.arctan2(siny_cosp, cosy_cosp)
return roll, pitch, yaw
def laser_callback(self,msg):
# Save the frontal laser scan info at 0°
self.laser_forward = msg.ranges[90]
def Odometry_callback(self,msg):
self.odom_raw = msg.pose.pose.orientation
self.y = msg.pose.pose.position.y
self.roll, self.pitch, self.yaw = self.euler_from_quaternion(self.odom_raw)
self.get_logger().info('I receive yaw: "%s"' % str(self.yaw))
def motion(self):
# print the data
if self.laser_forward == 0:
return
self.get_logger().info('I receive laser: "%s"' % str(self.laser_forward))
self.get_logger().info('I receive y movment: "%s"' % str(self.y))
if self.laser_forward != float('inf')and self.goal1 == False and self.goal2 == False and self.goal3 == False and self.goal4 == True:
self.cmd.linear.x = 0.5
self.get_logger().info('Goal1 if')
elif self.laser_forward == float('inf')and self.goal1 == False and self.goal2 == False and self.goal3 == False and self.goal4 == True:
self.cmd.linear.x = 0.0
self.goal1 = True
if self.yaw < 1.4 and self.goal1 == True and self.goal2 == False and self.goal3 == False:
self.cmd.angular.z = 0.25
self.get_logger().info('Goal2')
elif self.yaw >= 1.4 and self.goal1 == True and self.goal2 == False and self.goal3 == False:
self.cmd.angular.z = 0.0
self.goal2 = True
if self.y < 0.75 and self.goal1 == True and self.goal2 == True and self.goal3 == False:
self.cmd.linear.x = 0.5
self.get_logger().info('Goal3')
elif self.y >= 0.75 and self.goal1 == True and self.goal2 == True and self.goal3 == False:
self.cmd.linear.x = 0.0
self.goal3 = True
if self.goal1 == True and self.goal2 == True and self.goal3 == True:
self.master_goal = True
self.get_logger().info('Goal_Master')
else:
self.master_goal = False
self.publisher_twist_.publish(self.cmd)
def main(args=None):
# initialize the ROS communication
rclpy.init(args=args)
# declare the node constructor
topics_quiz1 = topics_quiz()
# pause the program execution, waits for a request to kill the node (ctrl+c)
rclpy.spin(topics_quiz1)
# Explicity destroy the node
topics_quiz1.destroy_node()
# shutdown the ROS communication
rclpy.shutdown()
if __name__ == '__main__':
main()
I attempted the quiz two times only please see screenshot below. Also, the name of the node is topics_quiz_node.py but the class defined in the python code is named “topics_quiz”. Should I just rename it?
My bad, that’s correct. I mistook the score for the number of trials. I apologise.
The node name is not the name of the Python file. Yes, you should change the name in the code as well as the one you used in the setup.py’s console_scripts key and, finally, in the launch file.
The issue has been resolved by changing the class name. Thank you for your kind assistance.
1 Like
system
Closed
July 29, 2024, 1:30pm
10
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.