-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathex_impedance_control_fixed.py
More file actions
executable file
·124 lines (90 loc) · 4.63 KB
/
Copy pathex_impedance_control_fixed.py
File metadata and controls
executable file
·124 lines (90 loc) · 4.63 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
"""
In these examples we will implement various hybrid motion-force controllers using the impedance control plugin, which can be used for a wide variety of
applications.
Impedance control is BEST SUITED for enabling free, rigid and springy behaviour, along/about each different axis.
While this is perfectly useful for:
- Having a selectively compliant end-effector,
- Switching between fixed and free behaviour to simulate (mostly) rigid constraints, and
- Allowing human intervention for automated operations by separating controls across different axes,
any applications involving more salient control of the forces (as more complex functions with flexible inputs) should use our force control plugin. See ex_force_control_demoname.py.
This comprises the following demos:
- Fixed: A task-space pose controller implemented entirely using force control via the (PD) impedance controller.
- Cartesian: Locks onto a particular end-effector position while having some compliant orientation.
- Gimbal: A gimbal that locks a specific end-effector orientation, while keeping the rest of the arm compliant.
- Floor: The end-effector is free to move but can't travel below a virtual floor. To further simulate sliding on the floor, see force_control example.
- Damping: The end-effector behaves as 3-different damped systems (overdamped, critically damped, and underdamped), at 3 different heights.
The following example is for the "Fixed" demo:
"""
import hebi
import os
from time import sleep
from hebi_util import create_mobile_io_from_config
from plotting import draw_plots
# NOTE: Angle wraparound is an unresolved issue which can lead to unstable behaviour for any case involving rotational positional control.
# Make sure that the rotational gains are high enough to prevent large angular errors. The gains provided in these examples are (mostly) well behaved.
# Interacting with the end-effector in these examples is perfectly safe.
# However, ensure that nothing prevents the wrist's actuators from moving, and DO NOT place your fingers between them.
# Initialize the interface for network connected modules
lookup = hebi.Lookup()
sleep(2)
# Config file
example_config_file = "config/ex_impedance_control_fixed.cfg.yaml" # Relative to this file directory
example_config = hebi.config.load_config(os.path.join(os.path.dirname(os.path.realpath(__file__)), example_config_file))
# Set up arm, and mobile_io from config
arm = hebi.arm.create_from_config(example_config, lookup)
mobile_io = create_mobile_io_from_config(example_config, lookup)
# Clear all position control gains for all the actuators
cmd = arm.pending_command
cmd.position_kp = 0.0
cmd.position_kd = 0.0
cmd.position_ki = 0.0
# Increase feedback frequency since we're calculating velocities at the
# high level for damping. Going faster can help reduce a little bit of
# jitter for fast motions, but going slower (100 Hz) also works just fine
# for most applications.
arm.group.feedback_frequency = 200.0
# Double the effort gains from their default values, to make the arm more sensitive for tracking force.
# TODO
enable_logging = False
goal = hebi.arm.Goal(arm.size)
# Start background logging
if enable_logging:
arm.group.start_log('dir', 'logs', mkdirs=True)
# Print instructions
instructions = """IMPEDANCE CONTROL FIXED EXAMPLE
(On/Off) - Toggles an impedance controller on/off:
ON - Apply controller based on current position and orientation
OFF - Go back to gravity-compensated mode
(Quit) - Exits the demo, and plots graphs if logging is enabled."""
print(instructions)
mobile_io.add_text(instructions)
#######################
## Main Control Loop ##
#######################
controller_on = False
switch_btn = 1
quit_btn = 2
# while quit is not pressed
while not mobile_io.get_button_state(quit_btn):
arm.update()
if mobile_io.update(timeout_ms=0):
# Set and unset impedance mode when button is pressed and released, respectively
if (mobile_io.get_button_diff(switch_btn) == 1):
controller_on = True
arm.set_goal(goal.clear().add_waypoint(position=arm.last_feedback.position))
elif (mobile_io.get_button_diff(switch_btn) == -1):
controller_on = False
# If in impedance mode set led blue
mobile_io.set_led_color("blue" if controller_on else "green", blocking=False)
if not controller_on:
arm.cancel_goal()
arm.send()
mobile_io.set_led_color("red")
##########################
## Logging and Plotting ##
##########################
if enable_logging:
hebi_log = arm.group.stop_log()
draw_plots(hebi_log)
# Add additional plotting code here