Skip to content

Add initial control node #5

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
wbb-amd64:
container_name: wbb
image: cr.yandex/crp8hpfj5tuhlaodm4dl/wbb:0.1.0-amd64
platform: linux/x86_64
stdin_open: true
privileged: true
tty: true
Expand All @@ -17,11 +18,11 @@ services:
- "9090:9090"
volumes:
- "${PWD}:/wbb"
- "/dev:/dev"

wbb-arm64v8:
container_name: wbb
image: cr.yandex/crp8hpfj5tuhlaodm4dl/wbb:0.1.0-arm64v8
platform: linux/arm64/v8
stdin_open: true
privileged: true
tty: true
Expand All @@ -35,4 +36,4 @@ services:
- "9090:9090"
volumes:
- "${PWD}:/wbb"
- "/dev:/dev"
- "/dev:/dev"
3 changes: 3 additions & 0 deletions packages/joystick_proxy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Joystick proxy node

Run `ros2 run joy joy_node` to receive events from joystick
5 changes: 5 additions & 0 deletions packages/joystick_proxy/config/ipega.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
velocity_axis: 3
curvature_axis: 0
off_button: 0
remote_button: 1
auto_button: 4
5 changes: 5 additions & 0 deletions packages/joystick_proxy/config/ps4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
velocity_axis: 4
curvature_axis: 0
off_button: 0
remote_button: 1
auto_button: 2
5 changes: 5 additions & 0 deletions packages/joystick_proxy/config/ps5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
velocity_axis: 1
curvature_axis: 2
off_button: 0 # square
remote_button: 1 # X
auto_button: 2 # O
Empty file.
57 changes: 57 additions & 0 deletions packages/joystick_proxy/joystick_proxy/joystick.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import rclpy
from rclpy.node import Node
from yaml import load, Loader

from wbb_msgs.msg import Control, Eraser
from sensor_msgs.msg import Joy


class Joystick(Node):
def __init__(self):
super(Joystick, self).__init__('joystick')
self.sub = self.create_subscription(Joy, "/joy", self.handleJoystick, 10)
self.pub = self.create_publisher(Control, "/movement", 10)
self.eraser_pub = self.create_publisher(Eraser, "/eraser", 10)

# Path to the joy control map yaml file
self.declare_parameter('control_map', None)
self.declare_parameter('max_curvature', 2.0)
self.declare_parameter('min_velocity', 0.1)
self.btn_state = 0

self.max_curv = self.get_parameter('max_curvature').value
self.min_velocity = self.get_parameter('min_velocity').value
self.loadConfig()

def loadConfig(self):
with open(self.get_parameter('control_map').value, 'r') as f:
self.joy_map = load(f, Loader=Loader)

def handleJoystick(self, msg):
curv = msg.axes[self.joy_map["curvature_axis"]] * self.max_curv
vel = msg.axes[self.joy_map["velocity_axis"]]
if abs(vel) < self.min_velocity:
vel = 0.0 # stop

#self.get_logger().info('curv: %f; vel: %f' % (curv, vel))

control = Control()
control.curvature = curv
control.velocity = vel
self.pub.publish(control)

btn = msg.axes[self.joy_map["off_button"]]
if not btn == self.btn_state:
er = Eraser()
er.toggle = True
self.eraser_pub.publish(er)
self.btn_state = btn

def main():
rclpy.init()
joy = Joystick()
rclpy.spin(joy)
rclpy.shutdown()

if __name__ == '__main__':
main()
12 changes: 12 additions & 0 deletions packages/joystick_proxy/launch/joystick.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
launch:
- arg:
name: "control_name"
default: "ps4"
- node:
pkg: "joystick_proxy"
exec: "joystick"
name: "joystick"
param:
- {name: "control_map", value: "$(find-pkg-share joystick_proxy)/config/$(var control_name).yaml"}
- {name: "max_curvature", value: 40.0}
- {name: "min_velocity", value: 0.0}
23 changes: 23 additions & 0 deletions packages/joystick_proxy/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>joystick_proxy</name>
<version>0.0.0</version>
<description>Simple joystick proxy</description>
<maintainer email="[email protected]">enaix</maintainer>
<license>TODO: License declaration</license>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>
<depend>sensor_msgs</depend>
<depend>python3-yaml</depend>
<depend>wbb_msgs</depend>
<depend>rclpy</depend>
<exec_depend>joy</exec_depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
Empty file.
4 changes: 4 additions & 0 deletions packages/joystick_proxy/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/joystick_proxy
[install]
install_scripts=$base/lib/joystick_proxy
30 changes: 30 additions & 0 deletions packages/joystick_proxy/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from setuptools import setup
import os
from glob import glob

