|
2 | 2 |
|
3 | 3 | import sys
|
4 | 4 | import time
|
| 5 | +import os |
| 6 | +import signal |
5 | 7 |
|
6 | 8 | from helm_basis import *
|
| 9 | +import activity.panels, activity.logging |
7 | 10 |
|
8 | 11 | import shm
|
9 | 12 |
|
@@ -71,102 +74,110 @@ def get_battery_status():
|
71 | 74 | status_line = ' Voltages nominal.'
|
72 | 75 | return (voltage_line, status_line)
|
73 | 76 |
|
74 |
| - drive_panels = Vbox( |
75 |
| - Hbox( |
76 |
| - LineLambdaPanel([ |
77 |
| - lambda: ' PORT: {:4} '.format( |
78 |
| - shm.motor_desires.port.get()), |
79 |
| - lambda: ' STAR: {:4} '.format( |
80 |
| - shm.motor_desires.starboard.get()), |
81 |
| - lambda: ' FORE:{:3}:{:3} '.format( |
82 |
| - shm.motor_desires.fore_port.get(), |
83 |
| - shm.motor_desires.fore_starboard.get()), |
84 |
| - lambda: ' AFT:{:3}:{:3} '.format( |
85 |
| - shm.motor_desires.aft_port.get(), |
86 |
| - shm.motor_desires.aft_starboard.get()), |
87 |
| - lambda: ' SFOR: {:4} '.format( |
88 |
| - shm.motor_desires.sway_fore.get()), |
89 |
| - lambda: ' SAFT: {:4} '.format( |
90 |
| - shm.motor_desires.sway_aft.get()), |
91 |
| - ], width=16, padding=False), |
92 |
| - |
93 |
| - ShmPanel(shm.navigation_desires, width=20, title=None, |
94 |
| - padding=False, |
95 |
| - select_vars=['heading', 'depth', 'pitch', |
96 |
| - 'roll', 'speed', 'sway_speed'], |
97 |
| - var_names=[' DES HEAD', ' DES DPTH', ' DES PTCH', |
98 |
| - ' DES ROLL', ' DES VELX', ' DES VELY']), |
99 |
| - |
100 |
| - ShmPanel(shm.kalman, width=16, title=None, padding=False, |
101 |
| - select_vars=['heading', 'depth', 'pitch', |
102 |
| - 'roll', 'velx', 'vely'], |
103 |
| - var_names=[' HEAD', ' DPTH', ' PTCH', |
104 |
| - ' ROLL', ' VELX', ' VELY']), |
105 |
| - |
106 |
| - LineLambdaPanel([ |
107 |
| - lambda: (' DVL ALTD:', dvl_fmt(shm.dvl.savg_altitude.get())), |
108 |
| - lambda: (' DVL TEMP:', dvl_fmt(shm.dvl.temperature.get())), |
109 |
| - lambda: (StyledString.highlight_if( |
110 |
| - ' DVL BEAM 1', shm.dvl.low_amp_1.get() |
111 |
| - or shm.dvl.low_correlation_1.get()), ' FWRD:'), |
112 |
| - lambda: (StyledString.highlight_if( |
113 |
| - ' DVL BEAM 2', shm.dvl.low_amp_2.get() |
114 |
| - or shm.dvl.low_correlation_2.get()), |
115 |
| - dvl_fmt(shm.kalman.forward.get())), |
116 |
| - lambda: (StyledString.highlight_if( |
117 |
| - ' DVL BEAM 3', shm.dvl.low_amp_3.get() |
118 |
| - or shm.dvl.low_correlation_3.get()), ' SWAY:'), |
119 |
| - lambda: (StyledString.highlight_if( |
120 |
| - ' DVL BEAM 4', shm.dvl.low_amp_4.get() |
121 |
| - or shm.dvl.low_correlation_4.get()), |
122 |
| - dvl_fmt(shm.kalman.sway.get())), |
123 |
| - ], width=20, columns=True, padding=False), |
124 |
| - |
125 |
| - LineLambdaPanel([ |
126 |
| - lambda: StyledString.highlight_if( |
127 |
| - ' HK ',shm.switches.hard_kill.get()), |
128 |
| - lambda: StyledString.highlight_if( |
129 |
| - ' SK ', shm.switches.soft_kill.get()), |
130 |
| - lambda: StyledString.highlight_if( |
131 |
| - ' DV ', shm.dvl.vel_x_invalid.get() |
132 |
| - or shm.dvl.vel_y_invalid.get() |
133 |
| - or shm.dvl.vel_z_invalid.get()), |
134 |
| - lambda: StyledString.highlight_if( |
135 |
| - ' PC ', shm.navigation_settings.position_controls.get()), |
136 |
| - lambda: StyledString.highlight_if( |
137 |
| - ' OT ', shm.navigation_settings.optimize.get()), |
138 |
| - lambda: StyledString.highlight_if( |
139 |
| - ' EN ', shm.settings_control.enabled.get()), |
140 |
| - ], width=6, padding=False), |
141 |
| - height=8, min_height=8 |
142 |
| - ), |
143 |
| - |
144 |
| - # PID loop panels |
145 |
| - Hbox( |
146 |
| - pid_panel('heading', 'heading_rate', 'heading'), |
147 |
| - pid_panel('pitch', 'pitch_rate', 'pitch'), |
148 |
| - pid_panel('roll', 'roll_rate', 'roll'), |
149 |
| - height=8, |
150 |
| - ), |
151 |
| - Hbox( |
152 |
| - pid_panel('velx', 'accelx', 'speed'), |
153 |
| - pid_panel('vely', 'accely', 'sway_speed'), |
154 |
| - pid_panel('depth', 'depth_rate', 'depth'), |
155 |
| - height=8, |
156 |
| - ), |
157 |
| - |
158 |
| - Hbox( |
159 |
| - LineLambdaPanel([ |
160 |
| - lambda: get_battery_status()[0], |
161 |
| - lambda: get_battery_status()[1], |
162 |
| - ], width=26), |
163 |
| - LineLambdaPanel([ |
164 |
| - lambda: msg, |
165 |
| - lambda: buf, |
166 |
| - ], width=26), |
167 |
| - Panel(width=26), |
168 |
| - height=4, |
| 77 | + drive_panels = Hbox( |
| 78 | + Vbox( |
| 79 | + Hbox( |
| 80 | + LineLambdaPanel([ |
| 81 | + lambda: ' PORT: {:4} '.format( |
| 82 | + shm.motor_desires.port.get()), |
| 83 | + lambda: ' STAR: {:4} '.format( |
| 84 | + shm.motor_desires.starboard.get()), |
| 85 | + lambda: ' FORE:{:3}:{:3} '.format( |
| 86 | + shm.motor_desires.fore_port.get(), |
| 87 | + shm.motor_desires.fore_starboard.get()), |
| 88 | + lambda: ' AFT:{:3}:{:3} '.format( |
| 89 | + shm.motor_desires.aft_port.get(), |
| 90 | + shm.motor_desires.aft_starboard.get()), |
| 91 | + lambda: ' SFOR: {:4} '.format( |
| 92 | + shm.motor_desires.sway_fore.get()), |
| 93 | + lambda: ' SAFT: {:4} '.format( |
| 94 | + shm.motor_desires.sway_aft.get()), |
| 95 | + ], width=16, padding=False), |
| 96 | + |
| 97 | + ShmPanel(shm.navigation_desires, width=20, title=None, |
| 98 | + padding=False, |
| 99 | + select_vars=['heading', 'depth', 'pitch', |
| 100 | + 'roll', 'speed', 'sway_speed'], |
| 101 | + var_names=[' DES HEAD', ' DES DPTH', ' DES PTCH', |
| 102 | + ' DES ROLL', ' DES VELX', ' DES VELY']), |
| 103 | + |
| 104 | + ShmPanel(shm.kalman, width=16, title=None, padding=False, |
| 105 | + select_vars=['heading', 'depth', 'pitch', |
| 106 | + 'roll', 'velx', 'vely'], |
| 107 | + var_names=[' HEAD', ' DPTH', ' PTCH', |
| 108 | + ' ROLL', ' VELX', ' VELY']), |
| 109 | + |
| 110 | + LineLambdaPanel([ |
| 111 | + lambda: (' DVL ALTD:', dvl_fmt(shm.dvl.savg_altitude.get())), |
| 112 | + lambda: (' DVL TEMP:', dvl_fmt(shm.dvl.temperature.get())), |
| 113 | + lambda: (StyledString.highlight_if( |
| 114 | + ' DVL BEAM 1', shm.dvl.low_amp_1.get() |
| 115 | + or shm.dvl.low_correlation_1.get()), ' FWRD:'), |
| 116 | + lambda: (StyledString.highlight_if( |
| 117 | + ' DVL BEAM 2', shm.dvl.low_amp_2.get() |
| 118 | + or shm.dvl.low_correlation_2.get()), |
| 119 | + dvl_fmt(shm.kalman.forward.get())), |
| 120 | + lambda: (StyledString.highlight_if( |
| 121 | + ' DVL BEAM 3', shm.dvl.low_amp_3.get() |
| 122 | + or shm.dvl.low_correlation_3.get()), ' SWAY:'), |
| 123 | + lambda: (StyledString.highlight_if( |
| 124 | + ' DVL BEAM 4', shm.dvl.low_amp_4.get() |
| 125 | + or shm.dvl.low_correlation_4.get()), |
| 126 | + dvl_fmt(shm.kalman.sway.get())), |
| 127 | + ], width=20, columns=True, padding=False), |
| 128 | + |
| 129 | + LineLambdaPanel([ |
| 130 | + lambda: StyledString.highlight_if( |
| 131 | + ' HK ',shm.switches.hard_kill.get()), |
| 132 | + lambda: StyledString.highlight_if( |
| 133 | + ' SK ', shm.switches.soft_kill.get()), |
| 134 | + lambda: StyledString.highlight_if( |
| 135 | + ' DV ', shm.dvl.vel_x_invalid.get() |
| 136 | + or shm.dvl.vel_y_invalid.get() |
| 137 | + or shm.dvl.vel_z_invalid.get()), |
| 138 | + lambda: StyledString.highlight_if( |
| 139 | + ' PC ', shm.navigation_settings.position_controls.get()), |
| 140 | + lambda: StyledString.highlight_if( |
| 141 | + ' OT ', shm.navigation_settings.optimize.get()), |
| 142 | + lambda: StyledString.highlight_if( |
| 143 | + ' EN ', shm.settings_control.enabled.get()), |
| 144 | + ], width=6, padding=False), |
| 145 | + height=8, min_height=8 |
| 146 | + ), |
| 147 | + |
| 148 | + # PID loop panels |
| 149 | + Hbox( |
| 150 | + pid_panel('heading', 'heading_rate', 'heading'), |
| 151 | + pid_panel('pitch', 'pitch_rate', 'pitch'), |
| 152 | + pid_panel('roll', 'roll_rate', 'roll'), |
| 153 | + height=8, |
| 154 | + ), |
| 155 | + Hbox( |
| 156 | + pid_panel('velx', 'accelx', 'speed'), |
| 157 | + pid_panel('vely', 'accely', 'sway_speed'), |
| 158 | + pid_panel('depth', 'depth_rate', 'depth'), |
| 159 | + height=8, |
| 160 | + ), |
| 161 | + Hbox( |
| 162 | + LineLambdaPanel([ |
| 163 | + lambda: get_battery_status()[0], |
| 164 | + lambda: get_battery_status()[1], |
| 165 | + ], width=26), |
| 166 | + LineLambdaPanel([ |
| 167 | + lambda: msg, |
| 168 | + lambda: buf, |
| 169 | + ], width=26), |
| 170 | + Panel(width=26), |
| 171 | + height=4 |
| 172 | + ), |
| 173 | + |
| 174 | + width=26 * 3, |
169 | 175 | ),
|
| 176 | + Vbox( |
| 177 | + activity.panels.ConnectionsPanel("Active", height=8, max_recency=30), |
| 178 | + activity.panels.ConnectionsPanel("Idle", height=16, min_recency=30), |
| 179 | + activity.panels.MissionPanel() |
| 180 | + ) |
170 | 181 | )
|
171 | 182 |
|
172 | 183 | def toggle_shm(var, set_msg=None):
|
@@ -412,8 +423,25 @@ def commit_pos(name):
|
412 | 423 | lambda: commit_pos('north'), allowable_chars)
|
413 | 424 |
|
414 | 425 | add_positional_controls()
|
415 |
| - |
| 426 | + |
| 427 | + # Add activity logging to each callback, so every keypress |
| 428 | + # updates the user's entry in the activity list. |
| 429 | + for key in drive_callbacks: |
| 430 | + activity.logging.add_logging(drive_callbacks, key) |
| 431 | + for mode in drive_modal_callbacks: |
| 432 | + for key in drive_modal_callbacks[mode]: |
| 433 | + activity.logging.add_logging(drive_modal_callbacks[mode], key) |
| 434 | + |
416 | 435 | return drive_panels, drive_callbacks, drive_modal_callbacks
|
417 | 436 |
|
418 | 437 | if __name__ == '__main__':
|
| 438 | + # When Control Helm is exited through any of these |
| 439 | + # means, remove the user from the activity list. |
| 440 | + signal.signal(signal.SIGTERM, activity.logging.close_helm) |
| 441 | + signal.signal(signal.SIGINT, activity.logging.close_helm) |
| 442 | + signal.signal(signal.SIGHUP, activity.logging.close_helm) |
| 443 | + |
| 444 | + # Add the user to the activity list. |
| 445 | + activity.logging.log(new_helm=True) |
| 446 | + |
419 | 447 | start_helm(*build_control_helm(expert='-e' in sys.argv))
|
0 commit comments