Skip to content
Closed

TEST_ #233

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
45 changes: 21 additions & 24 deletions turtlebot3_gazebo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ endif()
# Find ament packages and libraries for ament and system dependencies
################################################################################
find_package(ament_cmake REQUIRED)
find_package(ros_gz_sim REQUIRED)
find_package(gz-sim8 REQUIRED)
find_package(gz-plugin2 REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(rclcpp REQUIRED)
Expand All @@ -40,37 +41,33 @@ include_directories(
)

set(dependencies
"geometry_msgs"
"nav_msgs"
"rclcpp"
"sensor_msgs"
"tf2"
geometry_msgs
nav_msgs
rclcpp
sensor_msgs
tf2
)

set(EXEC_NAME "turtlebot3_drive")
add_executable(turtlebot3_drive src/turtlebot3_drive.cpp)
ament_target_dependencies(turtlebot3_drive ${dependencies})

add_executable(${EXEC_NAME} src/turtlebot3_drive.cpp)
ament_target_dependencies(${EXEC_NAME} ${dependencies})
add_library(obstacles SHARED src/obstacles.cpp)
ament_target_dependencies(obstacles gz-sim8 gz-plugin2)

# add_library(traffic_light_plugin SHARED src/traffic_light_plugin.cpp)
# target_link_libraries(traffic_light_plugin ${GAZEBO_LIBRARIES})
add_library(obstacle1 SHARED src/obstacle1.cpp)
ament_target_dependencies(obstacle1 gz-sim8 gz-plugin2)

# add_library(traffic_bar_plugin SHARED src/traffic_bar_plugin.cpp)
# target_link_libraries(traffic_bar_plugin ${GAZEBO_LIBRARIES})

# add_library(obstacle1 SHARED src/obstacle1.cpp)
# target_link_libraries(obstacle1 ${GAZEBO_LIBRARIES})

# add_library(obstacle2 SHARED src/obstacle2.cpp)
# target_link_libraries(obstacle2 ${GAZEBO_LIBRARIES})

# add_library(obstacles SHARED src/obstacles.cpp)
# target_link_libraries(obstacles ${GAZEBO_LIBRARIES})
add_library(obstacle2 SHARED src/obstacle2.cpp)
ament_target_dependencies(obstacle2 gz-sim8 gz-plugin2)

################################################################################
# Install
################################################################################
install(TARGETS ${EXEC_NAME}
install(TARGETS
turtlebot3_drive
obstacles
obstacle1
obstacle2
DESTINATION lib/${PROJECT_NAME}
)

Expand All @@ -86,7 +83,7 @@ install(DIRECTORY include/
# Macro for ament package
################################################################################
ament_export_include_directories(include)
ament_export_dependencies(gazebo_ros_pkgs)
ament_export_dependencies(gz-sim8)
ament_export_dependencies(geometry_msgs)
ament_export_dependencies(nav_msgs)
ament_export_dependencies(rclcpp)
Expand Down
67 changes: 35 additions & 32 deletions turtlebot3_gazebo/include/turtlebot3_gazebo/obstacle1.hpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
// Copyright 2012 Open Source Robotics Foundation
//
// 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.
//
// Author: Ryan Shim

#ifndef TURTLEBOT3_GAZEBO__OBSTACLE1_HPP_
#define TURTLEBOT3_GAZEBO__OBSTACLE1_HPP_

#include <ignition/math.hh>
#include <gazebo/common/common.hh>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>

namespace gazebo
#ifndef TURTLEBOT3_GAZEBO_OBSTACLE1_PLUGIN_HPP
#define TURTLEBOT3_GAZEBO_OBSTACLE1_PLUGIN_HPP

#include <gz/sim/System.hh>
#include <gz/sim/Model.hh>
#include <gz/sim/EntityComponentManager.hh>
#include <gz/sim/components/Pose.hh>
#include <gz/math/Vector3.hh>
#include <gz/math/Quaternion.hh>
#include <chrono>

namespace turtlebot3_gazebo
{
class Obstacle1 : public ModelPlugin

class Obstacle1Plugin
: public gz::sim::System,
public gz::sim::ISystemConfigure,
public gz::sim::ISystemPreUpdate
{
public:
void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/) override;
Obstacle1Plugin() = default;
~Obstacle1Plugin() override = default;

void Configure(
const gz::sim::Entity &entity,
const std::shared_ptr<const sdf::Element> &sdf,
gz::sim::EntityComponentManager &ecm,
gz::sim::EventManager &eventMgr) override;

void PreUpdate(
const gz::sim::UpdateInfo &info,
gz::sim::EntityComponentManager &ecm) override;

private:
physics::ModelPtr model;
event::ConnectionPtr updateConnection;
gz::sim::Model model{gz::sim::kNullEntity};
std::chrono::steady_clock::time_point startTime;
};
GZ_REGISTER_MODEL_PLUGIN(Obstacle1);
} // namespace gazebo
#endif // TURTLEBOT3_GAZEBO__OBSTACLE1_HPP_

} // namespace turtlebot3_gazebo

#endif // TURTLEBOT3_GAZEBO_OBSTACLE1_PLUGIN_HPP
68 changes: 35 additions & 33 deletions turtlebot3_gazebo/include/turtlebot3_gazebo/obstacle2.hpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
// Copyright 2012 Open Source Robotics Foundation
//
// 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.
//
// Author: Ryan Shim

#ifndef TURTLEBOT3_GAZEBO__OBSTACLE2_HPP_
#define TURTLEBOT3_GAZEBO__OBSTACLE2_HPP_

#include <ignition/math.hh>
#include <gazebo/common/common.hh>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>

namespace gazebo
#ifndef TURTLEBOT3_GAZEBO_OBSTACLE2_PLUGIN_HPP
#define TURTLEBOT3_GAZEBO_OBSTACLE2_PLUGIN_HPP

#include <gz/sim/System.hh>
#include <gz/sim/Model.hh>
#include <gz/sim/EntityComponentManager.hh>
#include <gz/sim/components/Pose.hh>
#include <gz/math/Vector3.hh>
#include <gz/math/Quaternion.hh>
#include <chrono>

namespace turtlebot3_gazebo
{
class Obstacle2 : public ModelPlugin

class Obstacle2Plugin
: public gz::sim::System,
public gz::sim::ISystemConfigure,
public gz::sim::ISystemPreUpdate
{
public:
Obstacle2() = default;
void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/) override;
Obstacle1Plugin() = default;
~Obstacle1Plugin() override = default;

void Configure(
const gz::sim::Entity &entity,
const std::shared_ptr<const sdf::Element> &sdf,
gz::sim::EntityComponentManager &ecm,
gz::sim::EventManager &eventMgr) override;

void PreUpdate(
const gz::sim::UpdateInfo &info,
gz::sim::EntityComponentManager &ecm) override;

private:
physics::ModelPtr model;
event::ConnectionPtr updateConnection;
gz::sim::Model model{gz::sim::kNullEntity};
std::chrono::steady_clock::time_point startTime;
};
GZ_REGISTER_MODEL_PLUGIN(Obstacle2);
} // namespace gazebo
#endif // TURTLEBOT3_GAZEBO__OBSTACLE2_HPP_

} // namespace turtlebot3_gazebo

