-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (44 loc) · 1.56 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import rospy
from robot_controller import Robot
from robot_controller import PoseConverter, calculate_relative_pose
def wait(on=True):
"""Waits for user input to continue
Args:
on (bool, optional): enable or disable waiting. Defaults to True.
"""
if on:
inp = input('continue? Y/N')
if inp == "N":
return exit()
def sleep(t):
"""Sleeps for t seconds using rospy.sleep
Args:
t (float): time in seconds
"""
duration = rospy.Duration(t)
rospy.sleep(duration)
if __name__ == '__main__':
rospy.init_node('robot_control', anonymous=True)
sleep(1)
robot = Robot()
# enable robot if working with real robot
robot.enable()
# define target pose
pose = PoseConverter([0.5, 0.5, 0.5], [0, 0, 0]).get_pose()
# move robot without blocking using move_ptp
robot.move_ptp(pose, blocking=False)
# wait for robot to finish movement
while robot.in_motion():
sleep(0.1)
# define target pose
pose = PoseConverter([0.45, 0.45, 0.45], [0, 0, 0]).get_pose()
# move robot while blocking using cartesian movement
# this line will block until the robot has reached the target pose
robot.move_cartesian_path([pose], blocking=True)
# get current pose
current_pose = robot.get_tool_pose()
# calculate relative pose
new_pose = calculate_relative_pose(current_pose, position=[0, 0, 0.1])
# move using linear movement
robot.move_linear(new_pose, blocking=True)