From 4d41485c4718d7fa53d1b23b54e5fe447bdd2a99 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 5 Jul 2023 11:36:16 +0200 Subject: [PATCH] working turtlebot3 sim --- src/dcaitirobot/dcaitirobot/twist.py | 8 +++- .../launch/remote_control_launch.py | 27 +++++++----- .../launch/start_turtle_slam_sim.py | 44 +++++++++++++++++++ 3 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 src/dcaitirobot/launch/start_turtle_slam_sim.py diff --git a/src/dcaitirobot/dcaitirobot/twist.py b/src/dcaitirobot/dcaitirobot/twist.py index fab6d26..5cbcbbb 100644 --- a/src/dcaitirobot/dcaitirobot/twist.py +++ b/src/dcaitirobot/dcaitirobot/twist.py @@ -41,6 +41,9 @@ class TwistPublisher(Node): self.publisher_ = self.create_publisher( Twist, "/diff_cont/cmd_vel_unstamped", 1 ) + + self.publisher_2 = self.create_publisher(Twist, "/cmd_vel", 1) + self.create_subscription(Joy, "/joy", self.joy_callback, 1) self.timer = self.create_timer(1 / publish_frequency_hz, self.timer_callback) @@ -67,9 +70,10 @@ class TwistPublisher(Node): self.update_smooth_window() self.calc_smooth_speed() - msg.linear.x = self.linear - msg.angular.z = self.angular + msg.linear.x = self.linear_out + msg.angular.z = self.angular_out self.publisher_.publish(msg) + self.publisher_2.publish(msg) self.get_logger().info( "Linear_window: {}, Linear_out: {}, Angular_window: {}, Angular_out: {}".format( self.linear_window, diff --git a/src/dcaitirobot/launch/remote_control_launch.py b/src/dcaitirobot/launch/remote_control_launch.py index 193078a..6a5af93 100644 --- a/src/dcaitirobot/launch/remote_control_launch.py +++ b/src/dcaitirobot/launch/remote_control_launch.py @@ -1,16 +1,19 @@ from launch import LaunchDescription from launch_ros.actions import Node + def generate_launch_description(): - return LaunchDescription([ - Node( - package='dcaitirobot', - executable='joy', - name='joystick', - ), - Node( - package='dcaitirobot', - executable='twistcalc', - name='twistcalc', - ) - ]) + return LaunchDescription( + [ + Node( + package="dcaitirobot", + executable="joy", + name="joystick", + ), + Node( + package="dcaitirobot", + executable="twistcalc", + name="twistcalc", + ), + ] + ) diff --git a/src/dcaitirobot/launch/start_turtle_slam_sim.py b/src/dcaitirobot/launch/start_turtle_slam_sim.py new file mode 100644 index 0000000..3a2804f --- /dev/null +++ b/src/dcaitirobot/launch/start_turtle_slam_sim.py @@ -0,0 +1,44 @@ +from pathlib import Path + +from launch import LaunchDescription +from launch.actions import IncludeLaunchDescription +from launch.launch_description_sources import PythonLaunchDescriptionSource +from launch_ros.actions import Node +from ament_index_python import get_package_share_directory + + +def generate_launch_description(): + return LaunchDescription( + [ + IncludeLaunchDescription( + PythonLaunchDescriptionSource( + str(Path(__file__).parent.absolute() / "remote_control_launch.py") + ) + ), + IncludeLaunchDescription( + PythonLaunchDescriptionSource( + str( + ( + Path( + get_package_share_directory("turtlebot3_gazebo") + ).absolute() + / "launch" + / "turtlebot3_world.launch.py" + ) + ) + ) + ), + IncludeLaunchDescription( + PythonLaunchDescriptionSource( + str( + ( + Path(get_package_share_directory("slam_toolbox")).absolute() + / "launch" + / "online_async_launch.py" + ) + ) + ), + launch_arguments=[("use_sim_time", "True")], + ), + ] + )