#endif // TURTLEBOT3_GAZEBO_OBSTACLE2_PLUGIN_HPP
43 changes: 29 additions & 14 deletions turtlebot3_gazebo/include/turtlebot3_gazebo/obstacles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,40 @@
#ifndef TURTLEBOT3_GAZEBO__OBSTACLES_HPP_
#define TURTLEBOT3_GAZEBO__OBSTACLES_HPP_

#include <ignition/math.hh>
#include <gazebo/common/common.hh>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gz/sim/System.hh>
#include <gz/sim/Model.hh>
#include <gz/sim/EntityComponentManager.hh>
#include <gz/sim/components/WorldPose.hh>
#include <gz/plugin/Register.hh>
#include <gz/math/Pose3.hh>
#include <gz/math/Vector3.hh>
#include <gz/math/Quaternion.hh>
#include <chrono>

#define PI 3.141592

namespace gazebo
namespace turtlebot3_gazebo
{
class Obstacles : public ModelPlugin

class ObstaclesPlugin
: public gz::sim::System,
public gz::sim::ISystemConfigure,
public gz::sim::ISystemPreUpdate
{
public:
Obstacles() = default;
void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/) override;
void Configure(
const gz::sim::Entity &entity,
const std::shared_ptr<const sdf::Element> &sdf,
gz::sim::EntityComponentManager &ecm,
gz::sim::EventManager &eventMgr) override;

void PreUpdate(
const gz::sim::UpdateInfo &info,
gz::sim::EntityComponentManager &ecm) override;

private:
physics::ModelPtr model;
event::ConnectionPtr updateConnection;
gz::sim::Model model{gz::sim::kNullEntity};
std::chrono::steady_clock::time_point startTime;
};
GZ_REGISTER_MODEL_PLUGIN(Obstacles);
} // namespace gazebo

} // namespace turtlebot3_gazebo

