ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

AssertionError: The 'time_from_start' field must be a sub message of type 'Duration'

asked 2023-05-29 03:24:49 -0500

Icon45 gravatar image

updated 2023-05-29 03:26:12 -0500

Hi everyone,

i created a python node, that should controll a Universal Robot UR10 via a Joint Trajectory. Here's its code:

#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from rclpy.time import Duration
from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint


class Ur10ManualJoints(Node):

    def __init__(self):
        super().__init__('Ur10ManualJoints')

        #Publisher creation
        self.publisher = self.create_publisher(JointTrajectory, 'joint_trajectory', 10)


        joint_name = ['shoulder_pan_joint', 'shoulder_lift_joint','elbow_joint', 'wrist_1_joint', 'wrist_2_joint', 'wrist_3_joint']
        joint_pos = []
        for joint_name in joint_name:
            pos = input(f'Gebe Position für {joint_name} ein:') # Translation: Enter position for {joint_name}
            joint_pos.append(float(pos)) 

        #Constructing the Message
        joint_traj_msg = JointTrajectory()
        joint_traj_msg.joint_names = joint_name

        point = JointTrajectoryPoint()
        point.positions = joint_pos
        point.time_from_start = Duration(seconds=10)

        joint_traj_msg.points.append(point)

        #Publish th msg
        self.get_logger().info(f"[HINWEIS] Nachricht: {joint_traj_msg} wurde veröffentlicht") #Translation: Message {joint_traj_msg} was published
        self.publisher.publish(joint_traj_msg)

def main(args=None):
    rclpy.init(args=args)
    node = Ur10ManualJoints()
    rclpy.spin(node)
    rclpy.shutdown()

if __name__ == '__main__':
    main()

And here's the Error i get when running the node:

ros2 run ur10_faps_driver Ur10ManualJoints
Gebe Position für shoulder_pan_joint ein:1
Gebe Position für shoulder_lift_joint ein:1
Gebe Position für elbow_joint ein:1
Gebe Position für wrist_1_joint ein:1
Gebe Position für wrist_2_joint ein:1
Gebe Position für wrist_3_joint ein:1
Traceback (most recent call last):
  File "/home/ubuntu/Schreibtisch/ros2_ws/install/ur10_faps_driver/lib/ur10_faps_driver/Ur10ManualJoints", line 33, in <module>
    sys.exit(load_entry_point('ur10-faps-driver==0.0.0', 'console_scripts', 'Ur10ManualJoints')())
  File "/home/ubuntu/Schreibtisch/ros2_ws/install/ur10_faps_driver/lib/python3.10/site-packages/ur10_faps_driver/Ur10ManualJoints.py", line 39, in main
    node = Ur10ManualJoints()
  File "/home/ubuntu/Schreibtisch/ros2_ws/install/ur10_faps_driver/lib/python3.10/site-packages/ur10_faps_driver/Ur10ManualJoints.py", line 29, in __init__
    point.time_from_start = Duration(seconds=10)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/trajectory_msgs/msg/_joint_trajectory_point.py", line 271, in time_from_start
    assert \
AssertionError: The 'time_from_start' field must be a sub message of type 'Duration'
1[ros2run]: Process exited with failure 1

Does anyone know wahts going on here, bc i didn`t find anything on the internet about such an error.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2023-05-29 07:47:55 -0500

Mike Scheutzow gravatar image

updated 2023-05-29 14:42:45 -0500

The 'time_from_start' field must be a sub message of type 'Duration'

You are using the wrong type of object. These two object types are not interchangable: rclpy.time.Duration and builtin_interfaces.msg.Duration

You can convert between them using the time.Duration methods to_msg() and from_msg()

from rclpy.time import Duration
my_duration_msg = Duration(seconds=10.0).to_msg()
edit flag offensive delete link more

Comments

Hi Mike,

thanks for your answer, i updated the line from rclpy.time import Duration to from biultin_interfaces.msg import Duration and now i' getting the following error: TypeError: Duration.__init__() takes 1 positional argument but 2 were given

The line where i use the Duration is now as follows:

point.time_from_start = Duration(1.0)
Icon45 gravatar image Icon45  ( 2023-05-29 09:40:23 -0500 )edit

I updated my answer.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2023-05-29 14:43:14 -0500 )edit

Hi Mike thank you very much for the update. It Worked!

Icon45 gravatar image Icon45  ( 2023-05-30 01:20:09 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2023-05-29 03:24:49 -0500

Seen: 321 times

Last updated: May 29 '23