Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Python API #3801

Closed
wants to merge 111 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
d3c9db8
Skeleton for the new Python API
omichel Oct 20, 2021
766ca65
Update mybot_simple.py
omichel Oct 20, 2021
a14547a
Update webots.py
omichel Oct 20, 2021
25972fd
Merge branch 'develop' into feature-new-python-api
omichel Oct 20, 2021
6dd49e8
Added a mechanism to export constants from C to other languages
omichel Oct 20, 2021
afb4bf5
Fixed test
omichel Oct 20, 2021
753d4b5
Moved webots.py to a better location
omichel Oct 20, 2021
06d2456
Added a helper function for retrieving constants
omichel Oct 21, 2021
e601580
simplified
omichel Oct 21, 2021
5939b73
File _WB.py assigns values for all WB_CONSTANTS
Justin-Fisher Oct 21, 2021
e2f393d
Update webots.py
Justin-Fisher Oct 21, 2021
94d54c5
added _WB_ prefix to constant names
Justin-Fisher Oct 21, 2021
8001f77
Changed import to handle _WB_ prefixes
Justin-Fisher Oct 21, 2021
e2aa157
Rename _WB.py to WB_CONTSTANTS.py
Justin-Fisher Oct 21, 2021
da6a978
changed name of import to WB_CONSTANTS
Justin-Fisher Oct 21, 2021
9b191a1
Fixed typo
omichel Oct 22, 2021
91a29d7
Merge branch 'develop' into feature-new-python-api
omichel Oct 25, 2021
60d4cad
Working driver supervisor example with new Python API
omichel Oct 26, 2021
937bdfd
Merge branch 'develop' into feature-new-python-api
omichel Oct 26, 2021
1e521f1
Set sensor.samplingPeriod to None to disable it
omichel Oct 26, 2021
44713e3
Merge branch 'feature-new-python-api' of https://github.com/cyberboti…
omichel Oct 26, 2021
663d54b
Working slave.py example
omichel Oct 27, 2021
85343cc
split module into multiple files
omichel Oct 27, 2021
f417c3d
Added license
omichel Oct 27, 2021
28c9e3c
Better naming for tag
omichel Oct 27, 2021
5ea2a7d
Removed useless argtypes/restype
omichel Oct 27, 2021
e30be2f
Merge remote-tracking branch 'origin/develop' into feature-new-python…
omichel Oct 28, 2021
2700750
moved restype and argtypes assignments in the class definition, close…
omichel Oct 28, 2021
b368065
Fixed Node.typeName
omichel Oct 28, 2021
821cbff
Use Linux line endings
omichel Oct 28, 2021
4e651ab
Fixed missing emitter argtypes in Emitter class
omichel Oct 28, 2021
2bb981a
simplified
omichel Oct 28, 2021
fc4572e
simplified
omichel Oct 28, 2021
d776525
Support more field operations
omichel Oct 28, 2021
78486d6
Merge remote-tracking branch 'origin/develop' into feature-new-python…
omichel Nov 3, 2021
92b9364
swiched API to PEP8 snake case
omichel Nov 3, 2021
d64b8f3
Merge branch 'develop' into feature-new-python-api
omichel Dec 2, 2021
0d628ee
Merge branch 'develop' into feature-new-python-api
omichel Dec 20, 2021
7cf4c63
ENU fix
omichel Dec 20, 2021
62cdeb7
Merge branch 'develop' into feature-new-python-api
omichel Dec 31, 2021
eeb396d
Update ansi_codes.c
omichel Dec 31, 2021
f275aa0
Update __init__.py
omichel Dec 31, 2021
7c2d657
Update ansi_codes.py
omichel Dec 31, 2021
dffffbc
Update WB_CONSTANTS.py
omichel Dec 31, 2021
6a860ad
Update camera.py
omichel Dec 31, 2021
153a46e
Update constants.py
omichel Dec 31, 2021
dcdab98
Update distance_sensor.py
omichel Dec 31, 2021
4e4a76e
Update emitter.py
omichel Dec 31, 2021
5066bc9
Update field.py
omichel Dec 31, 2021
29b3e88
Update keyboard.py
omichel Dec 31, 2021
116f460
Update motor.py
omichel Dec 31, 2021
a0888b0
Update node.py
omichel Dec 31, 2021
e98d5fa
Update receiver.py
omichel Dec 31, 2021
d3f83ed
Update wb.py
omichel Dec 31, 2021
4e37957
Update mybot_simple.py
omichel Dec 31, 2021
7be1b44
Update robot.py
omichel Dec 31, 2021
2520999
Update sensor.py
omichel Dec 31, 2021
1d62571
Update supervisor.py
omichel Dec 31, 2021
c15ec5c
Merge branch 'develop' into feature-new-python-api
omichel Jan 10, 2022
69e0116
Merge branch 'develop' into feature-new-python-api
omichel Jan 11, 2022
f287af1
Merge branch 'develop' into feature-new-python-api
omichel Jan 17, 2022
1ef3d8a
Merge branch 'develop' into feature-new-python-api
omichel Jan 23, 2022
4514b57
Merge branch 'develop' into feature-new-python-api
omichel Jan 31, 2022
e5c238e
Merge branch 'develop' into feature-new-python-api
omichel Feb 7, 2022
ff76565
Fixed line endings
omichel Feb 7, 2022
ba13adf
Fixed line endings
omichel Feb 7, 2022
c579248
Merge branch 'develop' into feature-new-python-api
omichel Feb 7, 2022
0f03202
Merge branch 'develop' into feature-new-python-api
omichel Feb 7, 2022
16f880f
Merge branch 'develop' into feature-new-python-api
omichel Feb 14, 2022
df5d8fd
Merge branch 'develop' into feature-new-python-api
omichel Feb 14, 2022
b72e01f
Merge branch 'develop' into feature-new-python-api
omichel Feb 15, 2022
6e0f14b
Merge branch 'develop' into feature-new-python-api
omichel Feb 15, 2022
80189c1
Merge branch 'develop' into feature-new-python-api
omichel Feb 15, 2022
98ba2c4
Merge branch 'develop' into feature-new-python-api
omichel Feb 21, 2022
1a60944
Merge branch 'develop' into feature-new-python-api
omichel Feb 21, 2022
f610e31
Merge branch 'develop' into feature-new-python-api
omichel Feb 24, 2022
a10f6cb
Merge branch 'develop' into feature-new-python-api
omichel Feb 28, 2022
7f603b8
Merge branch 'develop' into feature-new-python-api
omichel Mar 1, 2022
3a0a57e
Merge branch 'develop' into feature-new-python-api
omichel Mar 1, 2022
70ba4fb
Merge branch 'develop' into feature-new-python-api
omichel Mar 1, 2022
795d30e
Merge branch 'develop' into feature-new-python-api
omichel Mar 2, 2022
9dd68fb
Merge branch 'develop' into feature-new-python-api
omichel Mar 2, 2022
3d78a31
Merge branch 'develop' into feature-new-python-api
omichel Mar 3, 2022
3501059
Merge branch 'develop' into feature-new-python-api
omichel Mar 7, 2022
9d3facb
Merge branch 'develop' into feature-new-python-api
omichel Mar 14, 2022
d8d9d8f
Merge branch 'develop' into feature-new-python-api
omichel Mar 15, 2022
a16a51a
Merge branch 'develop' into feature-new-python-api
omichel Mar 16, 2022
667aaf7
Merge branch 'develop' into feature-new-python-api
omichel Mar 17, 2022
5650b4b
Merge branch 'develop' into feature-new-python-api
omichel Mar 25, 2022
2d8f466
Merge branch 'develop' into feature-new-python-api
omichel Mar 28, 2022
ad26671
Merge branch 'develop' into feature-new-python-api
omichel Mar 30, 2022
e509511
Merge branch 'develop' into feature-new-python-api
omichel Mar 30, 2022
82acf80
Merge branch 'develop' into feature-new-python-api
omichel Mar 31, 2022
0c06ef8
Merge branch 'develop' into feature-new-python-api
omichel Apr 1, 2022
e1e63ce
Merge branch 'develop' into feature-new-python-api
omichel Apr 4, 2022
74966fa
Merge branch 'develop' into feature-new-python-api
omichel Apr 5, 2022
2645740
Merge branch 'develop' into feature-new-python-api
omichel Apr 13, 2022
d6d3c36
Merge branch 'develop' into feature-new-python-api
omichel Apr 16, 2022
aab15d7
Merge branch 'develop' into feature-new-python-api
omichel Apr 21, 2022
c0d6e8d
Merge branch 'develop' into feature-new-python-api
omichel Apr 27, 2022
f8e8305
Merge branch 'develop' into feature-new-python-api
omichel Apr 28, 2022
8562375
Merge branch 'develop' into feature-new-python-api
omichel May 2, 2022
4def580
Merge branch 'develop' into feature-new-python-api
omichel May 3, 2022
7108112
Merge branch 'develop' into feature-new-python-api
omichel May 5, 2022
a01fc04
Merge branch 'develop' into feature-new-python-api
omichel May 9, 2022
f1f6959
Merge branch 'develop' into feature-new-python-api
omichel May 13, 2022
9c5258b
Merge branch 'develop' into feature-new-python-api
omichel May 25, 2022
129a931
Merge branch 'develop' into feature-new-python-api
omichel Jun 13, 2022
1be1090
Merge branch 'develop' into feature-new-python-api
omichel Jun 13, 2022
5756c6c
Merge branch 'develop' into feature-new-python-api
omichel Sep 15, 2022
377c60b
Merge branch 'develop' into feature-new-python-api
omichel Oct 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions lib/controller/python/WB_CONSTANTS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Webots constants without WB_prefixes