package_name = 'joystick_proxy'

setup(
name=package_name,
version='0.0.0',
packages=[package_name],
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join('share', package_name, 'config'), glob('config/*.yaml')),
('share/' + package_name, glob('launch/*.yaml')),
],
install_requires=['setuptools'],
zip_safe=True,
maintainer='enaix',
maintainer_email='[email protected]',
description='Simple joystick proxy node',
license='TODO: License declaration',
tests_require=['pytest'],
entry_points={
'console_scripts': [
'joystick = joystick_proxy.joystick:main'
],
},
)
23 changes: 23 additions & 0 deletions packages/joystick_proxy/test/test_copyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
Copy link
Member

@AndBondStyle AndBondStyle May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Все тесты можно выпилить, они бессмысленные (а еще это нужно сделать, чтобы PR менее мусорным стал)

#
# 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 ament_copyright.main import main
import pytest


@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found errors'
25 changes: 25 additions & 0 deletions packages/joystick_proxy/test/test_flake8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2017 Open Source Robotics Foundation, Inc.
#
# 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 ament_flake8.main import main_with_errors
import pytest


@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
rc, errors = main_with_errors(argv=[])
assert rc == 0, \
'Found %d code style errors / warnings:\n' % len(errors) + \
'\n'.join(errors)
23 changes: 23 additions & 0 deletions packages/joystick_proxy/test/test_pep257.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# 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 ament_pep257.main import main
import pytest


@pytest.mark.linter
@pytest.mark.pep257
def test_pep257():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found code style errors / warnings'
7 changes: 7 additions & 0 deletions packages/wbb_control/launch/control.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
launch:
- node:
pkg: "wbb_control"
exec: "control"
name: "control"
param:
- {name: "esp32_ip", value: "192.168.1.121"}
21 changes: 21 additions & 0 deletions packages/wbb_control/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>wbb_control</name>
<version>0.0.0</version>
<description>Whiteboard bot controller node</description>
<maintainer email="[email protected]">enaix</maintainer>
<license>TODO: License declaration</license>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>
<depend>wbb_msgs</depend>
<depend>python3-websockets</depend>
<exec_depend>rclpy</exec_depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
Empty file.
4 changes: 4 additions & 0 deletions packages/wbb_control/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[develop]
script_dir=$base/lib/wbb_control
[install]
install_scripts=$base/lib/wbb_control
28 changes: 28 additions & 0 deletions packages/wbb_control/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from setuptools import setup
from glob import glob

package_name = 'wbb_control'

setup(
name=package_name,
version='0.0.0',
packages=[package_name],
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
('share/' + package_name, glob('launch/*.yaml')),
],
install_requires=['setuptools', 'websockets'],
zip_safe=True,
maintainer='enaix',
maintainer_email='[email protected]',
description='Whiteboard bot control node',
license='TODO: License declaration',
tests_require=['pytest'],
entry_points={
'console_scripts': [
'control = wbb_control.control:main'
],
},
)
23 changes: 23 additions & 0 deletions packages/wbb_control/test/test_copyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# 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 ament_copyright.main import main
import pytest


@pytest.mark.copyright
@pytest.mark.linter
def test_copyright():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found errors'
25 changes: 25 additions & 0 deletions packages/wbb_control/test/test_flake8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2017 Open Source Robotics Foundation, Inc.
#
# 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 ament_flake8.main import main_with_errors
import pytest


@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
rc, errors = main_with_errors(argv=[])
assert rc == 0, \
'Found %d code style errors / warnings:\n' % len(errors) + \
'\n'.join(errors)
23 changes: 23 additions & 0 deletions packages/wbb_control/test/test_pep257.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2015 Open Source Robotics Foundation, Inc.
#
# 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 ament_pep257.main import main
import pytest


@pytest.mark.linter
@pytest.mark.pep257
def test_pep257():
rc = main(argv=['.', 'test'])
assert rc == 0, 'Found code style errors / warnings'
Empty file.
Loading