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

# confuse about the Baxter joint trajectory program

Hi, everyone

I currently was learning use simple Joint trajectory way to control the robot arm. The example shows in the Baxter wiki there the explain was a bit confuse for me. Here is the program:

def add_point(self, positions, time):
point = JointTrajectoryPoint()
point.positions = copy(positions)
point.time_from_start = rospy.Duration(time)
self._goal.trajectory.points.append(point)


this is the link of the example: Joint Trajectory Client

By the way, the example they had missing some of the code lines which was:

    print("Initializing node... ")
rospy.init_node("rsdk_joint_trajectory_client_%s" % (limb,))
print("Getting robot state... ")
rs = baxter_interface.RobotEnable(CHECK_VERSION)
print("Enabling robot... ")
rs.enable()
print("Running. Ctrl-c to quit")
positions = {
'left':  [-0.11, -0.62, -1.15, 1.32,  0.80, 1.27,  2.39],
'right':  [0.11, -0.62,  1.15, 1.32, -0.80, 1.27, -2.39],
}


And my question is why in the add_point() there have to use copy(positions) and at the end of function still have to use append() to add the point into the list again?

Thank you so much!

edit retag close merge delete

Sort by ยป oldest newest most voted

Lets take add_point() line by line.

point = JointTrajectoryPoint()


Get a new JointTrajectroty point.

point.positions = copy(positions)


Copy the arg positions into the newly created point's positions attribute.

point.time_from_start = rospy.Duration(time)


Set time_from_start of point

self._goal.trajectory.points.append(point)


Append this newly created point to the list self._goal.trajectory.points

copy(positions) is used to simply copy the lists to the new JointTrajectory point. You can't append() positions directly to self._goal.trajectory.points. You can only append() points.

Hope it's clear!

more

Hi Janindu, Frist of all, thank you for your replying. After your explain it really help me to understand how to use the copy() and append(), but in the end, you mention that I can only append() points, that points which one are you refer to? Are you referring to the point.positions ? Thanks

( 2016-06-14 23:46:37 -0500 )edit
1

So, self._goal.trajectory.points is simply a list of JointTrajectory points. ie : self._goal.trajectory.points = [p1, p2, p3] where p1, p2, p3 are of type JointTrajectory.

continued in the next comment.

( 2016-06-15 00:15:38 -0500 )edit
1

... Each p ( point) looks like this :

{
float64[] positions
float64[] velocities
float64[] accelerations
float64[] effort
duration time_from_start
}


Now using copy() you copy the positions passed as arguments to the point.

continued...

( 2016-06-15 00:17:24 -0500 )edit
1

... positions look like this:

positions = {
'left':  [-0.11, -0.62, -1.15, 1.32,  0.80, 1.27,  2.39],
'right':  [0.11, -0.62,  1.15, 1.32, -0.80, 1.27, -2.39],
}


You can't append positions to self._goal.trajectory.points when that list expects point

cont.

( 2016-06-15 00:18:45 -0500 )edit
1

... You can only append point to self._goal.trajectory.points, which is what's being done by append().

Hope it's clear!

( 2016-06-15 00:19:32 -0500 )edit

Wow! yes!i get that! Thank you so much! Your explain is really useful for me.

( 2016-06-15 00:49:29 -0500 )edit