Ask Your Question
1

Filling the Goal of FollowJointTrajectory in Python

asked 2013-02-04 23:49:03 -0500

Mingyuan Wang gravatar image

updated 2014-01-28 17:15:06 -0500

ngrennan gravatar image

Hi everyone,

I'm using Python to create (for my ros_smach) a connection to the ActionServer "control_msgs/FollowJointTrajectory". To call the function SimpleActionState() I have to specify a goal. I hard-coded this goal1 and tried to pass it through the function call.

        # Define the goal for the ActionServer
        goal1=FollowJointTrajectoryGoal()  #create an empty goal    
        goal1.trajectory.points[0].positions = [296.82, 294.143, 523.638, -46.3056, 71.3728, -137.832]  #define the point position of the goal(hard-coded) !!!This line gives an error saying "IndexError: list index out of range"!!!

        # Add a state to the container
        smach.StateMachine.add('PTP1',
            smach_ros.SimpleActionState('SiliaAction_TrajServer', 
                                         FollowJointTrajectoryAction, 
                                         goal = goal1
                                       ),
            transitions={'succeeded':'NextState'})

The problem is this created goal1 does not have an entry called "positions" under goal1.trajectory.points. To be more precise, goal1.trajectory.points is an empty array, which looks like this if I print it out:

trajectory: 
  header: 
    seq: 0
    stamp: 
      secs: 0
      nsecs: 0
    frame_id: ''
  joint_names: []
  points: []  # here it is
path_tolerance: []
goal_tolerance: []
goal_time_tolerance: 
  secs: 0
  nsecs: 0

Is there any method to fill in this goal and pass it on, for example by the time when calling the constructor FollowJointTrajectoryGoal() and fill my desired positions here?

Thank you for your answers!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-02-05 00:18:27 -0500

dornhege gravatar image

updated 2013-02-05 00:18:43 -0500

You should look at the index error. You can't access points[0] as it doesn't exist yet. The list is empty. Use points.append(...) to add an entry to the list.

edit flag offensive delete link more
0

answered 2013-02-05 03:02:23 -0500

Mingyuan Wang gravatar image

updated 2013-02-05 03:03:57 -0500

I solved it now.

Thank you dornhege for your help and effort, this ".append()" was really the important part. Still, what I missed was the concrete access to affect sub-objects of "points". The problem was solved with the following code:

        # Define the goal for the ActionServer
        goal1=FollowJointTrajectoryGoal()  #create an empty goal
        goal1.trajectory.points.append(trajectory_msgs.msg.JointTrajectoryPoint(positions = [296.82, 294.143, 523.638, -46.3056, 71.3728, -137.832]) )   #append a JointTrajectoryPoint with specified positions which becomes goal1.trajectory.points[0]

        # Add a state to the container
        smach.StateMachine.add('PTP1',
            smach_ros.SimpleActionState('SiliaAction_TrajServer', 
                                     FollowJointTrajectoryAction, 
                                     goal = goal1
                                   ),
            transitions={'succeeded':'NextState'})

The appended point automatically got the entry "positions" with the instantiation (with the above line). This is not visible however, if no point is appended to it, as in my original case.

Now if I print out goal1:

trajectory: 
  header: 
    seq: 0
    stamp: 
      secs: 0
      nsecs: 0
    frame_id: ''
  joint_names: []
  points:  # here it is
    - 
      positions: [296.82, 294.143, 523.638, -46.3056, 71.3728, -137.832]
      velocities: []
      accelerations: []
      time_from_start: 
        secs: 0
        nsecs: 0
path_tolerance: []
goal_tolerance: []
goal_time_tolerance: 
  secs: 0
  nsecs: 0
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-02-04 23:49:03 -0500

Seen: 991 times

Last updated: Feb 05 '13