# 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!

Originally posted by Zero on ROS Answers with karma: 104 on 2016-06-13

Post score: 1

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!

Originally posted by janindu with karma: 849 on 2016-06-14

This answer was ACCEPTED on the original site

Post score: 0

Comment by Zero on 2016-06-14:
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

Comment by janindu on 2016-06-15:
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.

Comment by janindu on 2016-06-15:
... 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...

Comment by janindu on 2016-06-15:
... 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.

Comment by janindu on 2016-06-15:
... You can only append point to self._goal.trajectory.points, which is what's being done by append().

Hope it's clear!

Comment by Zero on 2016-06-15:
Wow! yes!i get that! Thank you so much! Your explain is really useful for me.