_WB_STDOUT=0
_WB_STDERR=1
_WB_CHANNEL_BROADCAST=-1
_WB_IMAGE_RGB=3
_WB_IMAGE_RGBA=4
_WB_IMAGE_ARGB=5
_WB_IMAGE_BGRA=6
_WB_IMAGE_ABGR=7
_WB_KEYBOARD_KEY=65535
_WB_KEYBOARD_SHIFT=65536
_WB_KEYBOARD_CONTROL=131072
_WB_KEYBOARD_ALT=262144
_WB_KEYBOARD_LEFT=314
_WB_KEYBOARD_UP=315
_WB_KEYBOARD_RIGHT=316
_WB_KEYBOARD_DOWN=317
_WB_KEYBOARD_PAGEUP=366
_WB_KEYBOARD_PAGEDOWN=367
_WB_KEYBOARD_HOME=313
_WB_KEYBOARD_END=312
_WB_KEYBOARD_NUMPAD_UP=377
_WB_KEYBOARD_NUMPAD_DOWN=379
_WB_KEYBOARD_NUMPAD_LEFT=376
_WB_KEYBOARD_NUMPAD_RIGHT=378
_WB_KEYBOARD_NUMPAD_HOME=375
_WB_KEYBOARD_NUMPAD_END=382
_WB_NO_FIELD=0
_WB_SF_BOOL=1
_WB_SF_INT32=2
_WB_SF_FLOAT=3
_WB_SF_VEC2F=4
_WB_SF_VEC3F=5
_WB_SF_ROTATION=6
_WB_SF_COLOR=7
_WB_SF_STRING=8
_WB_SF_NODE=9
_WB_MF=16
_WB_MF_BOOL=17
_WB_MF_INT32=18
_WB_MF_FLOAT=19
_WB_MF_VEC2F=20
_WB_MF_VEC3F=21
_WB_MF_ROTATION=22
_WB_MF_COLOR=23
_WB_MF_STRING=24
_WB_MF_NODE=25
_WB_EVENT_QUIT=-1
_WB_EVENT_NO_EVENT=0
_WB_EVENT_MOUSE_CLICK=1
_WB_EVENT_MOUSE_MOVE=2
_WB_EVENT_KEYBOARD=4
_WB_EVENT_JOYSTICK_BUTTON=8
_WB_EVENT_JOYSTICK_AXIS=16
_WB_EVENT_JOYSTICK_POV=32
_WB_DISTANCE_SENSOR_GENERIC=0
_WB_DISTANCE_SENSOR_INFRA_RED=1
_WB_DISTANCE_SENSOR_SONAR=2
_WB_DISTANCE_SENSOR_LASER=3
_WB_GPS_LOCAL_COORDINATE=0
_WB_GPS_WGS84_COORDINATE=1
_WB_MODE_SIMULATION=0
_WB_MODE_CROSS_COMPILATION=1
_WB_MODE_REMOTE_CONTROL=2
_WB_NODE_NO_NODE=0
_WB_NODE_APPEARANCE=1
_WB_NODE_BACKGROUND=2
_WB_NODE_BILLBOARD=3
_WB_NODE_BOX=4
_WB_NODE_CAPSULE=5
_WB_NODE_COLOR=6
_WB_NODE_CONE=7
_WB_NODE_COORDINATE=8
_WB_NODE_CYLINDER=9
_WB_NODE_DIRECTIONAL_LIGHT=10
_WB_NODE_ELEVATION_GRID=11
_WB_NODE_FOG=12
_WB_NODE_GROUP=13
_WB_NODE_IMAGE_TEXTURE=14
_WB_NODE_INDEXED_FACE_SET=15
_WB_NODE_INDEXED_LINE_SET=16
_WB_NODE_MATERIAL=17
_WB_NODE_MESH=18
_WB_NODE_MUSCLE=19
_WB_NODE_NORMAL=20
_WB_NODE_PBR_APPEARANCE=21
_WB_NODE_PLANE=22
_WB_NODE_POINT_LIGHT=23
_WB_NODE_POINT_SET=24
_WB_NODE_SHAPE=25
_WB_NODE_SPHERE=26
_WB_NODE_SPOT_LIGHT=27
_WB_NODE_TEXTURE_COORDINATE=28
_WB_NODE_TEXTURE_TRANSFORM=29
_WB_NODE_TRANSFORM=30
_WB_NODE_VIEWPOINT=31
_WB_NODE_ROBOT=32
_WB_NODE_ACCELEROMETER=33
_WB_NODE_ALTIMETER=34
_WB_NODE_BRAKE=35
_WB_NODE_CAMERA=36
_WB_NODE_COMPASS=37
_WB_NODE_CONNECTOR=38
_WB_NODE_DISPLAY=39
_WB_NODE_DISTANCE_SENSOR=40
_WB_NODE_EMITTER=41
_WB_NODE_GPS=42
_WB_NODE_GYRO=43
_WB_NODE_INERTIAL_UNIT=44
_WB_NODE_LED=45
_WB_NODE_LIDAR=46
_WB_NODE_LIGHT_SENSOR=47
_WB_NODE_LINEAR_MOTOR=48
_WB_NODE_PEN=49
_WB_NODE_POSITION_SENSOR=50
_WB_NODE_PROPELLER=51
_WB_NODE_RADAR=52
_WB_NODE_RANGE_FINDER=53
_WB_NODE_RECEIVER=54
_WB_NODE_ROTATIONAL_MOTOR=55
_WB_NODE_SPEAKER=56
_WB_NODE_TOUCH_SENSOR=57
_WB_NODE_BALL_JOINT=58
_WB_NODE_BALL_JOINT_PARAMETERS=59
_WB_NODE_CHARGER=60
_WB_NODE_CONTACT_PROPERTIES=61
_WB_NODE_DAMPING=62
_WB_NODE_FLUID=63
_WB_NODE_FOCUS=64
_WB_NODE_HINGE_JOINT=65
_WB_NODE_HINGE_JOINT_PARAMETERS=66
_WB_NODE_HINGE_2_JOINT=67
_WB_NODE_IMMERSION_PROPERTIES=68
_WB_NODE_JOINT_PARAMETERS=69
_WB_NODE_LENS=70
_WB_NODE_LENS_FLARE=71
_WB_NODE_PHYSICS=72
_WB_NODE_RECOGNITION=73
_WB_NODE_SLIDER_JOINT=74
_WB_NODE_SLOT=75
_WB_NODE_SOLID=76
_WB_NODE_SOLID_REFERENCE=77
_WB_NODE_TRACK=78
_WB_NODE_TRACK_WHEEL=79
_WB_NODE_WORLD_INFO=80
_WB_NODE_ZOOM=81
_WB_NODE_MICROPHONE=82
_WB_NODE_RADIO=83
_WB_NODE_SKIN=84
_WB_SUPERVISOR_SIMULATION_MODE_PAUSE=0
_WB_SUPERVISOR_SIMULATION_MODE_REAL_TIME=1
_WB_SUPERVISOR_SIMULATION_MODE_FAST=2
_WB_ROTATIONAL=0
_WB_LINEAR=1
_WB_TOUCH_SENSOR_BUMPER=0
_WB_TOUCH_SENSOR_FORCE=1
_WB_TOUCH_SENSOR_FORCE3D=2
25 changes: 25 additions & 0 deletions lib/controller/python/webots/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 1996-2022 Cyberbotics Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from webots.ansi_codes import AnsiCodes # noqa
from webots.camera import Camera # noqa
from webots.distance_sensor import DistanceSensor # noqa
from webots.emitter import Emitter # noqa
from webots.field import Field # noqa
from webots.keyboard import Keyboard # noqa
from webots.motor import Motor # noqa
from webots.node import Node # noqa
from webots.receiver import Receiver # noqa
from webots.robot import Robot # noqa
from webots.supervisor import Supervisor # noqa
38 changes: 38 additions & 0 deletions lib/controller/python/webots/ansi_codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 1996-2022 Cyberbotics Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from webots.constants import constant


