5 import moveit_commander
6 from std_msgs.msg
import UInt8
7 import sys, tty, termios, select
18 self._teaching_joint_values.append([arm, gripper])
32 rospy.logwarn(
"Joint Values is nothing")
41 rospy.logwarn(
"Joint Values is nothing")
58 fd = sys.stdin.fileno()
59 old = termios.tcgetattr(fd)
62 (result_stdin, w, x) = select.select([sys.stdin], [], [], timeout)
64 return result_stdin[0].read(1)
70 termios.tcsetattr(fd, termios.TCSADRAIN, old)
76 rospy.loginfo(
"PID Gain Preset. No." + str(pid_gain_no))
78 preset_no.data = pid_gain_no
79 pub_preset.publish(preset_no)
84 arm = moveit_commander.MoveGroupCommander(
"arm")
85 arm.set_max_velocity_scaling_factor(0.5)
86 arm.set_max_acceleration_scaling_factor(1.0)
87 gripper = moveit_commander.MoveGroupCommander(
"gripper")
97 is_teaching_mode =
True 98 do_loop_playing =
False 101 gripper.set_joint_value_target([0.9, 0.9])
105 arm.set_named_target(
"home")
115 while do_shutdown
is False:
116 poses_num = data_base.get_num_of_poses()
117 pose_index = data_base.get_current_index() + 1
if poses_num
else 0
123 print(
"[Teaching Mode]" 124 +
"[Next Pose:" + str(pose_index) +
" of " + str(poses_num) +
"]")
125 print(
"[q]: Quit, [m]: switch to action Mode, [s]: Save, [d]: Delete")
127 print(
"[Action Mode]" 128 +
"[Next Pose:" + str(pose_index) +
" of " + str(poses_num) +
"]")
129 print(
"[q]: Quit, [m]: switch to teaching Mode, [p]: Play 1 pose, [a]: play All pose, [l]: Loop play on/off")
131 print(
"Keyboard input >>>")
135 input_key =
getch(0.1)
137 if input_key
is not False:
139 input_code = ord(input_key)
142 if input_code == CTRL_C
or input_code == ord(
'q')
or input_code == ord(
'Q'):
151 arm.set_pose_target(arm.get_current_pose())
153 gripper.set_joint_value_target(gripper.get_current_joint_values())
161 if input_code == ord(
'm')
or input_code == ord(
'M'):
163 is_teaching_mode =
not is_teaching_mode
173 arm.set_pose_target(arm.get_current_pose())
175 gripper.set_joint_value_target(gripper.get_current_joint_values())
185 if input_code == ord(
's')
or input_code == ord(
'S'):
186 print(
"Save joint values")
189 arm_joint_values = arm.get_current_joint_values()
190 gripper_joint_values = gripper.get_current_joint_values()
192 arm.set_joint_value_target(arm_joint_values)
193 gripper.set_joint_value_target(gripper_joint_values)
194 data_base.save_joint_values(arm_joint_values, gripper_joint_values)
196 print(
"Error setting joint target. Is the target within bounds?")
202 if input_code == ord(
'd')
or input_code == ord(
'D'):
203 print(
"\nDelete joint values")
204 data_base.delete_joint_values()
210 if input_code == ord(
'p')
or input_code == ord(
'P'):
212 joint_values = data_base.load_joint_values()
214 arm.set_joint_value_target(joint_values[0])
216 gripper.set_joint_value_target(joint_values[1])
222 if input_code == ord(
'a')
or input_code == ord(
'A'):
223 print(
"play All poses")
224 all_joint_values = data_base.load_all_joint_values()
226 for i, joint_values
in enumerate(all_joint_values):
227 print(
"Play: " + str(i+1) +
" of " + str(poses_num))
228 arm.set_joint_value_target(joint_values[0])
230 gripper.set_joint_value_target(joint_values[1])
236 if input_code == ord(
'l')
or input_code == ord(
'L'):
239 do_loop_playing =
not do_loop_playing
252 joint_values = data_base.load_joint_values()
254 print(
"Play " + str(pose_index) +
" of " + str(poses_num))
256 arm.set_joint_value_target(joint_values[0])
258 gripper.set_joint_value_target(joint_values[1])
262 print(
"Loop play OFF")
263 do_loop_playing =
False 269 arm.set_named_target(
"vertical")
273 if __name__ ==
'__main__':
274 rospy.init_node(
"teaching_example")
279 pub_preset = rospy.Publisher(
"preset_gain_no", UInt8, queue_size=1)
282 if not rospy.is_shutdown():
284 except rospy.ROSInterruptException:
def delete_joint_values(self)
def get_current_index(self)
def preset_pid_gain(pid_gain_no)
def save_joint_values(self, arm, gripper)
def load_all_joint_values(self)
def load_joint_values(self)
def get_num_of_poses(self)