5 import moveit_commander
6 from geometry_msgs.msg
import Vector3, Quaternion
8 from tf.transformations
import quaternion_from_euler, euler_from_quaternion
11 from sensor_msgs.msg
import Joy
12 from geometry_msgs.msg
import Pose
13 from std_msgs.msg
import UInt8
108 rospy.loginfo(
"Teaching. Save")
109 self._teaching_joint_values.append([arm, gripper])
117 rospy.loginfo(
"Teaching. Load")
122 rospy.loginfo(
"Teaching. Index reset")
126 rospy.logwarn(
"Teaching. Joint Values is nothing")
132 rospy.loginfo(
"Teaching. Delete")
142 e = euler_from_quaternion((x, y, z, w))
143 return Vector3(e[0], e[1], e[2])
147 q = quaternion_from_euler(rpy.x, rpy.y, rpy.z)
148 return Quaternion(q[0], q[1], q[2], q[3])
198 self._target_arm_pose.pose.position.x -= msg.axes[self.
_AXIS_POSITION_X] * 0.1
199 self._target_arm_pose.pose.position.y += msg.axes[self.
_AXIS_POSITION_Y] * 0.1
200 self._target_arm_pose.pose.position.z += msg.axes[self.
_AXIS_POSITION_Z] * 0.1
217 rospy.loginfo(
"PID Gain Preset. No." + str(pid_gain_no))
219 preset_no.data = pid_gain_no
220 pub_preset.publish(preset_no)
225 arm = moveit_commander.MoveGroupCommander(
"arm")
226 arm.set_max_velocity_scaling_factor(0.5)
227 arm.set_max_acceleration_scaling_factor(1.0)
228 gripper = moveit_commander.MoveGroupCommander(
"gripper")
232 pid_gain_no = PRESET_DEFAULT
236 gripper.set_joint_value_target([0.9, 0.9])
240 arm.set_named_target(
"home")
244 joy_wrapper.set_target_arm(arm.get_current_pose())
245 joy_wrapper.set_target_gripper(gripper.get_current_joint_values())
248 while joy_wrapper.do_shutdown() ==
False:
250 if joy_wrapper.get_and_reset_grip_update_flag():
251 gripper.set_joint_value_target(joy_wrapper.get_target_gripper())
255 if joy_wrapper.get_and_reset_pose_update_flag():
256 arm.set_pose_target(joy_wrapper.get_target_arm())
257 if arm.go() ==
False:
259 joy_wrapper.set_target_arm(arm.get_current_pose())
262 if joy_wrapper.get_and_reset_name_update_flag():
263 arm.set_named_target(joy_wrapper.get_target_name())
266 joy_wrapper.set_target_arm(arm.get_current_pose())
269 if joy_wrapper.get_and_reset_preset_update_flag():
271 if pid_gain_no == PRESET_DEFAULT:
272 pid_gain_no = PRESET_FREE
274 pid_gain_no = PRESET_DEFAULT
277 arm.set_pose_target(arm.get_current_pose())
281 joy_wrapper.set_target_arm(arm.get_current_pose())
284 teaching_flag = joy_wrapper.get_and_reset_teaching_flag()
285 if teaching_flag == joy_wrapper.TEACHING_SAVE:
289 arm_joint_values = arm.get_current_joint_values()
290 gripper_joint_values = gripper.get_current_joint_values()
292 arm.set_joint_value_target(arm_joint_values)
293 gripper.set_joint_value_target(gripper_joint_values)
294 joy_wrapper.save_joint_values(arm_joint_values, gripper_joint_values)
296 print(
"Error setting joint target. Is the target within bounds?")
297 elif teaching_flag == joy_wrapper.TEACHING_LOAD:
299 joint_values = joy_wrapper.load_joint_values()
301 arm.set_joint_value_target(joint_values[0])
303 gripper.set_joint_value_target(joint_values[1])
306 joy_wrapper.set_target_arm(arm.get_current_pose())
307 joy_wrapper.set_target_gripper(gripper.get_current_joint_values())
308 elif teaching_flag == joy_wrapper.TEACHING_DELETE:
310 joy_wrapper.delete_joint_values()
313 rospy.loginfo(
"Shutdown...")
316 arm.set_named_target(
"vertical")
320 if __name__ ==
'__main__':
321 rospy.init_node(
"joystick_example")
326 pub_preset = rospy.Publisher(
"preset_gain_no", UInt8, queue_size=1)
329 if not rospy.is_shutdown():
331 except rospy.ROSInterruptException:
def get_and_reset_preset_update_flag(self)
def _callback_joy(self, msg)
_target_gripper_joint_values
def set_target_gripper(self, joint_values)
def set_target_arm(self, pose)
def _orientation_to_rpy(self, orientation)
def load_joint_values(self)
def delete_joint_values(self)
def get_and_reset_grip_update_flag(self)
def save_joint_values(self, arm, gripper)
def _rpy_to_orientation(self, rpy)
def preset_pid_gain(pid_gain_no)
def get_target_name(self)
def get_and_reset_teaching_flag(self)
def get_target_gripper(self)
def get_and_reset_pose_update_flag(self)
def get_and_reset_name_update_flag(self)