pymammotion 0.0.37__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.
Potentially problematic release.
This version of pymammotion might be problematic. Click here for more details.
- pymammotion/__init__.py +43 -0
- pymammotion/aliyun/cloud_gateway.py +549 -0
- pymammotion/aliyun/cloud_service.py +65 -0
- pymammotion/aliyun/dataclass/aep_response.py +18 -0
- pymammotion/aliyun/dataclass/connect_response.py +51 -0
- pymammotion/aliyun/dataclass/dev_by_account_response.py +43 -0
- pymammotion/aliyun/dataclass/login_by_oauth_response.py +65 -0
- pymammotion/aliyun/dataclass/regions_response.py +26 -0
- pymammotion/aliyun/dataclass/session_by_authcode_response.py +18 -0
- pymammotion/aliyun/tmp_constant.py +175 -0
- pymammotion/bluetooth/__init__.py +1 -0
- pymammotion/bluetooth/ble.py +74 -0
- pymammotion/bluetooth/ble_message.py +430 -0
- pymammotion/bluetooth/const.py +27 -0
- pymammotion/bluetooth/data/__init__.py +0 -0
- pymammotion/bluetooth/data/convert.py +26 -0
- pymammotion/bluetooth/data/framectrldata.py +40 -0
- pymammotion/bluetooth/data/notifydata.py +63 -0
- pymammotion/const.py +9 -0
- pymammotion/data/__init__.py +0 -0
- pymammotion/data/model/__init__.py +8 -0
- pymammotion/data/model/device.py +157 -0
- pymammotion/data/model/enums.py +67 -0
- pymammotion/data/model/excute_boarder_params.py +48 -0
- pymammotion/data/model/execute_boarder.py +36 -0
- pymammotion/data/model/generate_route_information.py +133 -0
- pymammotion/data/model/hash_list.py +17 -0
- pymammotion/data/model/mowing_modes.py +37 -0
- pymammotion/data/model/plan.py +58 -0
- pymammotion/data/model/rapid_state.py +45 -0
- pymammotion/data/model/region_data.py +99 -0
- pymammotion/data/mqtt/__init__.py +1 -0
- pymammotion/data/mqtt/event.py +90 -0
- pymammotion/data/mqtt/properties.py +140 -0
- pymammotion/data/mqtt/status.py +52 -0
- pymammotion/event/__init__.py +6 -0
- pymammotion/event/event.py +50 -0
- pymammotion/http/_init_.py +0 -0
- pymammotion/http/http.py +76 -0
- pymammotion/luba/_init_.py +0 -0
- pymammotion/luba/base.py +52 -0
- pymammotion/mammotion/__init__.py +0 -0
- pymammotion/mammotion/commands/__init__.py +0 -0
- pymammotion/mammotion/commands/abstract_message.py +7 -0
- pymammotion/mammotion/commands/mammotion_command.py +34 -0
- pymammotion/mammotion/commands/messages/__init__.py +0 -0
- pymammotion/mammotion/commands/messages/driver.py +108 -0
- pymammotion/mammotion/commands/messages/media.py +36 -0
- pymammotion/mammotion/commands/messages/navigation.py +535 -0
- pymammotion/mammotion/commands/messages/network.py +236 -0
- pymammotion/mammotion/commands/messages/ota.py +34 -0
- pymammotion/mammotion/commands/messages/system.py +266 -0
- pymammotion/mammotion/commands/messages/video.py +27 -0
- pymammotion/mammotion/control/__init__.py +0 -0
- pymammotion/mammotion/control/joystick.py +184 -0
- pymammotion/mammotion/devices/__init__.py +1 -0
- pymammotion/mammotion/devices/luba.py +564 -0
- pymammotion/mqtt/mqtt.py +230 -0
- pymammotion/proto/__init__.py +0 -0
- pymammotion/proto/common.proto +7 -0
- pymammotion/proto/common.py +12 -0
- pymammotion/proto/common_pb2.py +25 -0
- pymammotion/proto/common_pb2.pyi +13 -0
- pymammotion/proto/dev_net.proto +297 -0
- pymammotion/proto/dev_net.py +381 -0
- pymammotion/proto/dev_net_pb2.py +107 -0
- pymammotion/proto/dev_net_pb2.pyi +472 -0
- pymammotion/proto/luba_msg.proto +73 -0
- pymammotion/proto/luba_msg.py +80 -0
- pymammotion/proto/luba_msg_pb2.py +40 -0
- pymammotion/proto/luba_msg_pb2.pyi +93 -0
- pymammotion/proto/luba_mul.proto +68 -0
- pymammotion/proto/luba_mul.py +76 -0
- pymammotion/proto/luba_mul_pb2.py +45 -0
- pymammotion/proto/luba_mul_pb2.pyi +91 -0
- pymammotion/proto/mctrl_driver.proto +67 -0
- pymammotion/proto/mctrl_driver.py +100 -0
- pymammotion/proto/mctrl_driver_pb2.py +45 -0
- pymammotion/proto/mctrl_driver_pb2.pyi +112 -0
- pymammotion/proto/mctrl_nav.proto +485 -0
- pymammotion/proto/mctrl_nav.py +589 -0
- pymammotion/proto/mctrl_nav_pb2.py +116 -0
- pymammotion/proto/mctrl_nav_pb2.pyi +875 -0
- pymammotion/proto/mctrl_ota.proto +42 -0
- pymammotion/proto/mctrl_ota.py +48 -0
- pymammotion/proto/mctrl_ota_pb2.py +35 -0
- pymammotion/proto/mctrl_ota_pb2.pyi +65 -0
- pymammotion/proto/mctrl_pept.proto +29 -0
- pymammotion/proto/mctrl_pept.py +41 -0
- pymammotion/proto/mctrl_pept_pb2.py +31 -0
- pymammotion/proto/mctrl_pept_pb2.pyi +50 -0
- pymammotion/proto/mctrl_sys.proto +487 -0
- pymammotion/proto/mctrl_sys.py +574 -0
- pymammotion/proto/mctrl_sys_pb2.py +142 -0
- pymammotion/proto/mctrl_sys_pb2.pyi +787 -0
- pymammotion/py.typed +0 -0
- pymammotion/utility/constant/__init__.py +1 -0
- pymammotion/utility/constant/device_constant.py +238 -0
- pymammotion/utility/datatype_converter.py +80 -0
- pymammotion/utility/device_type.py +152 -0
- pymammotion/utility/periodic.py +41 -0
- pymammotion/utility/rocker_util.py +135 -0
- pymammotion-0.0.37.dist-info/LICENSE +674 -0
- pymammotion-0.0.37.dist-info/METADATA +92 -0
- pymammotion-0.0.37.dist-info/RECORD +106 -0
- pymammotion-0.0.37.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from timeit import default_timer as timer
|
|
3
|
+
|
|
4
|
+
import nest_asyncio
|
|
5
|
+
import pyjoystick
|
|
6
|
+
from pyjoystick.sdl2 import Key, run_event_loop
|
|
7
|
+
from pyjoystick.utils import PeriodicThread
|
|
8
|
+
|
|
9
|
+
from pyluba import MammotionBaseBLEDevice
|
|
10
|
+
from pyluba.event import BleNotificationEvent
|
|
11
|
+
from pyluba.utility.rocker_util import RockerControlUtil
|
|
12
|
+
|
|
13
|
+
bleNotificationEvt = BleNotificationEvent()
|
|
14
|
+
|
|
15
|
+
nest_asyncio.apply()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class JoystickControl:
|
|
19
|
+
"""Joystick class for controlling Luba with a joystick"""
|
|
20
|
+
|
|
21
|
+
angular_percent = 0
|
|
22
|
+
linear_percent = 0
|
|
23
|
+
linear_speed = 0
|
|
24
|
+
angular_speed = 0
|
|
25
|
+
ignore_events = False
|
|
26
|
+
_blade_height = 25
|
|
27
|
+
worker = None
|
|
28
|
+
|
|
29
|
+
def __init__(self, luba_ble: MammotionBaseBLEDevice):
|
|
30
|
+
self._client = luba_ble
|
|
31
|
+
self._curr_time = timer()
|
|
32
|
+
self.stopped = False
|
|
33
|
+
|
|
34
|
+
repeater = pyjoystick.HatRepeater(
|
|
35
|
+
first_repeat_timeout=0.2, repeat_timeout=0.03, check_timeout=0.01
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
self.mngr = pyjoystick.ThreadEventManager(
|
|
39
|
+
event_loop=run_event_loop,
|
|
40
|
+
handle_key_event=self.key_received,
|
|
41
|
+
add_joystick=self.print_add,
|
|
42
|
+
remove_joystick=self.print_remove,
|
|
43
|
+
button_repeater=repeater,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
self.worker = PeriodicThread(
|
|
47
|
+
0.2, self.run_movement, name="luba-process_movements"
|
|
48
|
+
)
|
|
49
|
+
self.worker.alive = self.mngr.alive # stop when this event stops
|
|
50
|
+
self.worker.daemon = True
|
|
51
|
+
|
|
52
|
+
def _movement_finished(self):
|
|
53
|
+
self.ignore_events = False
|
|
54
|
+
|
|
55
|
+
def run_movement(self):
|
|
56
|
+
if self.linear_percent == 0.0 and self.angular_percent == 0.0:
|
|
57
|
+
if self.stopped:
|
|
58
|
+
return
|
|
59
|
+
self.stopped = True
|
|
60
|
+
self.stopped = False
|
|
61
|
+
(linear_speed, angular_speed) = self.transform_both_speeds(
|
|
62
|
+
self.linear_speed,
|
|
63
|
+
self.angular_speed,
|
|
64
|
+
self.linear_percent,
|
|
65
|
+
self.angular_percent,
|
|
66
|
+
)
|
|
67
|
+
asyncio.run(
|
|
68
|
+
self._client.command(
|
|
69
|
+
"send_movement", linear_speed=linear_speed, angular_speed=angular_speed
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
def print_add(self, joy):
|
|
74
|
+
print("Added", joy)
|
|
75
|
+
|
|
76
|
+
def print_remove(self, joy):
|
|
77
|
+
print("Removed", joy)
|
|
78
|
+
|
|
79
|
+
def key_received(self, key):
|
|
80
|
+
self.handle_key_received(key)
|
|
81
|
+
|
|
82
|
+
def run_controller(self):
|
|
83
|
+
self.mngr.start()
|
|
84
|
+
self.worker.start()
|
|
85
|
+
|
|
86
|
+
def get_percent(self, percent: float):
|
|
87
|
+
if percent <= 15.0:
|
|
88
|
+
return 0.0
|
|
89
|
+
|
|
90
|
+
return percent - 15.0
|
|
91
|
+
|
|
92
|
+
@staticmethod
|
|
93
|
+
def transform_both_speeds(
|
|
94
|
+
linear: float, angular: float, linear_percent: float, angular_percent: float
|
|
95
|
+
):
|
|
96
|
+
transfrom3 = RockerControlUtil.getInstance().transfrom3(linear, linear_percent)
|
|
97
|
+
transform4 = RockerControlUtil.getInstance().transfrom3(
|
|
98
|
+
angular, angular_percent
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
if transfrom3 is not None and len(transfrom3) > 0:
|
|
102
|
+
linear_speed = transfrom3[0] * 10
|
|
103
|
+
angular_speed = int(transform4[1] * 4.5)
|
|
104
|
+
print(linear_speed, angular_speed)
|
|
105
|
+
return linear_speed, angular_speed
|
|
106
|
+
|
|
107
|
+
def handle_key_received(self, key):
|
|
108
|
+
# print(key, "-", key.keytype, "-", key.number, "-", key.value)
|
|
109
|
+
|
|
110
|
+
if key.keytype is Key.BUTTON and key.value == 1:
|
|
111
|
+
# print(key, "-", key.keytype, "-", key.number, "-", key.value)
|
|
112
|
+
if key.number == 0: # x
|
|
113
|
+
asyncio.run(self._client.command("return_to_dock"))
|
|
114
|
+
if key.number == 1:
|
|
115
|
+
asyncio.run(self._client.command("leave_dock"))
|
|
116
|
+
if key.number == 3:
|
|
117
|
+
asyncio.run(self._client.command("set_blade_control", on_off=1))
|
|
118
|
+
if key.number == 2:
|
|
119
|
+
asyncio.run(self._client.command("set_blade_control", on_off=0))
|
|
120
|
+
if key.number == 9:
|
|
121
|
+
# lower knife height
|
|
122
|
+
if self._blade_height > 25:
|
|
123
|
+
self._blade_height -= 5
|
|
124
|
+
asyncio.run(
|
|
125
|
+
self._client.command(
|
|
126
|
+
"set_blade_height", height=self._blade_height
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
if key.number == 10:
|
|
130
|
+
# raise knife height
|
|
131
|
+
if self._blade_height < 60:
|
|
132
|
+
self._blade_height += 5
|
|
133
|
+
asyncio.run(
|
|
134
|
+
self._client.command(
|
|
135
|
+
"set_blade_height", height=self._blade_height
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
if key.keytype is Key.AXIS:
|
|
140
|
+
# print(key, "-", key.keytype, "-", key.number, "-", key.value)
|
|
141
|
+
if key.value > 0.09 or key.value < -0.09:
|
|
142
|
+
match key.number:
|
|
143
|
+
case 1: # left (up down)
|
|
144
|
+
# take left right values and convert to linear movement
|
|
145
|
+
# -1 is forward
|
|
146
|
+
# 1 is back
|
|
147
|
+
|
|
148
|
+
# linear_speed==1000
|
|
149
|
+
# linear_speed==-1000
|
|
150
|
+
print("case 1")
|
|
151
|
+
if key.value > 0:
|
|
152
|
+
self.linear_speed = 270.0
|
|
153
|
+
self.linear_percent = self.get_percent(abs(key.value * 100))
|
|
154
|
+
else:
|
|
155
|
+
self.linear_speed = 90.0
|
|
156
|
+
self.linear_percent = self.get_percent(abs(key.value * 100))
|
|
157
|
+
|
|
158
|
+
case 2: # right (left right)
|
|
159
|
+
# take left right values and convert to angular movement
|
|
160
|
+
# -1 left
|
|
161
|
+
# 1 is right
|
|
162
|
+
# angular_speed==-450
|
|
163
|
+
# angular_speed==450
|
|
164
|
+
if key.value > 0:
|
|
165
|
+
self.angular_speed = 0.0
|
|
166
|
+
self.angular_percent = self.get_percent(
|
|
167
|
+
abs(key.value * 100)
|
|
168
|
+
)
|
|
169
|
+
else:
|
|
170
|
+
# angle=180.0
|
|
171
|
+
# linear_speed=0//angular_speed=-450
|
|
172
|
+
self.angular_speed = 180.0
|
|
173
|
+
self.angular_percent = self.get_percent(
|
|
174
|
+
abs(key.value * 100)
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
else:
|
|
178
|
+
match key.number:
|
|
179
|
+
case 1: # left (up down)
|
|
180
|
+
self.linear_speed = 0.0
|
|
181
|
+
self.linear_percent = 0.0
|
|
182
|
+
case 2: # right (left right)
|
|
183
|
+
self.angular_speed = 0.0
|
|
184
|
+
self.angular_percent = 0.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .luba import MammotionBaseBLEDevice, has_field
|