8 from std_msgs.msg 
import String
     9 from sensor_msgs.msg 
import JointState
    10 from trajectory_msgs.msg 
import JointTrajectory
    11 from trajectory_msgs.msg 
import JointTrajectoryPoint
    12 from control_msgs.msg 
import FollowJointTrajectoryActionGoal
    19 def gen_traj(joint_limits = np.array([[-math.pi, math.pi]] * 6), 
    26     traj = JointTrajectory()
    27     traj.joint_names = [ 
'shoulder_pan_joint', 
    28                          'shoulder_lift_joint', 
    34     traj.header.frame_id = 
'/world'    39     init_pose = np.array(last_js.position) 
    40     init_pose[0:3] = init_pose[2::-1]
    42     pos = np.array([0.] * 6)
    43     vel = np.array([0.] * 6)
    44     acc = np.array([0.] * 6)
    54         point = JointTrajectoryPoint()
    55         point.positions = pos + init_pose
    56         point.velocities = [0.] * 6
    57         point.accelerations = [0.] * 6
    58         point.time_from_start = rospy.Duration(t)
    60         traj.points.append(point)
    62         pos += vel * time_step
    63         pos = np.minimum(pos, joint_limits[:,1])
    64         pos = np.maximum(pos, joint_limits[:,0])
    66         vel += acc * time_step
    67         vel = np.minimum(vel, vel_limit)
    68         vel = np.maximum(vel, -vel_limit)
    73         if iters % action_step == 0:
    74             acc = np.random.rand(6) - 0.5
    75             acc = acc / np.linalg.norm(acc)
    82     point = JointTrajectoryPoint()
    83     point.positions = init_pose
    84     point.velocities = [0.] * 6
    85     point.accelerations = [0.] * 6
    86     point.time_from_start = rospy.Duration(duration + 3)
    88     traj.points.append(point)
    97     traj_pub = rospy.Publisher(
'/arm_controller/follow_joint_trajectory/goal', FollowJointTrajectoryActionGoal, queue_size=10)
    98     rospy.init_node(
'generate_trajectory', anonymous=
True)
    99     rospy.Subscriber(
"/joint_states", JointState, js_callback)
   102     while 'last_js' not in globals() 
and not rospy.is_shutdown(): 
pass   104     joint_limits = np.array([[-math.pi, math.pi]] * 6)
   110     traj = 
gen_traj(joint_limits = joint_limits, action_step = 10, duration = 10, acc_mod = 10., vel_limit = 0.5, time_step = 0.01)
   112     goal = FollowJointTrajectoryActionGoal()
   113     goal.goal.trajectory = traj
   125         bag.write(
'/follow_joint_trajectory/goal', goal)
   129     traj_pub.publish(goal)
   133 if __name__ == 
'__main__':
   136     except rospy.ROSInterruptException:
 
def gen_traj(joint_limits=np.array([[-math.pi, math.pi]]*6), vel_limit=0.1, acc_mod=0.1, time_step=0.1, action_step=10, duration=10)