Add solution for Home Work 1 of Intelligent Robotics
Prompt: Make a program that makes the rosturtle in turtlesim run at velocity=v=0.5 m/s and turn with angular_velocity=ω=t/100 where t is time (in seconds); don't worry about the units too much.
This commit is contained in:
commit
96afe5b656
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
build/
|
||||
install/
|
||||
log/
|
11
LICENSE
Normal file
11
LICENSE
Normal file
@ -0,0 +1,11 @@
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
4
README.md
Normal file
4
README.md
Normal file
@ -0,0 +1,4 @@
|
||||
## Home Work 1
|
||||
Make a program that makes the rosturtle in turtlesim run at velocity=v=0.5 m/s and turn with angular_velocity=ω=t/100 where t is time (in seconds); don't worry about the units too much.
|
||||
|
||||
[Solution](ros2_turtlesim_shapes/publisher_member_function.py)
|
17
launch/turtlesim_draw.launch.py
Normal file
17
launch/turtlesim_draw.launch.py
Normal file
@ -0,0 +1,17 @@
|
||||
from launch import LaunchDescription
|
||||
from launch_ros.actions import Node
|
||||
|
||||
def generate_launch_description():
|
||||
return LaunchDescription([
|
||||
Node(
|
||||
package='turtlesim',
|
||||
executable='turtlesim_node'
|
||||
),
|
||||
Node(
|
||||
package='ros2_turtlesim_shapes',
|
||||
executable='talker',
|
||||
name='cmd_vel_publisher',
|
||||
output='screen'
|
||||
),
|
||||
|
||||
])
|
22
package.xml
Normal file
22
package.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?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>ros2_turtlesim_shapes</name>
|
||||
<version>0.0.0</version>
|
||||
<description>Simple package to draw an ellipse with ROS turtle.</description>
|
||||
<maintainer email="mail@diogo.site">Diogo Peralta Cordeiro</maintainer>
|
||||
<license>DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE</license>
|
||||
|
||||
<depend>rclpy</depend>
|
||||
<depend>std_msgs</depend>
|
||||
<exec_depend>ros2launch</exec_depend>
|
||||
|
||||
<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
resource/ros2_turtlesim_shapes
Normal file
0
resource/ros2_turtlesim_shapes
Normal file
0
ros2_turtlesim_shapes/__init__.py
Normal file
0
ros2_turtlesim_shapes/__init__.py
Normal file
70
ros2_turtlesim_shapes/publisher_member_function.py
Normal file
70
ros2_turtlesim_shapes/publisher_member_function.py
Normal file
@ -0,0 +1,70 @@
|
||||
import rclpy
|
||||
from rclpy.node import Node
|
||||
from geometry_msgs.msg import Twist
|
||||
|
||||
from turtlesim.srv import TeleportAbsolute
|
||||
from turtlesim.srv import SetPen
|
||||
|
||||
delta_t = 0.1
|
||||
v = 0.5
|
||||
t = 0
|
||||
|
||||
|
||||
def robot_angular_v(tt):
|
||||
return tt / 100
|
||||
|
||||
|
||||
def timed_callback():
|
||||
global t, node, pub
|
||||
t += delta_t
|
||||
|
||||
w = robot_angular_v(t)
|
||||
|
||||
msg = Twist()
|
||||
msg.linear.x = v
|
||||
msg.angular.z = w
|
||||
pub.publish(msg)
|
||||
|
||||
|
||||
def main(args=None):
|
||||
rclpy.init(args=args)
|
||||
global node, pub
|
||||
|
||||
node = Node('my_favourite_turtle')
|
||||
|
||||
cli = node.create_client(SetPen, "/turtle1/set_pen")
|
||||
req = SetPen.Request()
|
||||
req.off = True
|
||||
while not cli.wait_for_service(timeout_sec=1.0):
|
||||
node.get_logger().info('1: set_pen service not available, waiting again...')
|
||||
future = cli.call_async(req)
|
||||
rclpy.spin_until_future_complete(node, future)
|
||||
|
||||
cli = node.create_client(TeleportAbsolute, "/turtle1/teleport_absolute")
|
||||
req = TeleportAbsolute.Request()
|
||||
req.x = 0.0
|
||||
req.y = 0.0
|
||||
req.theta = 0.0
|
||||
while not cli.wait_for_service(timeout_sec=1.0):
|
||||
node.get_logger().info('2: teleport_absolute service not available, waiting again...')
|
||||
future = cli.call_async(req)
|
||||
rclpy.spin_until_future_complete(node, future)
|
||||
|
||||
cli = node.create_client(SetPen, "/turtle1/set_pen")
|
||||
req = SetPen.Request()
|
||||
req.off = False
|
||||
req.r = 255
|
||||
while not cli.wait_for_service(timeout_sec=1.0):
|
||||
node.get_logger().info('3: set_pen service not available, waiting again...')
|
||||
future = cli.call_async(req)
|
||||
rclpy.spin_until_future_complete(node, future)
|
||||
|
||||
pub = node.create_publisher(Twist, '/turtle1/cmd_vel', 10)
|
||||
node.create_timer(delta_t, timed_callback)
|
||||
|
||||
rclpy.spin(node)
|
||||
rclpy.shutdown()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
4
setup.cfg
Normal file
4
setup.cfg
Normal file
@ -0,0 +1,4 @@
|
||||
[develop]
|
||||
script_dir=$base/lib/ros2_turtlesim_shapes
|
||||
[install]
|
||||
install_scripts=$base/lib/ros2_turtlesim_shapes
|
29
setup.py
Normal file
29
setup.py
Normal file
@ -0,0 +1,29 @@
|
||||
from setuptools import setup
|
||||
import os
|
||||
from glob import glob
|
||||
|
||||
package_name = 'ros2_turtlesim_shapes'
|
||||
|
||||
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, 'launch'), glob('launch/*.py')),
|
||||
],
|
||||
install_requires=['setuptools'],
|
||||
zip_safe=True,
|
||||
maintainer='Diogo Peralta Cordeiro',
|
||||
maintainer_email='mail@diogo.site',
|
||||
description='Simple package to draw an ellipse with ROS turtle.',
|
||||
license='DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE',
|
||||
tests_require=['pytest'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'talker = ros2_turtlesim_shapes.publisher_member_function:main',
|
||||
],
|
||||
},
|
||||
)
|
25
test/test_copyright.py
Normal file
25
test/test_copyright.py
Normal file
@ -0,0 +1,25 @@
|
||||
# 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
|
||||
|
||||
|
||||
# Remove the `skip` decorator once the source file(s) have a copyright header
|
||||
@pytest.mark.skip(reason='No copyright header has been placed in the generated source file.')
|
||||
@pytest.mark.copyright
|
||||
@pytest.mark.linter
|
||||
def test_copyright():
|
||||
rc = main(argv=['.', 'test'])
|
||||
assert rc == 0, 'Found errors'
|
25
test/test_flake8.py
Normal file
25
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
test/test_pep257.py
Normal file
23
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'
|
Reference in New Issue
Block a user