Skip to content

Commit 5c38d20

Browse files
committed
Added demo launch files (space-ros#46)
1 parent 09b4544 commit 5c38d20

8 files changed

+682
-2
lines changed

custom_gz_plugins/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,29 @@ endif()
77

88
# find dependencies
99
find_package(ament_cmake REQUIRED)
10+
find_package(rclcpp REQUIRED)
11+
find_package(geometry_msgs REQUIRED)
12+
find_package(std_msgs REQUIRED)
13+
find_package(sensor_msgs REQUIRED)
1014
# uncomment the following section in order to fill in
1115
# further dependencies manually.
1216
# find_package(<dependency> REQUIRED)
1317

1418
add_subdirectory(src/DayLightManager)
1519
add_subdirectory(src/DustManager)
1620
add_subdirectory(src/VehicleDust)
17-
add_subdirectory(src/DroneDustPlguin)
21+
add_subdirectory(src/DroneDustPlugin)
1822

23+
add_executable(inguenity_control nodes/inguenity_control.cpp)
24+
ament_target_dependencies(inguenity_control rclcpp std_msgs)
25+
26+
install(TARGETS
27+
inguenity_control
28+
DESTINATION lib/${PROJECT_NAME})
1929

2030
## Install the launch directory
2131
install(
22-
DIRECTORY launch
32+
DIRECTORY launch worlds config
2333
DESTINATION share/${PROJECT_NAME}
2434
)
2535

custom_gz_plugins/config/buggy_bridge.yaml

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
- ros_topic_name: "/thrust"
3+
gz_topic_name: "/model/ingenuity/joint/bottomblade_joint/cmd_thrust"
4+
ros_type_name: "std_msgs/msg/Float64"
5+
gz_type_name: "gz.msgs.Double"
6+
direction: ROS_TO_GZ
7+
8+
- ros_topic_name: "/ang_vel"
9+
gz_topic_name: "/model/ingenuity/joint/bottomblade_joint/ang_vel"
10+
ros_type_name: "std_msgs/msg/Float64"
11+
gz_type_name: "gz.msgs.Double"
12+
direction: ROS_TO_GZ
13+
14+
- ros_topic_name: "/upper_blade"
15+
gz_topic_name: "/plate1_joint/cmd_pos"
16+
ros_type_name: "std_msgs/msg/Float64"
17+
gz_type_name: "gz.msgs.Double"
18+
direction: ROS_TO_GZ
19+
20+
- ros_topic_name: "/lower_blade"
21+
gz_topic_name: "/plate2_joint/cmd_pos"
22+
ros_type_name: "std_msgs/msg/Float64"
23+
gz_type_name: "gz.msgs.Double"
24+
direction: ROS_TO_GZ
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
from ament_index_python.packages import get_package_share_directory
3+
from launch import LaunchDescription
4+
from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
5+
from launch.launch_description_sources import PythonLaunchDescriptionSource
6+
from launch.substitutions import LaunchConfiguration, Command
7+
from launch_ros.actions import Node
8+
9+
def generate_launch_description():
10+
# Get directories
11+
pkg_ugv_sim = get_package_share_directory('custom_gz_plugins')
12+
13+
# Set robot name and bridge config
14+
robot_name = 'buggy'
15+
bridge_config = os.path.join(pkg_ugv_sim, 'config', robot_name + '_bridge.yaml')
16+
17+
# Launch Gazebo
18+
gazebo = ExecuteProcess(
19+
cmd=['gz', 'sim', '-r', 'vehicle_dust_demo.sdf'],
20+
output='screen'
21+
)
22+
23+
# Launch the ROS-GZ bridge
24+
ros_gz_bridge = Node(
25+
package="ros_gz_bridge",
26+
executable="parameter_bridge",
27+
parameters=[{'config_file': bridge_config}],
28+
output='screen'
29+
)
30+
31+
return LaunchDescription([
32+
gazebo,
33+
ros_gz_bridge
34+
])
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
from ament_index_python.packages import get_package_share_directory
3+
from launch import LaunchDescription
4+
from launch.actions import DeclareLaunchArgument, ExecuteProcess, IncludeLaunchDescription
5+
from launch.launch_description_sources import PythonLaunchDescriptionSource
6+
from launch.substitutions import LaunchConfiguration, Command
7+
from launch_ros.actions import Node
8+
9+
def generate_launch_description():
10+
# Get directories
11+
custom_pkg = get_package_share_directory('custom_gz_plugins')
12+
pkg_ros_gz_sim = get_package_share_directory('ros_gz_sim')
13+
14+
# Set robot name and bridge config
15+
robot_name = 'ingenuity'
16+
world_name = 'drone_dust_demo'
17+
bridge_config = os.path.join(custom_pkg, 'config', robot_name + '_bridge.yaml')
18+
19+
world_path = os.path.join(custom_pkg, 'worlds', world_name + '.sdf')
20+
21+
# launch GZ Sim with empty world
22+
gz_sim = IncludeLaunchDescription(
23+
PythonLaunchDescriptionSource(
24+
os.path.join(pkg_ros_gz_sim, 'launch', 'gz_sim.launch.py')
25+
),
26+
launch_arguments={
27+
'gz_args' : world_path + " -r"
28+
}.items()
29+
)
30+
31+
# Launch the ROS-GZ bridge
32+
ros_gz_bridge = Node(
33+
package="ros_gz_bridge",
34+
executable="parameter_bridge",
35+
parameters=[{'config_file': bridge_config}],
36+
output='screen'
37+
)
38+
39+
return LaunchDescription([
40+
# gz_sim,
41+
ros_gz_bridge
42+
])
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
#include <chrono>
2+
#include <functional>
3+
#include <memory>
4+
#include <string>
5+
6+
#include "rclcpp/rclcpp.hpp"
7+
#include "std_msgs/msg/float64.hpp"
8+
#include <stdio.h>
9+
#include <unistd.h>
10+
#include <termios.h>
11+
12+
#include <map>
13+
using namespace std::chrono_literals;
14+
15+
/* This example creates a subclass of Node and uses std::bind() to register a
16+
* member function as a callback from the timer. */
17+
18+
19+
int getch(void)
20+
{
21+
int ch;
22+
struct termios oldt;
23+
struct termios newt;
24+
25+
// Store old settings, and copy to new settings
26+
tcgetattr(STDIN_FILENO, &oldt);
27+
newt = oldt;
28+
29+
// Make required changes and apply the settings
30+
newt.c_lflag &= ~(ICANON | ECHO);
31+
newt.c_iflag |= IGNBRK;
32+
newt.c_iflag &= ~(INLCR | ICRNL | IXON | IXOFF);
33+
newt.c_lflag &= ~(ICANON | ECHO | ECHOK | ECHOE | ECHONL | ISIG | IEXTEN);
34+
newt.c_cc[VMIN] = 1;
35+
newt.c_cc[VTIME] = 0;
36+
tcsetattr(fileno(stdin), TCSANOW, &newt);
37+
38+
// Get the current character
39+
ch = getchar();
40+
41+
// Reapply old settings
42+
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
43+
44+
return ch;
45+
}
46+
47+
int main(int argc, char * argv[])
48+
{
49+
const char* msg = R"(
50+
Reading from the keyboard!
51+
---------------------------
52+
Thrust Key:
53+
w
54+
55+
s
56+
57+
Lower Blades:
58+
59+
a d
60+
61+
62+
Upper Blades:
63+
u
64+
65+
j
66+
67+
t : up (+z)
68+
b : down (-z)
69+
q/e : reverse thrust
70+
w/s : increase/decrease Thrust Key by 10
71+
a/d : increase/decrease Lower Blade angle by 1
72+
u/j : increase/decrease Upper Blade angle by 1
73+
NOTE : Increasing or Decreasing will take affect live on the moving robot.
74+
Consider Stopping the robot before changing it.
75+
CTRL-C to quit
76+
)";
77+
rclcpp::init(argc, argv);
78+
auto node = rclcpp::Node::make_shared("uuv_teleop");
79+
std::cout<<msg<<std::endl;
80+
auto publisher_ver = node->create_publisher<std_msgs::msg::Float64>("/lower_blade", 10);
81+
auto publisher_hoz = node->create_publisher<std_msgs::msg::Float64>("/upper_blade", 10);
82+
auto publisher_thrust = node->create_publisher<std_msgs::msg::Float64>("/thrust", 10);
83+
auto message_ver = std_msgs::msg::Float64();
84+
auto message_hoz = std_msgs::msg::Float64();
85+
auto message_thrust = std_msgs::msg::Float64();
86+
message_ver.data = 0;
87+
message_hoz.data = 0;
88+
message_thrust.data = 0;
89+
90+
while (rclcpp::ok())
91+
{
92+
char key = getch();
93+
94+
if(key == 'A'|| key == 'a'){
95+
if (message_ver.data <= -1.0){
96+
message_ver.data = message_ver.data;
97+
std::cout<<"Lower Blade Angle:- "<<message_ver.data<<std::endl;
98+
}
99+
else{
100+
message_ver.data = message_ver.data - 1;
101+
publisher_ver->publish(message_ver);
102+
std::cout<<"Lower Blade Angle:- "<<message_ver.data<<std::endl;
103+
}
104+
}
105+
if(key == 'D'|| key == 'd'){
106+
if (message_ver.data >= 1.0){
107+
message_ver.data = message_ver.data;
108+
std::cout<<"Lower Blade Angle:- "<<message_ver.data<<std::endl;
109+
}
110+
else{
111+
message_ver.data = message_ver.data + 1;
112+
publisher_ver->publish(message_ver);
113+
std::cout<<"Lower Blade Angle:- "<<message_ver.data<<std::endl;
114+
}
115+
}
116+
if(key == 'u'|| key == 'U'){
117+
if (message_hoz.data <= -1.0){
118+
message_hoz.data = message_hoz.data;
119+
std::cout<<"Upper Blade Angle:- "<<message_hoz.data<<std::endl;
120+
}
121+
else{
122+
message_hoz.data = message_hoz.data - 1;
123+
publisher_hoz->publish(message_hoz);
124+
std::cout<<"Upper Blade Angle:- "<<message_hoz.data<<std::endl;
125+
}
126+
}
127+
if(key == 'j'|| key == 'J'){
128+
if (message_hoz.data >= 1.0){
129+
message_hoz.data = message_hoz.data;
130+
std::cout<<"Upper Blade Angle:- "<<message_hoz.data<<std::endl;
131+
}
132+
else{
133+
message_hoz.data = message_hoz.data + 1;
134+
publisher_hoz->publish(message_hoz);
135+
std::cout<<"Upper Blade Angle:- "<<message_hoz.data<<std::endl;
136+
}
137+
}
138+
if (key == 'q' || key == 'Q'){
139+
if (message_thrust.data <=0){
140+
message_thrust.data = message_thrust.data;
141+
publisher_thrust->publish(message_thrust);
142+
std::cout<<"Thrust Value:- "<<message_thrust.data<<std::endl;
143+
}
144+
else {
145+
message_thrust.data = - message_thrust.data;
146+
publisher_thrust->publish(message_thrust);
147+
std::cout<<"Thrust Value:- "<<message_thrust.data<<std::endl;
148+
}
149+
150+
}
151+
if (key == 'e' || key == 'E'){
152+
if (message_thrust.data >=0){
153+
message_thrust.data = message_thrust.data;
154+
publisher_thrust->publish(message_thrust);
155+
std::cout<<"Thrust Value:- "<<message_thrust.data<<std::endl;
156+
}
157+
else {
158+
message_thrust.data = - message_thrust.data;
159+
publisher_thrust->publish(message_thrust);
160+
std::cout<<"Thrust Value:- "<<message_thrust.data<<std::endl;
161+
}
162+
163+
}
164+
if(key == 'w' || key == 'W'){
165+
message_thrust.data = message_thrust.data + 10;
166+
publisher_thrust->publish(message_thrust);
167+
std::cout<<"Thrust Value (UP):- "<<message_thrust.data<<std::endl;
168+
}
169+
170+
if(key == 's' || key == 'S'){
171+
message_thrust.data = message_thrust.data - 10;
172+
publisher_thrust->publish(message_thrust);
173+
std::cout<<"Thrust Value (DOWN):- "<<message_thrust.data<<std::endl;
174+
}
175+
176+
else if(key == '\x03'){
177+
break;
178+
}
179+
}
180+
181+
182+
rclcpp::shutdown();
183+
return 0;
184+
}

0 commit comments

Comments
 (0)