symetrie-hexapod 0.17.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- egse/hexapod/__init__.py +33 -0
- egse/hexapod/symetrie/__init__.py +182 -0
- egse/hexapod/symetrie/alpha.py +857 -0
- egse/hexapod/symetrie/dynalpha.py +1438 -0
- egse/hexapod/symetrie/hexapod.py +550 -0
- egse/hexapod/symetrie/hexapod_ui.py +1484 -0
- egse/hexapod/symetrie/joran.py +289 -0
- egse/hexapod/symetrie/joran.yaml +62 -0
- egse/hexapod/symetrie/joran_cs.py +179 -0
- egse/hexapod/symetrie/joran_protocol.py +117 -0
- egse/hexapod/symetrie/joran_ui.py +433 -0
- egse/hexapod/symetrie/pmac.py +1001 -0
- egse/hexapod/symetrie/pmac_regex.py +86 -0
- egse/hexapod/symetrie/puna.py +649 -0
- egse/hexapod/symetrie/puna.yaml +193 -0
- egse/hexapod/symetrie/puna_cs.py +241 -0
- egse/hexapod/symetrie/puna_protocol.py +126 -0
- egse/hexapod/symetrie/puna_ui.py +410 -0
- egse/hexapod/symetrie/punaplus.py +115 -0
- egse/hexapod/symetrie/zonda.py +846 -0
- egse/hexapod/symetrie/zonda.yaml +337 -0
- egse/hexapod/symetrie/zonda_cs.py +239 -0
- egse/hexapod/symetrie/zonda_devif.py +416 -0
- egse/hexapod/symetrie/zonda_protocol.py +118 -0
- egse/hexapod/symetrie/zonda_ui.py +434 -0
- symetrie_hexapod/__init__.py +0 -0
- symetrie_hexapod/cgse_explore.py +19 -0
- symetrie_hexapod/cgse_services.py +162 -0
- symetrie_hexapod/settings.yaml +15 -0
- symetrie_hexapod-0.17.3.dist-info/METADATA +21 -0
- symetrie_hexapod-0.17.3.dist-info/RECORD +33 -0
- symetrie_hexapod-0.17.3.dist-info/WHEEL +4 -0
- symetrie_hexapod-0.17.3.dist-info/entry_points.txt +23 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
BaseClass:
|
|
2
|
+
egse.hexapod.symmetrie.PunaInterface
|
|
3
|
+
|
|
4
|
+
ProxyClass:
|
|
5
|
+
egse.hexapod.symetrie.PunaProxy
|
|
6
|
+
|
|
7
|
+
ControlServerClass:
|
|
8
|
+
egse.hexapod.symetrie.PunaControlServer
|
|
9
|
+
|
|
10
|
+
ControlServer:
|
|
11
|
+
egse.hexapod.symetrie.puna_cs
|
|
12
|
+
|
|
13
|
+
UserInterface:
|
|
14
|
+
egse.hexapod.symetrie.puna_ui
|
|
15
|
+
|
|
16
|
+
Commands:
|
|
17
|
+
|
|
18
|
+
# Each of these groups is parsed and used on both the server and the client side.
|
|
19
|
+
#
|
|
20
|
+
# The group name (e.g. is_simulator) will be monkey patched in the Proxy class for the device
|
|
21
|
+
# or service.
|
|
22
|
+
#
|
|
23
|
+
# The other field are:
|
|
24
|
+
# description: Used by the doc_string method to generate a help string
|
|
25
|
+
# cmd: Command string that will eventually be send to the hardware controller for
|
|
26
|
+
# the device. This cmd string is also used at the client side to parse and
|
|
27
|
+
# validate the arguments.
|
|
28
|
+
# device_method: The name of the method to be called on the device class.
|
|
29
|
+
# These should all be defined by the interface class for the device, i.e.
|
|
30
|
+
# PunaInterface in this case.
|
|
31
|
+
# When the device_method is the same as the group name, it can be omitted.
|
|
32
|
+
# response: The name of the method to be called from the device protocol.
|
|
33
|
+
# This method should exist in the subclass of the CommandProtocol base class,
|
|
34
|
+
# i.e. in this case it will be the PunaProtocol class.
|
|
35
|
+
# The default (when no response is given) is 'handle_device_method'.
|
|
36
|
+
|
|
37
|
+
# Definition of the DeviceInterface
|
|
38
|
+
|
|
39
|
+
is_simulator:
|
|
40
|
+
description: Ask if the connected class is a simulator instead of the real device Controller class.
|
|
41
|
+
returns: bool | True if the far end is a simulator instead of the real hardware
|
|
42
|
+
|
|
43
|
+
is_connected:
|
|
44
|
+
description: Check if the Hexapod hardware controller is connected.
|
|
45
|
+
|
|
46
|
+
connect:
|
|
47
|
+
description: Connect the Hexapod hardware controller
|
|
48
|
+
|
|
49
|
+
reconnect:
|
|
50
|
+
description: Reconnect the Hexapod hardware controller.
|
|
51
|
+
|
|
52
|
+
This command will force a disconnect and then try to re-connect to the controller.
|
|
53
|
+
|
|
54
|
+
disconnect:
|
|
55
|
+
description: Disconnect from the hexapod controller.
|
|
56
|
+
|
|
57
|
+
This command will be send to the Hexapod Control Server which will then
|
|
58
|
+
disconnect from the hardware controller.
|
|
59
|
+
|
|
60
|
+
This command does not affect the ZeroMQ connection of the Proxy to the
|
|
61
|
+
control server. Use the service command `disconnect_cs()` to disconnect
|
|
62
|
+
from the control server.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# Definition of the device commands
|
|
66
|
+
|
|
67
|
+
is_in_position:
|
|
68
|
+
description: Returns True when the actuators are in position.
|
|
69
|
+
|
|
70
|
+
info:
|
|
71
|
+
description: Retrieve basic information about the Hexapod and the Controller.
|
|
72
|
+
|
|
73
|
+
reset:
|
|
74
|
+
description: Completely resets the Hexapod controller with the standard boot cycle.
|
|
75
|
+
cmd: "$$$"
|
|
76
|
+
|
|
77
|
+
stop:
|
|
78
|
+
description: Stop the current motion.
|
|
79
|
+
cmd: "&2 Q20=2"
|
|
80
|
+
|
|
81
|
+
homing:
|
|
82
|
+
description: Start the homing cycle for the Hexapod.
|
|
83
|
+
cmd: "&2 Q20=1"
|
|
84
|
+
|
|
85
|
+
is_homing_done:
|
|
86
|
+
description: Check if Homing is done.
|
|
87
|
+
|
|
88
|
+
set_virtual_homing:
|
|
89
|
+
description: Starts the virtual homing cycle on the hexapod.
|
|
90
|
+
|
|
91
|
+
This command uses the position given in parameters to initialize the hexapod position.
|
|
92
|
+
No movements of the hexapod are performed during this homing cycle. Please note that the
|
|
93
|
+
position specified in parameters must match the absolute position of the Object coordinate
|
|
94
|
+
system in the User coordinate system (see description in the manual chapter 2 on coordinates
|
|
95
|
+
systems). This position correspond to the answer of the command `get_user_positions()`.
|
|
96
|
+
During this operation, it is important to have the same hexapod position as those defined
|
|
97
|
+
during the record of the position. Otherwise, the system initialization will be incorrect.
|
|
98
|
+
|
|
99
|
+
cmd: "&2 Q71={tx} Q72={ty} Q73={tz} Q74={rx} Q75={ry} Q76={rz} Q20=42"
|
|
100
|
+
|
|
101
|
+
clear_error:
|
|
102
|
+
description: Clear all errors in the controller software.
|
|
103
|
+
cmd: "&2 Q20=15"
|
|
104
|
+
|
|
105
|
+
activate_control_loop:
|
|
106
|
+
description: Activates the control loop on motors.
|
|
107
|
+
cmd: "&2 Q20=3"
|
|
108
|
+
|
|
109
|
+
deactivate_control_loop:
|
|
110
|
+
description: Disables the control loop on the servo motors.
|
|
111
|
+
cmd: "&2 Q20=4"
|
|
112
|
+
|
|
113
|
+
configure_coordinates_systems:
|
|
114
|
+
description: Change the definition of the User Coordinate System and the Object Coordinate System.
|
|
115
|
+
cmd: "&2 Q80={tx_u} Q81={ty_u} Q82={tz_u} Q83={rx_u} Q84={ry_u} Q85={rz_u} Q86={tx_o} Q87={ty_o} Q88={tz_o} Q89={rx_o} Q90={ry_o} Q91={rz_o} Q20=21"
|
|
116
|
+
|
|
117
|
+
get_coordinates_systems:
|
|
118
|
+
description: Retrieve the definition of the User Coordinate System and the Object Coordinate System.
|
|
119
|
+
cmd: "&2 Q20=31"
|
|
120
|
+
query: "&2 Q20 Q80,12,1"
|
|
121
|
+
|
|
122
|
+
get_general_state:
|
|
123
|
+
description: Retrieve general state information of the hexapod.
|
|
124
|
+
|
|
125
|
+
get_user_positions:
|
|
126
|
+
description: Retrieve the position of the Object Coordinate System in the User Coordinate System.
|
|
127
|
+
cmd: "&2 Q53,6,1"
|
|
128
|
+
|
|
129
|
+
get_machine_positions:
|
|
130
|
+
description: Retrieve the position of the Platform Coordinate System in the Machine Coordinate System.
|
|
131
|
+
cmd: "&2 Q47,6,1"
|
|
132
|
+
|
|
133
|
+
get_actuator_length:
|
|
134
|
+
description: Retrieve the current length of the hexapod actuators.
|
|
135
|
+
cmd: "&2 Q41,6,1"
|
|
136
|
+
|
|
137
|
+
get_actuator_state:
|
|
138
|
+
description: Returns the general state of the actuators.
|
|
139
|
+
|
|
140
|
+
move_absolute:
|
|
141
|
+
description: Move/define the Object Coordinate System position and orientation expressed in the invariant user coordinate system.
|
|
142
|
+
|
|
143
|
+
The rotation centre coincides with the Object Coordinates System origin and
|
|
144
|
+
the movements are controlled with translation components at first (Tx, Ty, tZ)
|
|
145
|
+
and then the rotation components (Rx, Ry, Rz).
|
|
146
|
+
cmd: "&2 Q70=0 Q71={tx:.6f} Q72={ty:.6f} Q73={tz:.6f} Q74={rx:.6f} Q75={ry:.6f} Q76={rz:.6f} Q20=11"
|
|
147
|
+
|
|
148
|
+
move_relative_object:
|
|
149
|
+
description: Move the object relative to its current object position and orientation.
|
|
150
|
+
cmd: "&2 Q70=1 Q71={tx:.6f} Q72={ty:.6f} Q73={tz:.6f} Q74={rx:.6f} Q75={ry:.6f} Q76={rz:.6f} Q20=11"
|
|
151
|
+
|
|
152
|
+
move_relative_user:
|
|
153
|
+
description: Move the object relative to its current object position and orientation.
|
|
154
|
+
cmd: "&2 Q70=2 Q71={tx:.6f} Q72={ty:.6f} Q73={tz:.6f} Q74={rx:.6f} Q75={ry:.6f} Q76={rz:.6f} Q20=11"
|
|
155
|
+
|
|
156
|
+
check_absolute_movement:
|
|
157
|
+
description: Check if the requested object movement is valid.
|
|
158
|
+
cmd: "&2 Q70=0 Q71={tx} Q72={ty} Q73={tz} Q74={rx} Q75={ry} Q76={rz} Q20=10"
|
|
159
|
+
|
|
160
|
+
check_relative_object_movement:
|
|
161
|
+
description: Check if the requested object movement is valid.
|
|
162
|
+
cmd: "&2 Q70=1 Q71={tx} Q72={ty} Q73={tz} Q74={rx} Q75={ry} Q76={rz} Q20=10"
|
|
163
|
+
|
|
164
|
+
check_relative_user_movement:
|
|
165
|
+
description: Check if the requested object movement is valid.
|
|
166
|
+
cmd: "&2 Q70=2i Q71={tx} Q72={ty} Q73={tz} Q74={rx} Q75={ry} Q76={rz} Q20=10"
|
|
167
|
+
|
|
168
|
+
goto_zero_position:
|
|
169
|
+
cmd: "&2 Q80=1 Q20=13"
|
|
170
|
+
|
|
171
|
+
goto_retracted_position:
|
|
172
|
+
cmd: "&2 Q80=2 Q20=13"
|
|
173
|
+
|
|
174
|
+
goto_specific_position:
|
|
175
|
+
cmd: "&2 Q80={pos} Q20=13"
|
|
176
|
+
|
|
177
|
+
perform_maintenance:
|
|
178
|
+
description: Ask the controller to perform the maintenance cycle which consists to
|
|
179
|
+
travel the full range on one axis. Full range corresponds to the Hexapod
|
|
180
|
+
machine limts (defined by the manufacturer), and the movement is
|
|
181
|
+
performed in Machine coordinate system.
|
|
182
|
+
cmd: "{axis}"
|
|
183
|
+
|
|
184
|
+
get_speed:
|
|
185
|
+
description: Returns the movement speed. Translation speed is expressed in mm per
|
|
186
|
+
second, the angular speed is expressed in degrees per second.
|
|
187
|
+
|
|
188
|
+
set_speed:
|
|
189
|
+
description: Sets the speed of movements.
|
|
190
|
+
cmd: "&2 Q80={vt} Q81={vr} Q20=25"
|
|
191
|
+
|
|
192
|
+
get_debug_info:
|
|
193
|
+
description: Returns debugging status information.
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The Control Server that connects to the Hexapod PUNA Hardware Controller.
|
|
3
|
+
|
|
4
|
+
Start the control server from the terminal as follows:
|
|
5
|
+
|
|
6
|
+
$ puna_cs start-bg
|
|
7
|
+
|
|
8
|
+
or when you don't have the device available, start the control server in simulator mode. That
|
|
9
|
+
will make the control server connect to a device software simulator:
|
|
10
|
+
|
|
11
|
+
$ puna_cs start --sim
|
|
12
|
+
|
|
13
|
+
Please note that software simulators are intended for simple test purposes and will not simulate
|
|
14
|
+
all device behavior correctly, e.g. timing, error conditions, etc.
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import multiprocessing
|
|
19
|
+
import sys
|
|
20
|
+
from typing import Annotated
|
|
21
|
+
|
|
22
|
+
import rich
|
|
23
|
+
import typer
|
|
24
|
+
import zmq
|
|
25
|
+
from prometheus_client import start_http_server
|
|
26
|
+
|
|
27
|
+
from egse.control import ControlServer
|
|
28
|
+
from egse.control import is_control_server_active
|
|
29
|
+
from egse.hexapod.symetrie import ProxyFactory
|
|
30
|
+
from egse.hexapod.symetrie import get_hexapod_controller_pars
|
|
31
|
+
from egse.hexapod.symetrie import logger
|
|
32
|
+
from egse.hexapod.symetrie.puna_protocol import PunaProtocol
|
|
33
|
+
from egse.registry.client import RegistryClient
|
|
34
|
+
from egse.services import ServiceProxy
|
|
35
|
+
from egse.settings import Settings
|
|
36
|
+
from egse.storage import store_housekeeping_information
|
|
37
|
+
from egse.zmq_ser import connect_address
|
|
38
|
+
|
|
39
|
+
CTRL_SETTINGS = Settings.load("Hexapod Control Server")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class PunaControlServer(ControlServer):
|
|
43
|
+
"""
|
|
44
|
+
PunaControlServer - Command and monitor the Hexapod PUNA hardware.
|
|
45
|
+
|
|
46
|
+
This class works as a command and monitoring server to control the Symétrie Hexapod PUNA.
|
|
47
|
+
This control server shall be used as the single point access for controlling the hardware
|
|
48
|
+
device. Monitoring access should be done preferably through this control server also,
|
|
49
|
+
but can be done with a direct connection through the PunaController if needed.
|
|
50
|
+
|
|
51
|
+
The sever binds to the following ZeroMQ sockets:
|
|
52
|
+
|
|
53
|
+
* a REQ-REP socket that can be used as a command server. Any client can connect and
|
|
54
|
+
send a command to the Hexapod.
|
|
55
|
+
|
|
56
|
+
* a PUB-SUP socket that serves as a monitoring server. It will send out Hexapod status
|
|
57
|
+
information to all the connected clients every five seconds.
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def __init__(self, device_id: str, simulator: bool = False):
|
|
62
|
+
super().__init__()
|
|
63
|
+
|
|
64
|
+
multiprocessing.current_process().name = "puna_cs"
|
|
65
|
+
|
|
66
|
+
self.logger = logger
|
|
67
|
+
|
|
68
|
+
self.device_id = device_id
|
|
69
|
+
self.device_protocol = PunaProtocol(self, device_id=device_id, simulator=simulator)
|
|
70
|
+
|
|
71
|
+
self.device_protocol.bind(self.dev_ctrl_cmd_sock)
|
|
72
|
+
|
|
73
|
+
self.poller.register(self.dev_ctrl_cmd_sock, zmq.POLLIN)
|
|
74
|
+
|
|
75
|
+
self.register_service(service_type=f"{device_id}")
|
|
76
|
+
|
|
77
|
+
def get_communication_protocol(self):
|
|
78
|
+
return CTRL_SETTINGS.PROTOCOL
|
|
79
|
+
|
|
80
|
+
def get_commanding_port(self):
|
|
81
|
+
return CTRL_SETTINGS.COMMANDING_PORT
|
|
82
|
+
|
|
83
|
+
def get_service_port(self):
|
|
84
|
+
return CTRL_SETTINGS.SERVICE_PORT
|
|
85
|
+
|
|
86
|
+
def get_monitoring_port(self):
|
|
87
|
+
return CTRL_SETTINGS.MONITORING_PORT
|
|
88
|
+
|
|
89
|
+
def get_storage_mnemonic(self):
|
|
90
|
+
try:
|
|
91
|
+
return CTRL_SETTINGS.STORAGE_MNEMONIC
|
|
92
|
+
except AttributeError:
|
|
93
|
+
return "PUNA"
|
|
94
|
+
|
|
95
|
+
def is_storage_manager_active(self):
|
|
96
|
+
from egse.storage import is_storage_manager_active
|
|
97
|
+
|
|
98
|
+
return is_storage_manager_active()
|
|
99
|
+
|
|
100
|
+
def store_housekeeping_information(self, data):
|
|
101
|
+
"""Send housekeeping information to the Storage manager."""
|
|
102
|
+
|
|
103
|
+
origin = self.get_storage_mnemonic()
|
|
104
|
+
store_housekeeping_information(origin, data)
|
|
105
|
+
|
|
106
|
+
def register_to_storage_manager(self):
|
|
107
|
+
from egse.storage import register_to_storage_manager
|
|
108
|
+
from egse.storage.persistence import TYPES
|
|
109
|
+
|
|
110
|
+
register_to_storage_manager(
|
|
111
|
+
origin=self.get_storage_mnemonic(),
|
|
112
|
+
persistence_class=TYPES["CSV"],
|
|
113
|
+
prep={
|
|
114
|
+
"column_names": list(self.device_protocol.get_housekeeping().keys()),
|
|
115
|
+
"mode": "a",
|
|
116
|
+
},
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
def unregister_from_storage_manager(self):
|
|
120
|
+
from egse.storage import unregister_from_storage_manager
|
|
121
|
+
|
|
122
|
+
unregister_from_storage_manager(origin=self.get_storage_mnemonic())
|
|
123
|
+
|
|
124
|
+
def before_serve(self):
|
|
125
|
+
start_http_server(CTRL_SETTINGS.METRICS_PORT)
|
|
126
|
+
|
|
127
|
+
def after_serve(self) -> None:
|
|
128
|
+
self.deregister_service()
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
app = typer.Typer()
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
@app.command()
|
|
135
|
+
def start(
|
|
136
|
+
device_id: Annotated[str, typer.Argument(help="the device identifier, identifies the hardware controller")],
|
|
137
|
+
simulator: Annotated[
|
|
138
|
+
bool, typer.Option("--simulator", "--sim", help="start the hexapod PUNA Control Server in simulator mode")
|
|
139
|
+
] = False,
|
|
140
|
+
):
|
|
141
|
+
"""
|
|
142
|
+
Start the Hexapod PUNA Control Server.
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
try:
|
|
146
|
+
controller = PunaControlServer(device_id, simulator)
|
|
147
|
+
controller.serve()
|
|
148
|
+
|
|
149
|
+
except KeyboardInterrupt:
|
|
150
|
+
print("Shutdown requested...exiting")
|
|
151
|
+
|
|
152
|
+
except SystemExit as exc:
|
|
153
|
+
exit_code = exc.code if hasattr(exc, "code") else 0
|
|
154
|
+
print(f"System Exit with code {exc.code}")
|
|
155
|
+
sys.exit(exit_code)
|
|
156
|
+
|
|
157
|
+
except Exception:
|
|
158
|
+
logger.exception("Cannot start the Hexapod Puna Control Server")
|
|
159
|
+
|
|
160
|
+
# The above line does exactly the same as the traceback, but on the logger
|
|
161
|
+
# import traceback
|
|
162
|
+
# traceback.print_exc(file=sys.stdout)
|
|
163
|
+
|
|
164
|
+
return 0
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@app.command()
|
|
168
|
+
def stop(device_id: str):
|
|
169
|
+
"""Send a 'quit_server' command to the Hexapod Puna Control Server."""
|
|
170
|
+
|
|
171
|
+
with RegistryClient() as reg:
|
|
172
|
+
service = reg.discover_service(device_id)
|
|
173
|
+
rich.print("service = ", service)
|
|
174
|
+
|
|
175
|
+
if service:
|
|
176
|
+
proxy = ServiceProxy(protocol="tcp", hostname=service["host"], port=service["metadata"]["service_port"])
|
|
177
|
+
proxy.quit_server()
|
|
178
|
+
else:
|
|
179
|
+
*_, device_type, controller_type = get_hexapod_controller_pars(device_id)
|
|
180
|
+
|
|
181
|
+
factory = ProxyFactory()
|
|
182
|
+
try:
|
|
183
|
+
with factory.create(device_type, device_id=device_id) as proxy:
|
|
184
|
+
sp = proxy.get_service_proxy()
|
|
185
|
+
sp.quit_server()
|
|
186
|
+
except ConnectionError:
|
|
187
|
+
rich.print("[red]Couldn't connect to 'puna_cs', process probably not running. ")
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@app.command()
|
|
191
|
+
def status(device_id: str):
|
|
192
|
+
"""Request status information from the Control Server."""
|
|
193
|
+
|
|
194
|
+
*_, device_type, controller_type = get_hexapod_controller_pars(device_id)
|
|
195
|
+
|
|
196
|
+
with RegistryClient() as reg:
|
|
197
|
+
service = reg.discover_service(device_id)
|
|
198
|
+
# rich.print("service = ", service)
|
|
199
|
+
|
|
200
|
+
if service:
|
|
201
|
+
protocol = service.get("protocol", "tcp")
|
|
202
|
+
hostname = service["host"]
|
|
203
|
+
port = service["port"]
|
|
204
|
+
service_port = service["metadata"]["service_port"]
|
|
205
|
+
monitoring_port = service["metadata"]["monitoring_port"]
|
|
206
|
+
endpoint = connect_address(protocol, hostname, port)
|
|
207
|
+
# rich.print(f"{endpoint = }")
|
|
208
|
+
else:
|
|
209
|
+
rich.print(
|
|
210
|
+
f"[red]The PUNA CS '{device_id}' isn't registered as a service. I cannot contact the control "
|
|
211
|
+
f"server without the required info from the service registry.[/]"
|
|
212
|
+
)
|
|
213
|
+
rich.print("PUNA Hexapod: [red]not active")
|
|
214
|
+
return
|
|
215
|
+
|
|
216
|
+
factory = ProxyFactory()
|
|
217
|
+
|
|
218
|
+
if is_control_server_active(endpoint):
|
|
219
|
+
rich.print("PUNA Hexapod: [green]active")
|
|
220
|
+
with factory.create(device_type, device_id=device_id, protocol=protocol, hostname=hostname, port=port) as puna:
|
|
221
|
+
sim = puna.is_simulator()
|
|
222
|
+
connected = puna.is_connected()
|
|
223
|
+
ip = puna.get_ip_address()
|
|
224
|
+
rich.print(f"type: {controller_type}")
|
|
225
|
+
rich.print(f"mode: {'simulator' if sim else 'device'}{'' if connected else ' not'} connected")
|
|
226
|
+
rich.print(f"hostname: {ip}")
|
|
227
|
+
rich.print(f"commanding port: {port}")
|
|
228
|
+
rich.print(f"service port: {service_port}")
|
|
229
|
+
rich.print(f"monitoring port: {monitoring_port}")
|
|
230
|
+
else:
|
|
231
|
+
rich.print("PUNA Hexapod: [red]not active")
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
if __name__ == "__main__":
|
|
235
|
+
import logging
|
|
236
|
+
|
|
237
|
+
from egse.logger import set_all_logger_levels
|
|
238
|
+
|
|
239
|
+
set_all_logger_levels(logging.DEBUG)
|
|
240
|
+
|
|
241
|
+
sys.exit(app())
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
from egse.command import ClientServerCommand
|
|
4
|
+
from egse.control import ControlServer
|
|
5
|
+
from egse.device import DeviceConnectionState
|
|
6
|
+
from egse.hexapod.symetrie import ControllerFactory
|
|
7
|
+
from egse.hexapod.symetrie import get_hexapod_controller_pars
|
|
8
|
+
from egse.hexapod.symetrie import logger
|
|
9
|
+
from egse.hexapod.symetrie.puna import PunaInterface
|
|
10
|
+
from egse.hexapod.symetrie.puna import PunaSimulator
|
|
11
|
+
|
|
12
|
+
# from egse.hk import read_conversion_dict, convert_hk_names
|
|
13
|
+
from egse.protocol import CommandProtocol
|
|
14
|
+
from egse.settings import Settings
|
|
15
|
+
from egse.system import format_datetime
|
|
16
|
+
from egse.zmq_ser import bind_address
|
|
17
|
+
|
|
18
|
+
_HERE = Path(__file__).parent
|
|
19
|
+
|
|
20
|
+
DEVICE_SETTINGS = Settings.load(filename="puna.yaml", location=_HERE)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class PunaCommand(ClientServerCommand):
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class PunaProtocol(CommandProtocol):
|
|
28
|
+
def __init__(self, control_server: ControlServer, device_id: str, simulator: bool = False):
|
|
29
|
+
super().__init__(control_server)
|
|
30
|
+
self.simulator = simulator
|
|
31
|
+
self.device_id = device_id
|
|
32
|
+
|
|
33
|
+
# FIXME: HK needs to be working
|
|
34
|
+
# self.hk_conversion_table = read_conversion_dict(self.control_server.get_storage_mnemonic(), use_site=True)
|
|
35
|
+
|
|
36
|
+
if self.simulator:
|
|
37
|
+
self.hexapod = PunaSimulator()
|
|
38
|
+
else:
|
|
39
|
+
*_, device_type, controller_type = get_hexapod_controller_pars(device_id)
|
|
40
|
+
|
|
41
|
+
factory = ControllerFactory()
|
|
42
|
+
self.hexapod = factory.create(device_type, device_id=device_id)
|
|
43
|
+
self.hexapod.add_observer(self)
|
|
44
|
+
|
|
45
|
+
try:
|
|
46
|
+
self.hexapod.connect()
|
|
47
|
+
except ConnectionError:
|
|
48
|
+
logger.warning("Couldn't establish a connection to the PUNA Hexapod, check the log messages.")
|
|
49
|
+
|
|
50
|
+
self.load_commands(DEVICE_SETTINGS.Commands, PunaCommand, PunaInterface)
|
|
51
|
+
self.build_device_method_lookup_table(self.hexapod)
|
|
52
|
+
|
|
53
|
+
# self.metrics = define_metrics("PUNA")
|
|
54
|
+
|
|
55
|
+
def get_bind_address(self):
|
|
56
|
+
return bind_address(
|
|
57
|
+
self.control_server.get_communication_protocol(),
|
|
58
|
+
self.control_server.get_commanding_port(),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def get_device(self):
|
|
62
|
+
return self.hexapod
|
|
63
|
+
|
|
64
|
+
def get_status(self):
|
|
65
|
+
status = super().get_status()
|
|
66
|
+
|
|
67
|
+
if self.state == DeviceConnectionState.DEVICE_NOT_CONNECTED and not self.simulator:
|
|
68
|
+
return status
|
|
69
|
+
|
|
70
|
+
mach_positions = self.hexapod.get_machine_positions()
|
|
71
|
+
user_positions = self.hexapod.get_user_positions()
|
|
72
|
+
actuator_length = self.hexapod.get_actuator_length()
|
|
73
|
+
|
|
74
|
+
status.update({"mach": mach_positions, "user": user_positions, "alength": actuator_length})
|
|
75
|
+
|
|
76
|
+
return status
|
|
77
|
+
|
|
78
|
+
def get_housekeeping(self) -> dict:
|
|
79
|
+
result = dict()
|
|
80
|
+
result["timestamp"] = format_datetime()
|
|
81
|
+
|
|
82
|
+
if self.state == DeviceConnectionState.DEVICE_NOT_CONNECTED and not self.simulator:
|
|
83
|
+
return result
|
|
84
|
+
|
|
85
|
+
mach_positions = self.hexapod.get_machine_positions()
|
|
86
|
+
user_positions = self.hexapod.get_user_positions()
|
|
87
|
+
actuator_length = self.hexapod.get_actuator_length()
|
|
88
|
+
|
|
89
|
+
# The result of the previous calls might be None when e.g. the connection
|
|
90
|
+
# to the device gets lost.
|
|
91
|
+
|
|
92
|
+
if mach_positions is None or user_positions is None or actuator_length is None:
|
|
93
|
+
if not self.hexapod.is_connected():
|
|
94
|
+
logger.warning("Hexapod PUNA disconnected.")
|
|
95
|
+
self.update_connection_state(DeviceConnectionState.DEVICE_NOT_CONNECTED)
|
|
96
|
+
return result
|
|
97
|
+
|
|
98
|
+
for idx, key in enumerate(["user_t_x", "user_t_y", "user_t_z", "user_r_x", "user_r_y", "user_r_z"]):
|
|
99
|
+
result[key] = user_positions[idx]
|
|
100
|
+
|
|
101
|
+
for idx, key in enumerate(["mach_t_x", "mach_t_y", "mach_t_z", "mach_r_x", "mach_r_y", "mach_r_z"]):
|
|
102
|
+
result[key] = mach_positions[idx]
|
|
103
|
+
|
|
104
|
+
for idx, key in enumerate(["alen_t_x", "alen_t_y", "alen_t_z", "alen_r_x", "alen_r_y", "alen_r_z"]):
|
|
105
|
+
result[key] = actuator_length[idx]
|
|
106
|
+
|
|
107
|
+
# TODO:
|
|
108
|
+
# the get_general_state() method should be refactored as to return a dict instead of a
|
|
109
|
+
# list. Also, we might want to rethink the usefulness of returning the tuple,
|
|
110
|
+
# it the first return value ever used?
|
|
111
|
+
|
|
112
|
+
_, _ = self.hexapod.get_general_state()
|
|
113
|
+
|
|
114
|
+
result["Homing done"] = self.hexapod.is_homing_done()
|
|
115
|
+
result["In position"] = self.hexapod.is_in_position()
|
|
116
|
+
|
|
117
|
+
return result # convert_hk_names(result, self.hk_conversion_table)
|
|
118
|
+
|
|
119
|
+
def is_device_connected(self):
|
|
120
|
+
# FIXME(rik): There must be another way to check if the socket is still alive...
|
|
121
|
+
# This will send way too many VERSION requests to the controllers.
|
|
122
|
+
# According to SO [https://stackoverflow.com/a/15175067] the best way
|
|
123
|
+
# to check for a connection drop / close is to handle the exceptions
|
|
124
|
+
# properly.... so, no polling for connections by sending it a simple
|
|
125
|
+
# command.
|
|
126
|
+
return self.hexapod.is_connected()
|