class AnsiCodes:
RESET = constant('ANSI_RESET', type=str)
BOLD = constant('ANSI_BOLD', type=str)
UNDERLINE = constant('ANSI_UNDERLINE', type=str)
BLACK_BACKGROUND = constant('ANSI_BLACK_BACKGROUND', type=str)
RED_BACKGROUND = constant('ANSI_RED_BACKGROUND', type=str)
GREEN_BACKGROUND = constant('ANSI_GREEN_BACKGROUND', type=str)
YELLOW_BACKGROUND = constant('ANSI_YELLOW_BACKGROUND', type=str)
BLUE_BACKGROUND = constant('ANSI_BLUE_BACKGROUND', type=str)
MAGENTA_BACKGROUND = constant('ANSI_MAGENTA_BACKGROUND', type=str)
CYAN_BACKGROUND = constant('ANSI_CYAN_BACKGROUND', type=str)
WHITE_BACKGROUND = constant('ANSI_WHITE_BACKGROUND', type=str)
BLACK_FOREGROUND = constant('ANSI_BLACK_FOREGROUND', type=str)
RED_FOREGROUND = constant('ANSI_RED_FOREGROUND', type=str)
GREEN_FOREGROUND = constant('ANSI_GREEN_FOREGROUND', type=str)
YELLOW_FOREGROUND = constant('ANSI_YELLOW_FOREGROUND', type=str)
BLUE_FOREGROUND = constant('ANSI_BLUE_FOREGROUND', type=str)
MAGENTA_FOREGROUND = constant('ANSI_MAGENTA_FOREGROUND', type=str)
CYAN_FOREGROUND = constant('ANSI_CYAN_FOREGROUND', type=str)
WHITE_FOREGROUND = constant('ANSI_WHITE_FOREGROUND', type=str)
CLEAR_SCREEN = constant('ANSI_CLEAR_SCREEN', type=str)
23 changes: 23 additions & 0 deletions lib/controller/python/webots/camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 1996-2022 Cyberbotics Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from webots.sensor import Sensor
from webots.wb import wb