#endif // TURTLEBOT3_GAZEBO__OBSTACLES_HPP_
101 changes: 101 additions & 0 deletions turtlebot3_gazebo/launch/turtlebot3_dqn_stage1.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env python3
#
# Copyright 2019 ROBOTIS CO., 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.
#
# Authors: Joep Tool

import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import AppendEnvironmentVariable
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node

def generate_launch_description():
launch_file_dir = os.path.join(get_package_share_directory('turtlebot3_gazebo'), 'launch')
ros_gz_sim = get_package_share_directory('ros_gz_sim')

use_sim_time = LaunchConfiguration('use_sim_time', default='true')
x_pose = LaunchConfiguration('x_pose', default='0.0')
y_pose = LaunchConfiguration('y_pose', default='0.0')

world = os.path.join(
get_package_share_directory('turtlebot3_gazebo'),
'worlds',
'turtlebot3_dqn_stage1.world'
)
set_env_vars_resources = AppendEnvironmentVariable(
'GZ_SIM_RESOURCE_PATH',
os.path.join(
get_package_share_directory('turtlebot3_gazebo'),
'models'
)
)

gzserver_cmd = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(ros_gz_sim, 'launch', 'gz_sim.launch.py')
),
launch_arguments={'gz_args': ['-r -s -v4 ', world]}.items()
)
gzclient_cmd = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(ros_gz_sim, 'launch', 'gz_sim.launch.py')
),
launch_arguments={'gz_args': '-g -v4 '}.items()
)

robot_state_publisher_cmd = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(launch_file_dir, 'robot_state_publisher.launch.py')
),
launch_arguments={'use_sim_time': use_sim_time}.items()
)

spawn_turtlebot_cmd = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(launch_file_dir, 'spawn_turtlebot3.launch.py')
),
launch_arguments={
'x_pose': x_pose,
'y_pose': y_pose
}.items()
)

bridge_node = Node(
package='ros_gz_bridge',
executable='parameter_bridge',
name='parameter_bridge_services',
arguments=[
'/delete_entity@ros_gz_interfaces/srv/DeleteEntity',
'/spawn_entity@ros_gz_interfaces/srv/SpawnEntity',
'/reset_simulation@std_srvs/srv/Empty'
],
output='screen'
)

ld = LaunchDescription()

ld.add_action(set_env_vars_resources)
ld.add_action(gzserver_cmd)
ld.add_action(gzclient_cmd)
ld.add_action(robot_state_publisher_cmd)
ld.add_action(spawn_turtlebot_cmd)
ld.add_action(bridge_node)

return ld
Loading
Loading