Added joystick and platform packages
This commit is contained in:
parent
609b24c884
commit
c041ac26f0
18 changed files with 331 additions and 0 deletions
0
src/cobot_platform/cobot_platform/__init__.py
Normal file
0
src/cobot_platform/cobot_platform/__init__.py
Normal file
60
src/cobot_platform/cobot_platform/move.py
Normal file
60
src/cobot_platform/cobot_platform/move.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
import rclpy
|
||||
from rclpy.node import Node
|
||||
|
||||
from std_msgs.msg import Float32
|
||||
|
||||
from serial import Serial
|
||||
|
||||
from enum import Enum
|
||||
|
||||
class Servos(Enum):
|
||||
BODY = 0
|
||||
ARM = 1
|
||||
HAND = 2
|
||||
|
||||
class CobotMove(Node):
|
||||
def __init__(self):
|
||||
super().__init__('cobot_move')
|
||||
self._logger = self.get_logger()
|
||||
self._logger.info('COBOT init')
|
||||
|
||||
self._serial = Serial('/dev/ttyACM0', 115200)
|
||||
|
||||
# self._buf = [90, 90, 90] # 3 servos
|
||||
# self._prev_buf = [90, 90, 90]
|
||||
|
||||
base_topic = 'move/'
|
||||
|
||||
self.create_subscription(Float32, base_topic+'body', self._move_body_cb, rclpy.qos.qos_profile_sensor_data)
|
||||
self.create_subscription(Float32, base_topic+'arm', self._move_arm_cb, rclpy.qos.qos_profile_sensor_data)
|
||||
self.create_subscription(Float32, base_topic+'hand', self._move_hand_cb, rclpy.qos.qos_profile_sensor_data)
|
||||
|
||||
def _move_body_cb(self, msg):
|
||||
self._move_servo(Servos.BODY, msg.data)
|
||||
|
||||
def _move_arm_cb(self, msg):
|
||||
self._move_servo(Servos.ARM, msg.data)
|
||||
|
||||
def _move_hand_cb(self, msg):
|
||||
self._move_servo(Servos.HAND, msg.data)
|
||||
|
||||
def _move_servo(self, serv_num, pos):
|
||||
cmd = 'SV'
|
||||
# self._buf[serv_num] = pos
|
||||
self._logger.info('COBOT: Servo {serv_num} to {pos}')
|
||||
self._serial.write(f'{cmd}V{serv_num}P{pos}\n'.encode('UTF-8'))
|
||||
|
||||
# def _push ?
|
||||
|
||||
def main(args=None):
|
||||
rclpy.init(args=args)
|
||||
|
||||
cobot_move = CobotMove()
|
||||
rclpy.spin(cobot_move)
|
||||
|
||||
cobot_move.destroy_node()
|
||||
rclpy.shutdown()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
18
src/cobot_platform/package.xml
Normal file
18
src/cobot_platform/package.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?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>cobot_platform</name>
|
||||
<version>1.0.0</version>
|
||||
<description>Driver for the cobot platform</description>
|
||||
<maintainer email="farrell2017@my.fit.edu">John Farrell</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>
|
||||
|
||||
<export>
|
||||
<build_type>ament_python</build_type>
|
||||
</export>
|
||||
</package>
|
0
src/cobot_platform/resource/cobot_platform
Normal file
0
src/cobot_platform/resource/cobot_platform
Normal file
4
src/cobot_platform/setup.cfg
Normal file
4
src/cobot_platform/setup.cfg
Normal file
|
@ -0,0 +1,4 @@
|
|||
[develop]
|
||||
script-dir=$base/lib/cobot_platform
|
||||
[install]
|
||||
install-scripts=$base/lib/cobot_platform
|
26
src/cobot_platform/setup.py
Normal file
26
src/cobot_platform/setup.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from setuptools import setup
|
||||
|
||||
package_name = 'cobot_platform'
|
||||
|
||||
setup(
|
||||
name=package_name,
|
||||
version='1.0.0',
|
||||
packages=[package_name],
|
||||
data_files=[
|
||||
('share/ament_index/resource_index/packages',
|
||||
['resource/' + package_name]),
|
||||
('share/' + package_name, ['package.xml']),
|
||||
],
|
||||
install_requires=['setuptools'],
|
||||
zip_safe=True,
|
||||
maintainer='John Farrell',
|
||||
maintainer_email='farrell2017@my.fit.edu',
|
||||
description='Driver for the cobot platform',
|
||||
license='TODO: License declaration',
|
||||
tests_require=['pytest'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'move = cobot_platform.move:main'
|
||||
],
|
||||
},
|
||||
)
|
23
src/cobot_platform/test/test_copyright.py
Normal file
23
src/cobot_platform/test/test_copyright.py
Normal file
|
@ -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
src/cobot_platform/test/test_flake8.py
Normal file
25
src/cobot_platform/test/test_flake8.py
Normal file
|
@ -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
src/cobot_platform/test/test_pep257.py
Normal file
23
src/cobot_platform/test/test_pep257.py
Normal file
|
@ -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'
|
0
src/joystickmove/joystickmove/__init__.py
Normal file
0
src/joystickmove/joystickmove/__init__.py
Normal file
33
src/joystickmove/joystickmove/move.py
Normal file
33
src/joystickmove/joystickmove/move.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
import rclpy
|
||||
from rclpy.node import Node
|
||||
|
||||
from std_msgs.msg import Float32
|
||||
from sensor_msgs.msg import Joy
|
||||
|
||||
class JoyMove(Node):
|
||||
def __init__(self):
|
||||
super().__init__('joystickmove')
|
||||
self._logger = self.get_logger()
|
||||
self._logger.info('joystick init')
|
||||
|
||||
self.create_subscription(Joy, '/joy', self._joy_cb, rclpy.qos.qos_profile_sensor_data)
|
||||
|
||||
self.base_pub = self.create_publisher(Float32, '/move/body', 10)
|
||||
|
||||
def _joy_cb(self, msg):
|
||||
asd = (msg.axes[1] + 1) / 2 * 180.0
|
||||
self.base_pub.publish(Float32(data=asd))
|
||||
|
||||
|
||||
def main(args=None):
|
||||
rclpy.init(args=args)
|
||||
|
||||
joy_move = JoyMove()
|
||||
rclpy.spin(joy_move)
|
||||
|
||||
joy_move.destroy_node()
|
||||
rclpy.shutdown()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
18
src/joystickmove/package.xml
Normal file
18
src/joystickmove/package.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?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>joystickmove</name>
|
||||
<version>0.0.0</version>
|
||||
<description>Joystick memes</description>
|
||||
<maintainer email="farrell2017@my.fit.edu">John Farrell</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>
|
||||
|
||||
<export>
|
||||
<build_type>ament_python</build_type>
|
||||
</export>
|
||||
</package>
|
0
src/joystickmove/resource/joystickmove
Normal file
0
src/joystickmove/resource/joystickmove
Normal file
4
src/joystickmove/setup.cfg
Normal file
4
src/joystickmove/setup.cfg
Normal file
|
@ -0,0 +1,4 @@
|
|||
[develop]
|
||||
script-dir=$base/lib/joystickmove
|
||||
[install]
|
||||
install-scripts=$base/lib/joystickmove
|
26
src/joystickmove/setup.py
Normal file
26
src/joystickmove/setup.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from setuptools import setup
|
||||
|
||||
package_name = 'joystickmove'
|
||||
|
||||
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']),
|
||||
],
|
||||
install_requires=['setuptools'],
|
||||
zip_safe=True,
|
||||
maintainer='John Farrell',
|
||||
maintainer_email='farrell2017@my.fit.edu',
|
||||
description='Joystick memes',
|
||||
license='TODO: License declaration',
|
||||
tests_require=['pytest'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'joystickmove = joystickmove.move:main'
|
||||
],
|
||||
},
|
||||
)
|
23
src/joystickmove/test/test_copyright.py
Normal file
23
src/joystickmove/test/test_copyright.py
Normal file
|
@ -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
src/joystickmove/test/test_flake8.py
Normal file
25
src/joystickmove/test/test_flake8.py
Normal file
|
@ -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
src/joystickmove/test/test_pep257.py
Normal file
23
src/joystickmove/test/test_pep257.py
Normal file
|
@ -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'
|
Loading…
Reference in a new issue