class Camera(Sensor):
def __init__(self, name: str, sampling_period: int = None):
self._enable = wb.wb_camera_enable
self._get_sampling_period = wb.wb_camera_get_sampling_period
super().__init__(name, sampling_period)
23 changes: 23 additions & 0 deletions lib/controller/python/webots/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 1996-2022 Cyberbotics Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import ctypes
from webots.wb import wb


def constant(name, type=int):
if type == int:
return ctypes.c_int.in_dll(wb, 'wb_' + name).value
if type == str:
return ctypes.c_char_p.in_dll(wb, 'wb_' + name).value.decode()
30 changes: 30 additions & 0 deletions lib/controller/python/webots/distance_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 1996-2022 Cyberbotics Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import ctypes
from webots.wb import wb
from webots.sensor import Sensor


class DistanceSensor(Sensor):
def __init__(self, name: str, sampling_period: int = None):
self._enable = wb.wb_distance_sensor_enable
self._get_sampling_period = wb.wb_distance_sensor_get_sampling_period
super().__init__(name, sampling_period)

wb.wb_distance_sensor_get_value.restype = ctypes.c_double

@property
def value(self) -> float:
return wb.wb_distance_sensor_get_value(self._tag)
33 changes: 33 additions & 0 deletions lib/controller/python/webots/emitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 1996-2022 Cyberbotics Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import typing
from webots.wb import wb


class Emitter:
def __init__(self, name: str):
self._tag = wb.wb_robot_get_device(str.encode(name))

def send(self, message: typing.Union[str, bytes], length: int = None):
if isinstance(message, str):
wb.wb_emitter_send(self._tag, str.encode(message), len(message) + 1)
elif isinstance(message, bytes):
if length is None:
print('Emitter.send(): missing byte buffer length', file=sys.stderr)
else:
wb.wb_emitter_send(self._tag, message, length)
else:
print('Emitter.send(): unsupported data type', file=sys.stderr)
Loading