robotframework-parrot-touchcontroller 1.0.0__tar.gz → 1.0.2__tar.gz
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.
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/PKG-INFO +4 -4
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/parrot/TouchController.py +22 -16
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/parrot/touch/adbtouch.py +5 -18
- robotframework_parrot_touchcontroller-1.0.2/parrot/touch/axitouch.py +379 -0
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/pyproject.toml +4 -4
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/robotframework_parrot_touchcontroller.egg-info/PKG-INFO +4 -4
- robotframework_parrot_touchcontroller-1.0.2/robotframework_parrot_touchcontroller.egg-info/requires.txt +3 -0
- robotframework_parrot_touchcontroller-1.0.0/parrot/touch/axitouch.py +0 -185
- robotframework_parrot_touchcontroller-1.0.0/robotframework_parrot_touchcontroller.egg-info/requires.txt +0 -3
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/README.md +0 -0
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/parrot/touch/base.py +0 -0
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/parrot/touch/dummy.py +0 -0
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/parrot/touch/usbhidtouch.py +0 -0
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/robotframework_parrot_touchcontroller.egg-info/SOURCES.txt +0 -0
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/robotframework_parrot_touchcontroller.egg-info/dependency_links.txt +0 -0
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/robotframework_parrot_touchcontroller.egg-info/top_level.txt +0 -0
- {robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/setup.cfg +0 -0
{robotframework_parrot_touchcontroller-1.0.0 → robotframework_parrot_touchcontroller-1.0.2}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: robotframework-parrot-touchcontroller
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: Touch control api to use within the Robot Framework ecosystem
|
|
5
5
|
Author-email: Zilogic Systems <code@zilogic.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -9,9 +9,9 @@ Project-URL: Repository, https://github.com//zilogic-systems/parrot.git
|
|
|
9
9
|
Project-URL: Issues, https://github.com/zilogic-systems/parrot/issues
|
|
10
10
|
Requires-Python: >=3.6
|
|
11
11
|
Description-Content-Type: text/markdown
|
|
12
|
-
Requires-Dist: robotframework
|
|
13
|
-
Requires-Dist: pyyaml
|
|
14
|
-
Requires-Dist: robotframework-parrot-adbcontroller
|
|
12
|
+
Requires-Dist: robotframework~=7.3.2
|
|
13
|
+
Requires-Dist: pyyaml~=6.0.2
|
|
14
|
+
Requires-Dist: robotframework-parrot-adbcontroller~=1.0.0
|
|
15
15
|
|
|
16
16
|
# Touch Controller
|
|
17
17
|
|
|
@@ -17,9 +17,9 @@ class TouchController:
|
|
|
17
17
|
|
|
18
18
|
== Configuration ==
|
|
19
19
|
|
|
20
|
-
Touch devices are configured using the `Touch Setup` keyword with a dictionary
|
|
21
|
-
typically loaded from a YAML file (e.g. `config.yaml`) by importing the library
|
|
22
|
-
and variables into your test suite. Each entry in the configuration must include
|
|
20
|
+
Touch devices are configured using the `Touch Setup` keyword with a dictionary
|
|
21
|
+
typically loaded from a YAML file (e.g. `config.yaml`) by importing the library
|
|
22
|
+
and variables into your test suite. Each entry in the configuration must include
|
|
23
23
|
a `type` field that specifies the device type. Supported types include:
|
|
24
24
|
|
|
25
25
|
- `UsbHidTouch`: USB HID-based touch simulation over TCP.
|
|
@@ -40,11 +40,17 @@ class TouchController:
|
|
|
40
40
|
- `width`, `height`: Touch surface resolution in pixels
|
|
41
41
|
- `start_pos`: Physical start coordinates (e.g., `[0, 0]`)
|
|
42
42
|
- `end_pos`: Physical end coordinates defining working area (e.g., `[8.66, 5.12]`)
|
|
43
|
+
- `orientation`: Defines how touchscreen pixel coordinates are mapped to
|
|
44
|
+
the AxiDraw's coordinate system (e.g., `landscape` or `portrait`).
|
|
45
|
+
- `landscape`: Screen X maps to Robot Y, Screen Y maps to Robot X.
|
|
46
|
+
- `portrait`: Screen X maps to Robot X, Screen Y maps to Robot Y.
|
|
47
|
+
|
|
48
|
+
|
|
43
49
|
|
|
44
50
|
=== ADBTouch ===
|
|
45
51
|
Simulates touch events on an Android device using ADB commands.
|
|
46
52
|
Supported configs:
|
|
47
|
-
- `
|
|
53
|
+
- `type`: ADBTouch
|
|
48
54
|
|
|
49
55
|
=== Configuration Sample (config.yaml) ===
|
|
50
56
|
|
|
@@ -66,15 +72,15 @@ class TouchController:
|
|
|
66
72
|
| height: 600
|
|
67
73
|
| start_pos: [0, 0]
|
|
68
74
|
| end_pos: [8.66, 5.12]
|
|
75
|
+
| orientation: landscape
|
|
69
76
|
|
|
|
70
77
|
| T3:
|
|
71
78
|
| type: ADBTouch
|
|
72
|
-
| ip: 192.168.43.168
|
|
73
79
|
|
|
74
80
|
= General Usage =
|
|
75
81
|
|
|
76
|
-
Setup and initialize touch devices from a YAML configuration. Simulate touch input such as tap and swipe gestures
|
|
77
|
-
across multiple supported devices. This library supports both real physical systems and simulated touch environments,
|
|
82
|
+
Setup and initialize touch devices from a YAML configuration. Simulate touch input such as tap and swipe gestures
|
|
83
|
+
across multiple supported devices. This library supports both real physical systems and simulated touch environments,
|
|
78
84
|
making it suitable for automated device interaction and UI testing.
|
|
79
85
|
|
|
80
86
|
= Example =
|
|
@@ -102,7 +108,7 @@ class TouchController:
|
|
|
102
108
|
@keyword("Touch Setup")
|
|
103
109
|
def setup(self, config: Dict[str, Dict[str, Any]]) -> None:
|
|
104
110
|
"""Initializes and configures touch controller devices.
|
|
105
|
-
Loads controller instances from the given `Configuration` dictionary
|
|
111
|
+
Loads controller instances from the given `Configuration` dictionary
|
|
106
112
|
and prepares them for input simulation.
|
|
107
113
|
|
|
108
114
|
*Syntax*
|
|
@@ -144,11 +150,11 @@ class TouchController:
|
|
|
144
150
|
print(f"[INFO] Loaded controllers: {list(self.devices.keys())}")
|
|
145
151
|
|
|
146
152
|
@keyword("Tap")
|
|
147
|
-
def send_touch(self, device: str, x: float, y: float, tap_time: float
|
|
153
|
+
def send_touch(self, device: str, x: float, y: float, tap_time: float) -> None:
|
|
148
154
|
"""
|
|
149
155
|
Simulates a tap action on the given device at specified screen coordinates.
|
|
150
|
-
Requires the device name, X and Y coordinates in pixels, and an
|
|
151
|
-
|
|
156
|
+
Requires the device name, X and Y coordinates in pixels, and an
|
|
157
|
+
tap duration.
|
|
152
158
|
|
|
153
159
|
*Syntax*
|
|
154
160
|
|
|
@@ -197,11 +203,11 @@ class TouchController:
|
|
|
197
203
|
"""
|
|
198
204
|
Executes a backend-specific touch command on the given device controller.
|
|
199
205
|
|
|
200
|
-
This keyword is used to send a command (e.g., `Move`, `Home`) to a specific device.
|
|
201
|
-
The available commands and required arguments depends on the backend implementation
|
|
206
|
+
This keyword is used to send a command (e.g., `Move`, `Home`) to a specific device.
|
|
207
|
+
The available commands and required arguments depends on the backend implementation
|
|
202
208
|
of the touch controller. Currently only the AxiDrawTouch backend has commands.
|
|
203
209
|
|
|
204
|
-
AxiDrawTouch backend supports the following commands.
|
|
210
|
+
AxiDrawTouch backend supports the following commands.
|
|
205
211
|
|
|
206
212
|
- `Move` — Moves to the specified position (in inches) without touching.
|
|
207
213
|
Requires two arguments: `x`, `y`.
|
|
@@ -228,12 +234,12 @@ class TouchController:
|
|
|
228
234
|
def set_param_auto_home(self, device: str, param: str, value: str) -> None:
|
|
229
235
|
"""
|
|
230
236
|
Sets values to configure runtime parameters for Touch control devices.
|
|
231
|
-
|
|
237
|
+
|
|
232
238
|
Currently, this keyword supports only for `AxiDrawTouch` type devices,
|
|
233
239
|
|
|
234
240
|
| *Parameter* | *Description* | *Example Value* |
|
|
235
241
|
| `auto_home` | Specifies the touch action to be directed to the home position | "True or False" |
|
|
236
|
-
|
|
242
|
+
|
|
237
243
|
*Syntax*
|
|
238
244
|
|
|
239
245
|
| `Touch Set Param` | <DEVICE_NAME> | auto_home | <VALUE> |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from
|
|
1
|
+
from robot.libraries.BuiltIn import BuiltIn
|
|
2
2
|
from parrot.touch.base import BaseTouch, Error
|
|
3
3
|
|
|
4
4
|
class ADBTouch(BaseTouch):
|
|
@@ -12,20 +12,8 @@ class ADBTouch(BaseTouch):
|
|
|
12
12
|
def __init__(self, config: dict):
|
|
13
13
|
"""
|
|
14
14
|
Initializes the ADB touch controller.
|
|
15
|
-
|
|
16
|
-
The configuration dictionary must contain:
|
|
17
|
-
- `ip`: IP address of the ADB-connected device
|
|
18
|
-
|
|
19
|
-
Raises:
|
|
20
|
-
Error: If required configuration is missing or initialization fails.
|
|
21
15
|
"""
|
|
22
|
-
|
|
23
|
-
self.device_ip = config["ip"]
|
|
24
|
-
self.adb = ADBController.ADBController()
|
|
25
|
-
except KeyError as err:
|
|
26
|
-
raise Error(f"Missing required configuration key: {err}") from err
|
|
27
|
-
except Exception as err:
|
|
28
|
-
raise Error(f"Initialization failed: {err}") from err
|
|
16
|
+
self.adb = None
|
|
29
17
|
|
|
30
18
|
def touch_init(self):
|
|
31
19
|
"""
|
|
@@ -35,10 +23,9 @@ class ADBTouch(BaseTouch):
|
|
|
35
23
|
Error: If the device connection fails.
|
|
36
24
|
"""
|
|
37
25
|
try:
|
|
38
|
-
self.adb.
|
|
39
|
-
print(f"ADBTouch: Connected to device {self.device_ip}")
|
|
26
|
+
self.adb = BuiltIn().get_library_instance("parrot.ADBController")
|
|
40
27
|
except Exception as err:
|
|
41
|
-
raise Error("Initialization failed") from err
|
|
28
|
+
raise Error(f"ADB Touch Initialization failed: {err}") from err
|
|
42
29
|
|
|
43
30
|
def touch_tap(self, x, y, tap_time):
|
|
44
31
|
"""
|
|
@@ -79,6 +66,6 @@ class ADBTouch(BaseTouch):
|
|
|
79
66
|
print(f"ADBTouch: Swipe from ({startx}, {starty}) to ({endx}, {endy})")
|
|
80
67
|
except Exception as err:
|
|
81
68
|
raise Error(f"Swipe failed from ({startx}, {starty}) to ({endx}, {endy})") from err
|
|
82
|
-
|
|
69
|
+
|
|
83
70
|
def touch_command(self, cmd, *args):
|
|
84
71
|
raise Error("Commands are not supported by the ADBTouch backend")
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
# pylint: disable=no-member
|
|
2
|
+
|
|
3
|
+
from robot.api.deco import keyword
|
|
4
|
+
from parrot.touch.base import BaseTouch,Error
|
|
5
|
+
from typing import Tuple, Any
|
|
6
|
+
import yaml
|
|
7
|
+
import os
|
|
8
|
+
import tkinter as tk
|
|
9
|
+
from tkinter import messagebox
|
|
10
|
+
|
|
11
|
+
import xmlrpc.client
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class AxiTouchError(Exception):
|
|
15
|
+
"""Represents an error in the AxiDrawTouch controller."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AxiDrawTouch(BaseTouch):
|
|
19
|
+
"""A touch controller implementation using the AxiDraw plotting device.
|
|
20
|
+
|
|
21
|
+
This class provides methods to simulate touch gestures such as tap and swipe
|
|
22
|
+
by controlling an AxiDraw plotter based on screen coordinates.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
PROPERTIES = ["auto_home"]
|
|
26
|
+
|
|
27
|
+
def __init__(self, config: dict[str, Any]) -> None:
|
|
28
|
+
"""Initializes the AxiDraw touch controller.
|
|
29
|
+
|
|
30
|
+
The configuration dictionary must contain:
|
|
31
|
+
- `width`: screen width in pixels
|
|
32
|
+
- `height`: screen height in pixels
|
|
33
|
+
- `start_pos`: tuple (x, y) of starting cartesian coordinates (in inches)
|
|
34
|
+
- `end_pos`: tuple (x, y) of ending cartesian coordinates (in inches)
|
|
35
|
+
|
|
36
|
+
Raises:
|
|
37
|
+
AxiTouchError: If initialization or connection to AxiDraw fails.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
uri = f"http://{config['host']}:{config['port']}"
|
|
42
|
+
self.screen_width_px: int = config["width"]
|
|
43
|
+
self.screen_height_px: int = config["height"]
|
|
44
|
+
self.auto_home = False # Flag to track auto-home behavior
|
|
45
|
+
self.calibration_file: str = config["calibration_data"]
|
|
46
|
+
self.device_name = config.get("device_name")
|
|
47
|
+
self.start_x_pos = None
|
|
48
|
+
self.start_y_pos = None
|
|
49
|
+
self.end_x_pos = None
|
|
50
|
+
self.end_y_pos = None
|
|
51
|
+
self.start_position = None
|
|
52
|
+
self.end_position = None
|
|
53
|
+
self.orientation = config.get("orientation")
|
|
54
|
+
|
|
55
|
+
# Optional: configure pen heights and speed
|
|
56
|
+
pen_pos_up = 75
|
|
57
|
+
pen_pos_down = 40
|
|
58
|
+
speed_pendown = 100
|
|
59
|
+
speed_penup = 100
|
|
60
|
+
accel = 75
|
|
61
|
+
|
|
62
|
+
self.axi = xmlrpc.client.ServerProxy(uri)
|
|
63
|
+
|
|
64
|
+
self.axi.connect(accel,
|
|
65
|
+
pen_pos_up, pen_pos_down,
|
|
66
|
+
speed_penup, speed_pendown)
|
|
67
|
+
self._load_calibration_data()
|
|
68
|
+
|
|
69
|
+
except KeyError as err:
|
|
70
|
+
raise Error(f"Missing required configuration key: {err}") from err
|
|
71
|
+
except Exception as err:
|
|
72
|
+
raise Error(f"Initialization failed: {err}") from err
|
|
73
|
+
|
|
74
|
+
def _load_calibration_data(self):
|
|
75
|
+
"""Load start and end Cartesian positions from calibration YAML."""
|
|
76
|
+
if not os.path.exists(self.calibration_file):
|
|
77
|
+
raise FileNotFoundError(
|
|
78
|
+
f"Calibration file '{self.calibration_file}' not found. "
|
|
79
|
+
f"Please perform calibration to get the start and end positions."
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
with open(self.calibration_file, 'r') as file:
|
|
84
|
+
config = yaml.safe_load(file) or {}
|
|
85
|
+
except yaml.YAMLError as e:
|
|
86
|
+
raise ValueError(
|
|
87
|
+
f"Error reading YAML from '{self.calibration_file}': {e}"
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
if "start_position" not in config or "end_position" not in config:
|
|
91
|
+
raise KeyError(
|
|
92
|
+
"Missing 'start_position' or 'end_position' in calibration file. "
|
|
93
|
+
"Please perform calibration again."
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
self.cartesian_start = tuple(config["start_position"])
|
|
97
|
+
self.cartesian_end = tuple(config["end_position"])
|
|
98
|
+
|
|
99
|
+
def convert_to_inches(self, x: float, y: float) -> Tuple[float, float]:
|
|
100
|
+
"""Convert screen coordinates (x, y) in pixels to Cartesian coordinates in inches.
|
|
101
|
+
|
|
102
|
+
*Args:*
|
|
103
|
+
`x` (float): X-coordinate in pixels.
|
|
104
|
+
`y` (float): Y-coordinate in pixels.
|
|
105
|
+
`orientation` (str): The orientation of the screen ('landscape' or 'portrait').
|
|
106
|
+
|
|
107
|
+
*Returns:*
|
|
108
|
+
`Tuple[float, float]`: Corresponding Cartesian coordinates (x, y) in inches.
|
|
109
|
+
|
|
110
|
+
*Raises:*
|
|
111
|
+
ValueError: If the screen coordinates are out of bounds or if calibration data is missing.
|
|
112
|
+
|
|
113
|
+
*NOTE:*
|
|
114
|
+
Use "landscape" when the screen X-axis maps to the robot Y-axis and
|
|
115
|
+
the screen Y-axis maps to the robot X-axis, as shown below.
|
|
116
|
+
|
|
117
|
+
Robot Y
|
|
118
|
+
+-----------------------------+
|
|
119
|
+
| |
|
|
120
|
+
| Screen X |
|
|
121
|
+
| +-------------------+ |
|
|
122
|
+
Robot X | | | Screen Y
|
|
123
|
+
| | | |
|
|
124
|
+
| +-------------------+ |
|
|
125
|
+
| |
|
|
126
|
+
| |
|
|
127
|
+
| |
|
|
128
|
+
+-----------------------------+
|
|
129
|
+
|
|
130
|
+
Use "portrait" when the screen X-axis maps to the robot X-axis and
|
|
131
|
+
the screen Y-axis maps to the robot Y-axis, as shown below.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
Robot Y
|
|
135
|
+
+-----------------------------+
|
|
136
|
+
| Screen Y |
|
|
137
|
+
| +-------+ |
|
|
138
|
+
| | | |
|
|
139
|
+
Robot X | | | |
|
|
140
|
+
| | | Screen X |
|
|
141
|
+
| | | |
|
|
142
|
+
| | | |
|
|
143
|
+
| | | |
|
|
144
|
+
| +-------+ |
|
|
145
|
+
+-----------------------------+
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
x = float(x)
|
|
149
|
+
y = float(y)
|
|
150
|
+
|
|
151
|
+
if not self.orientation:
|
|
152
|
+
self.orientation = "landscape"
|
|
153
|
+
|
|
154
|
+
sx, sy = self.cartesian_start
|
|
155
|
+
ex, ey = self.cartesian_end
|
|
156
|
+
|
|
157
|
+
if self.orientation == 'landscape':
|
|
158
|
+
x_scale = (ex - sx) / self.screen_height_px
|
|
159
|
+
y_scale = (ey - sy) / self.screen_width_px
|
|
160
|
+
|
|
161
|
+
robot_x = sx + y * x_scale
|
|
162
|
+
robot_y = sy + x * y_scale
|
|
163
|
+
|
|
164
|
+
elif self.orientation == 'portrait':
|
|
165
|
+
x_scale = (ex - sx) / self.screen_width_px
|
|
166
|
+
y_scale = (ey - sy) / self.screen_height_px
|
|
167
|
+
|
|
168
|
+
robot_x = sx + x * x_scale
|
|
169
|
+
robot_y = sy + y * y_scale
|
|
170
|
+
|
|
171
|
+
else:
|
|
172
|
+
raise ValueError("orientation must be either 'landscape' or 'portrait'")
|
|
173
|
+
|
|
174
|
+
return round(robot_x, 3), round(robot_y, 3)
|
|
175
|
+
|
|
176
|
+
def _validate_screen_coordinates(self, x: float, y: float) -> None:
|
|
177
|
+
"""Validate that the screen coordinates are within the configured display."""
|
|
178
|
+
|
|
179
|
+
if not (0 <= x <= self.screen_width_px):
|
|
180
|
+
raise Error(
|
|
181
|
+
f"Touch tap failed at ({x}, {y}) due to out-of-bound coordinates"
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
if not (0 <= y <= self.screen_height_px):
|
|
185
|
+
raise Error(
|
|
186
|
+
f"Touch tap failed at ({x}, {y}) due to out-of-bound coordinates"
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def touch_init(self) -> None:
|
|
191
|
+
"""Initialize the pen by lifting it up and moving to origin (0, 0).
|
|
192
|
+
|
|
193
|
+
Raises:
|
|
194
|
+
AxiTouchError: If initialization movement fails.
|
|
195
|
+
"""
|
|
196
|
+
|
|
197
|
+
try:
|
|
198
|
+
self.axi.penup()
|
|
199
|
+
self.axi.home()
|
|
200
|
+
print("AxiDrawTouch: Initialized and moved to origin")
|
|
201
|
+
except Exception as err:
|
|
202
|
+
raise Error("Initialization failed") from err
|
|
203
|
+
|
|
204
|
+
def touch_tap(self, x: float, y: float, tap_time) -> None:
|
|
205
|
+
"""Simulate a tap at the given screen coordinates.
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
x (int | float): X-coordinate in pixels.
|
|
209
|
+
y (int | float): Y-coordinate in pixels.
|
|
210
|
+
tap_time (float): Duration to hold pen down.
|
|
211
|
+
Raises:
|
|
212
|
+
AxiTouchError: If the tap operation fails.
|
|
213
|
+
"""
|
|
214
|
+
|
|
215
|
+
try:
|
|
216
|
+
x = float(x)
|
|
217
|
+
y = float(y)
|
|
218
|
+
self._validate_screen_coordinates(x, y)
|
|
219
|
+
px, py = self.convert_to_inches(x, y)
|
|
220
|
+
print(px, py)
|
|
221
|
+
self.axi.tap(px, py, tap_time)
|
|
222
|
+
if self.auto_home:
|
|
223
|
+
self.axi.home()
|
|
224
|
+
print(f"AxiDrawTouch: Tap at ({x}, {y}) for {tap_time}s")
|
|
225
|
+
except Error:
|
|
226
|
+
raise
|
|
227
|
+
except Exception as err:
|
|
228
|
+
raise Error(f"Touch tap failed at ({x}, {y})") from err
|
|
229
|
+
|
|
230
|
+
def touch_swipe(
|
|
231
|
+
self,
|
|
232
|
+
startx: float,
|
|
233
|
+
starty: float,
|
|
234
|
+
endx: float,
|
|
235
|
+
endy: float
|
|
236
|
+
) -> None:
|
|
237
|
+
"""Simulate a swipe gesture from start to end coordinates.
|
|
238
|
+
|
|
239
|
+
Args:
|
|
240
|
+
startx (int | float): Start X-coordinate in pixels.
|
|
241
|
+
starty (int | float): Start Y-coordinate in pixels.
|
|
242
|
+
endx (int | float): End X-coordinate in pixels.
|
|
243
|
+
endy (int | float): End Y-coordinate in pixels.
|
|
244
|
+
swipe_time (float): Duration of the swipe.
|
|
245
|
+
|
|
246
|
+
Raises:
|
|
247
|
+
AxiTouchError: If the swipe operation fails.
|
|
248
|
+
"""
|
|
249
|
+
|
|
250
|
+
try:
|
|
251
|
+
startx = float(startx)
|
|
252
|
+
starty = float(starty)
|
|
253
|
+
endx = float(endx)
|
|
254
|
+
endy = float(endy)
|
|
255
|
+
self._validate_screen_coordinates(startx, starty)
|
|
256
|
+
self._validate_screen_coordinates(endx, endy)
|
|
257
|
+
psx, psy = self.convert_to_inches(startx, starty)
|
|
258
|
+
pex, pey = self.convert_to_inches(endx, endy)
|
|
259
|
+
self.axi.swipe(psx, psy, pex, pey)
|
|
260
|
+
|
|
261
|
+
print(
|
|
262
|
+
f"AxiDrawTouch: Swipe from "f"({startx}, {starty}) to ({endx}, {endy})")
|
|
263
|
+
|
|
264
|
+
except Error:
|
|
265
|
+
raise
|
|
266
|
+
|
|
267
|
+
except Exception as err:
|
|
268
|
+
raise Error(
|
|
269
|
+
f"Swipe failed from "
|
|
270
|
+
f"({startx}, {starty}) to ({endx}, {endy})") from err
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def move(self, x: float, y: float):
|
|
274
|
+
"""
|
|
275
|
+
Moving Axi arm to the absolute position in axi usable
|
|
276
|
+
area. where x and y are inches.
|
|
277
|
+
"""
|
|
278
|
+
try:
|
|
279
|
+
if x == 0 and y == 0:
|
|
280
|
+
self.axi.home()
|
|
281
|
+
return
|
|
282
|
+
self.axi.move(x, y)
|
|
283
|
+
except Exception as err:
|
|
284
|
+
raise Error(f"Failed to Move pointing device from ({x}, {y})") from err
|
|
285
|
+
|
|
286
|
+
def home(self):
|
|
287
|
+
"""Returns the touch to its home default position."""
|
|
288
|
+
try:
|
|
289
|
+
self.axi.home_with_limit_switch()
|
|
290
|
+
except Exception as err:
|
|
291
|
+
raise Error(f"Failed to Home pointing device") from err
|
|
292
|
+
|
|
293
|
+
def wait_for_ok(self, message):
|
|
294
|
+
root = tk.Tk()
|
|
295
|
+
root.withdraw()
|
|
296
|
+
messagebox.showinfo("Position Calculation", message)
|
|
297
|
+
root.destroy()
|
|
298
|
+
|
|
299
|
+
def calibrate(self):
|
|
300
|
+
"""Returns the calibration for start and end position"""
|
|
301
|
+
try:
|
|
302
|
+
|
|
303
|
+
self.start_x_pos, self.start_y_pos = self._calibrate_corner(f"Move the TouchBot arm to the top-left corner of {self.device_name}. Click OK to continue.")
|
|
304
|
+
|
|
305
|
+
self.end_x_pos, self.end_y_pos = self._calibrate_corner(f"Move the TouchBot arm to the bottom-right corner of {self.device_name}. Click OK to continue.")
|
|
306
|
+
|
|
307
|
+
self.save_calibrate_position()
|
|
308
|
+
|
|
309
|
+
except Exception as err:
|
|
310
|
+
raise Error("Failed to Calibrate the device") from err
|
|
311
|
+
|
|
312
|
+
def _calibrate_corner(self, message: str):
|
|
313
|
+
"""Calibrate a corner and reconnect the AXI server afterward."""
|
|
314
|
+
self.axi.disconnect()
|
|
315
|
+
try:
|
|
316
|
+
self.wait_for_ok(message)
|
|
317
|
+
self.axi.connect()
|
|
318
|
+
x, y = self.axi.calibrate_with_limit_switch()
|
|
319
|
+
return round(abs(x), 2), round(abs(y), 2)
|
|
320
|
+
|
|
321
|
+
finally:
|
|
322
|
+
self.axi.disconnect()
|
|
323
|
+
self.axi.connect()
|
|
324
|
+
|
|
325
|
+
def save_calibrate_position(self):
|
|
326
|
+
try:
|
|
327
|
+
calibrate_position = {}
|
|
328
|
+
|
|
329
|
+
if not os.path.exists(self.calibration_file):
|
|
330
|
+
pass
|
|
331
|
+
else:
|
|
332
|
+
with open(self.calibration_file, "r") as file:
|
|
333
|
+
loaded_file = yaml.safe_load(file)
|
|
334
|
+
if isinstance(loaded_file, dict):
|
|
335
|
+
calibrate_position = loaded_file
|
|
336
|
+
|
|
337
|
+
calibrate_position["start_position"] = [self.start_x_pos, self.start_y_pos]
|
|
338
|
+
calibrate_position["end_position"] = [self.end_x_pos, self.end_y_pos]
|
|
339
|
+
|
|
340
|
+
with open(self.calibration_file, "w") as file:
|
|
341
|
+
yaml.safe_dump(calibrate_position, file, sort_keys=False)
|
|
342
|
+
|
|
343
|
+
print("YAML file updated successfully.")
|
|
344
|
+
|
|
345
|
+
except Exception as err:
|
|
346
|
+
raise Error(f"Error saving ArUco points: {err}") from err
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def touch_command(self, cmd, *args):
|
|
350
|
+
"""Executes a backend-specific touch command on the given device controller."""
|
|
351
|
+
cmd = cmd.lower()
|
|
352
|
+
if cmd == "move":
|
|
353
|
+
if len(args) != 2:
|
|
354
|
+
raise Error("move command expects x and y as argument")
|
|
355
|
+
x = float(args[0])
|
|
356
|
+
y = float(args[1])
|
|
357
|
+
self.move(x, y)
|
|
358
|
+
elif cmd == "home":
|
|
359
|
+
self.home()
|
|
360
|
+
elif cmd == "calibrate":
|
|
361
|
+
self.calibrate()
|
|
362
|
+
else:
|
|
363
|
+
raise Error(f"Invalid command {cmd}")
|
|
364
|
+
|
|
365
|
+
def set_param(self, param: str, value: bool) -> None:
|
|
366
|
+
"""
|
|
367
|
+
Set a runtime parameter for ArucoCapture.
|
|
368
|
+
|
|
369
|
+
| *Arguments* | *Description* |
|
|
370
|
+
| `param (str)` | Supported: `auto_home`. |
|
|
371
|
+
| `value (bool)` | True or False Value Supported. |
|
|
372
|
+
|
|
373
|
+
*Raises:*
|
|
374
|
+
| `Error` | If an unsupported parameter is provided. |
|
|
375
|
+
"""
|
|
376
|
+
if param == 'auto_home' and param in self.PROPERTIES:
|
|
377
|
+
self.auto_home = value
|
|
378
|
+
else:
|
|
379
|
+
raise Error(f"ArucoCapture Error: Unsupported parameter: {param}")
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "robotframework-parrot-touchcontroller"
|
|
7
|
-
version = "1.0.
|
|
7
|
+
version = "1.0.2"
|
|
8
8
|
description = "Touch control api to use within the Robot Framework ecosystem"
|
|
9
9
|
authors = [
|
|
10
10
|
{ name = "Zilogic Systems", email = "code@zilogic.com" },
|
|
@@ -13,9 +13,9 @@ requires-python = ">=3.6"
|
|
|
13
13
|
readme = "README.md"
|
|
14
14
|
license = "Apache-2.0"
|
|
15
15
|
dependencies = [
|
|
16
|
-
"robotframework",
|
|
17
|
-
"pyyaml",
|
|
18
|
-
"robotframework-parrot-adbcontroller"
|
|
16
|
+
"robotframework~=7.3.2",
|
|
17
|
+
"pyyaml~=6.0.2",
|
|
18
|
+
"robotframework-parrot-adbcontroller~=1.0.0"
|
|
19
19
|
]
|
|
20
20
|
|
|
21
21
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: robotframework-parrot-touchcontroller
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: Touch control api to use within the Robot Framework ecosystem
|
|
5
5
|
Author-email: Zilogic Systems <code@zilogic.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -9,9 +9,9 @@ Project-URL: Repository, https://github.com//zilogic-systems/parrot.git
|
|
|
9
9
|
Project-URL: Issues, https://github.com/zilogic-systems/parrot/issues
|
|
10
10
|
Requires-Python: >=3.6
|
|
11
11
|
Description-Content-Type: text/markdown
|
|
12
|
-
Requires-Dist: robotframework
|
|
13
|
-
Requires-Dist: pyyaml
|
|
14
|
-
Requires-Dist: robotframework-parrot-adbcontroller
|
|
12
|
+
Requires-Dist: robotframework~=7.3.2
|
|
13
|
+
Requires-Dist: pyyaml~=6.0.2
|
|
14
|
+
Requires-Dist: robotframework-parrot-adbcontroller~=1.0.0
|
|
15
15
|
|
|
16
16
|
# Touch Controller
|
|
17
17
|
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
from robot.api.deco import keyword
|
|
2
|
-
from parrot.touch.base import BaseTouch,Error
|
|
3
|
-
from typing import Tuple, Any
|
|
4
|
-
|
|
5
|
-
import xmlrpc.client
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class AxiTouchError(Exception):
|
|
9
|
-
"""Represents an error in the AxiDrawTouch controller."""
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class AxiDrawTouch(BaseTouch):
|
|
13
|
-
"""A touch controller implementation using the AxiDraw plotting device.
|
|
14
|
-
|
|
15
|
-
This class provides methods to simulate touch gestures such as tap and swipe
|
|
16
|
-
by controlling an AxiDraw plotter based on screen coordinates.
|
|
17
|
-
"""
|
|
18
|
-
|
|
19
|
-
PROPERTIES = ["auto_home"]
|
|
20
|
-
|
|
21
|
-
def __init__(self, config: dict[str, Any]) -> None:
|
|
22
|
-
"""Initializes the AxiDraw touch controller.
|
|
23
|
-
|
|
24
|
-
The configuration dictionary must contain:
|
|
25
|
-
- `width`: screen width in pixels
|
|
26
|
-
- `height`: screen height in pixels
|
|
27
|
-
- `start_pos`: tuple (x, y) of starting cartesian coordinates (in inches)
|
|
28
|
-
- `end_pos`: tuple (x, y) of ending cartesian coordinates (in inches)
|
|
29
|
-
|
|
30
|
-
Raises:
|
|
31
|
-
AxiTouchError: If initialization or connection to AxiDraw fails.
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
try:
|
|
35
|
-
uri = f"http://{config['host']}:{config['port']}"
|
|
36
|
-
self.screen_width_px: int = config["width"]
|
|
37
|
-
self.screen_height_px: int = config["height"]
|
|
38
|
-
self.cartesian_start: Tuple[float, float] = config["start_pos"]
|
|
39
|
-
self.cartesian_end: Tuple[float, float] = config["end_pos"]
|
|
40
|
-
|
|
41
|
-
self.auto_home = False # Flag to track auto-home behavior
|
|
42
|
-
|
|
43
|
-
# Optional: configure pen heights and speed
|
|
44
|
-
pen_pos_up = 75
|
|
45
|
-
pen_pos_down = 40
|
|
46
|
-
speed_pendown = 100
|
|
47
|
-
speed_penup = 100
|
|
48
|
-
accel = 75
|
|
49
|
-
|
|
50
|
-
self.axi = xmlrpc.client.ServerProxy(uri)
|
|
51
|
-
|
|
52
|
-
self.axi.connect(accel,
|
|
53
|
-
pen_pos_up, pen_pos_down,
|
|
54
|
-
speed_penup, speed_pendown)
|
|
55
|
-
|
|
56
|
-
except KeyError as err:
|
|
57
|
-
raise Error(f"Missing required configuration key: {err}") from err
|
|
58
|
-
except Exception as err:
|
|
59
|
-
raise Error(f"Initialization failed: {err}") from err
|
|
60
|
-
|
|
61
|
-
def convert_to_inches(self, x: float, y: float) -> Tuple[float, float]:
|
|
62
|
-
x = float(x)
|
|
63
|
-
y = float(y)
|
|
64
|
-
sx, sy = self.cartesian_start
|
|
65
|
-
ex, ey = self.cartesian_end
|
|
66
|
-
x_scale = (ex - sx) / self.screen_width_px
|
|
67
|
-
y_scale = (ey - sy) / self.screen_height_px
|
|
68
|
-
return round(sx + x * x_scale, 3), round(sy + y * y_scale, 3)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def touch_init(self) -> None:
|
|
72
|
-
"""Initialize the pen by lifting it up and moving to origin (0, 0).
|
|
73
|
-
|
|
74
|
-
Raises:
|
|
75
|
-
AxiTouchError: If initialization movement fails.
|
|
76
|
-
"""
|
|
77
|
-
|
|
78
|
-
try:
|
|
79
|
-
self.axi.penup()
|
|
80
|
-
self.axi.home()
|
|
81
|
-
print("AxiDrawTouch: Initialized and moved to origin")
|
|
82
|
-
except Exception as err:
|
|
83
|
-
raise Error("Initialization failed") from err
|
|
84
|
-
|
|
85
|
-
def touch_tap(self, x: float, y: float, tap_time) -> None:
|
|
86
|
-
"""Simulate a tap at the given screen coordinates.
|
|
87
|
-
|
|
88
|
-
Args:
|
|
89
|
-
x (int | float): X-coordinate in pixels.
|
|
90
|
-
y (int | float): Y-coordinate in pixels.
|
|
91
|
-
tap_time (float, optional): Duration to hold pen down. Defaults to 0.2s.
|
|
92
|
-
|
|
93
|
-
Raises:
|
|
94
|
-
AxiTouchError: If the tap operation fails.
|
|
95
|
-
"""
|
|
96
|
-
|
|
97
|
-
try:
|
|
98
|
-
px, py = self.convert_to_inches(x, y)
|
|
99
|
-
print(px, py)
|
|
100
|
-
self.axi.tap(px, py, tap_time)
|
|
101
|
-
if self.auto_home:
|
|
102
|
-
self.axi.home()
|
|
103
|
-
print(f"AxiDrawTouch: Tap at ({x}, {y}) for {tap_time}s")
|
|
104
|
-
except Exception as err:
|
|
105
|
-
raise Error(f"Touch tap failed at ({x}, {y})") from err
|
|
106
|
-
|
|
107
|
-
def touch_swipe(
|
|
108
|
-
self,
|
|
109
|
-
startx: float,
|
|
110
|
-
starty: float,
|
|
111
|
-
endx: float,
|
|
112
|
-
endy: float
|
|
113
|
-
) -> None:
|
|
114
|
-
"""Simulate a swipe gesture from start to end coordinates.
|
|
115
|
-
|
|
116
|
-
Args:
|
|
117
|
-
startx (int | float): Start X-coordinate in pixels.
|
|
118
|
-
starty (int | float): Start Y-coordinate in pixels.
|
|
119
|
-
endx (int | float): End X-coordinate in pixels.
|
|
120
|
-
endy (int | float): End Y-coordinate in pixels.
|
|
121
|
-
swipe_time (float, optional): Duration of the swipe. Defaults to 0.2s.
|
|
122
|
-
|
|
123
|
-
Raises:
|
|
124
|
-
AxiTouchError: If the swipe operation fails.
|
|
125
|
-
"""
|
|
126
|
-
|
|
127
|
-
try:
|
|
128
|
-
psx, psy = self.convert_to_inches(startx, starty)
|
|
129
|
-
pex, pey = self.convert_to_inches(endx, endy)
|
|
130
|
-
self.axi.swipe(psx, psy, pex, pey)
|
|
131
|
-
print(f"AxiDrawTouch: Swipe from ({startx}, {starty}) to ({endx}, {endy})")
|
|
132
|
-
except Exception as err:
|
|
133
|
-
raise Error(f"Swipe failed from ({startx}, {starty}) to ({endx}, {endy})") from err
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def move(self, x: float, y: float):
|
|
137
|
-
"""
|
|
138
|
-
Moving Axi arm to the absolute position in axi usable
|
|
139
|
-
area. where x and y are inches.
|
|
140
|
-
"""
|
|
141
|
-
try:
|
|
142
|
-
if x == 0 and y == 0:
|
|
143
|
-
self.axi.home()
|
|
144
|
-
return
|
|
145
|
-
self.axi.move(x, y)
|
|
146
|
-
except Exception as err:
|
|
147
|
-
raise Error(f"Failed to Move pointing device from ({x}, {y})") from err
|
|
148
|
-
|
|
149
|
-
def home(self):
|
|
150
|
-
"""Returns the touch to its home default position."""
|
|
151
|
-
try:
|
|
152
|
-
self.axi.home_with_limit_switch()
|
|
153
|
-
except Exception as err:
|
|
154
|
-
raise Error(f"Failed to Home pointing device") from err
|
|
155
|
-
|
|
156
|
-
def touch_command(self, cmd, *args):
|
|
157
|
-
"""Executes a backend-specific touch command on the given device controller."""
|
|
158
|
-
cmd = cmd.lower()
|
|
159
|
-
if cmd == "move":
|
|
160
|
-
if len(args) != 2:
|
|
161
|
-
raise Error("move command expects x and y as argument")
|
|
162
|
-
x = float(args[0])
|
|
163
|
-
y = float(args[1])
|
|
164
|
-
self.move(x, y)
|
|
165
|
-
elif cmd == "home":
|
|
166
|
-
self.home()
|
|
167
|
-
|
|
168
|
-
else:
|
|
169
|
-
raise Error(f"Invalid command {cmd}")
|
|
170
|
-
|
|
171
|
-
def set_param(self, param: str, value: bool) -> None:
|
|
172
|
-
"""
|
|
173
|
-
Set a runtime parameter for ArucoCapture.
|
|
174
|
-
|
|
175
|
-
| *Arguments* | *Description* |
|
|
176
|
-
| `param (str)` | Supported: `auto_home`. |
|
|
177
|
-
| `value (bool)` | True or False Value Supported. |
|
|
178
|
-
|
|
179
|
-
*Raises:*
|
|
180
|
-
| `Error` | If an unsupported parameter is provided. |
|
|
181
|
-
"""
|
|
182
|
-
if param == 'auto_home' and param in self.PROPERTIES:
|
|
183
|
-
self.auto_home = value
|
|
184
|
-
else:
|
|
185
|
-
raise Error(f"ArucoCapture Error: Unsupported parameter: {param}")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|