[Bug] Error in grading

This is an error report.


Screenshot of the error


Error details

The distance is calculated correctly using odometer, but I cannot get passed the error regarding the distance...

Make sure that the variables you use to calculate the distance are initialized to be float type. That was the problem in my case.

Thanks for your answer! I think that the variables type is correct, I would appreciate you taking a look and check if you see something wrong:) Thanks a lot:
The node of my node is the following, and as I said, I get the feedback and publish to the total_distance topic correctly…
class MyActionServer(Node):

def __init__(self):
    super().__init__('action_quiz_server')
    self._action_server = ActionServer(self, Distance, 'distance_as', self.execute_callback)
    self.publisher_ = self.create_publisher(Twist, 'cmd_vel', 10)
    self.publisher2_ = self.create_publisher(Float64,"total_distance",10)
    self.odom_subscriber = self.create_subscription(Odometry, '/odom', self.odom_callback, 10)
    self.initial_odom = None

def odom_callback(self, msg):
    if self.initial_odom is None:
        self.initial_odom = msg.pose.pose
    self.current_odom = msg.pose.pose

def calculate_distance(self, initial_odom, current_odom):
    initial_position = initial_odom.position
    current_position = current_odom.position
    dx = current_position.x - initial_position.x
    dy = current_position.y - initial_position.y
    return float(math.sqrt(dx**2 + dy**2))


async def execute_callback_async(self, goal_handle):
    self.get_logger().info('Executing goal...')
    feedback_msg = Distance.Feedback()
    move_cmd = Twist()
    move_cmd.linear.x = 0.1
    self.publisher_.publish(move_cmd)
    for i in range(goal_handle.request.seconds):
        await asyncio.sleep(1)
        if self.initial_odom and self.current_odom:
            current_distance_message = Float64()
            current_distance= self.calculate_distance(self.initial_odom, self.current_odom)
            feedback_msg.feedback = current_distance
            current_distance_message.data = current_distance
            self.publisher2_.publish(current_distance_message)
            goal_handle.publish_feedback(feedback_msg)
        self.get_logger().info(f'Current distance: {current_distance}')
    move_cmd.linear.x = 0.0
    current_distance= self.calculate_distance(self.initial_odom, self.current_odom)
    self.publisher_.publish(move_cmd)
    result = Distance.Result()
    result.status = True
    result.total_dist = current_distance
    self.get_logger().info(f'Result status: {result.status}, Total distance: {result.total_dist}')
    goal_handle.succeed()
    self.initial_odom=None
    return result

def execute_callback(self, goal_handle):
    # Esta es una envoltura para ser llamada por ROS2 actions
    asyncio.run(self.execute_callback_async(goal_handle))

From what I see in the logs, if you can make your logger messages look like the one indicated in the notebooks (publishing the message directly), it should work.

image

I don’t think you should have to format your logs in any particular way (but should rather focus on calculating the distance correctly and publishing it), but this is what the gradebot is currently expecting.

I have captured this for review by the team in charge of this quiz. Please bear with us. I have also assigned you two more trials.

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