Skip to content

Commit 9887f16

Browse files
author
Taehun Lim
authored
Merge pull request #5 from ROBOTIS-GIT/develop
add auto parking application
2 parents 61ee919 + 996ef31 commit 9887f16

19 files changed

+1183
-4
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
###########
2+
## CMake ##
3+
###########
4+
cmake_minimum_required(VERSION 2.8.3)
5+
project(turtlebot3_auto_docking)
6+
7+
##############
8+
## Packages ##
9+
##############
10+
find_package(catkin REQUIRED COMPONENTS
11+
roscpp
12+
std_msgs
13+
tf
14+
geometry_msgs
15+
sensor_msgs
16+
nav_msgs
17+
laser_filters
18+
laser_geometry
19+
message_generation
20+
)
21+
22+
################################################
23+
## Declare ROS messages, services and actions ##
24+
################################################
25+
26+
add_service_files(FILES ChangeNode.srv)
27+
28+
generate_messages( DEPENDENCIES std_msgs)
29+
30+
###################################
31+
## catkin specific configuration ##
32+
###################################
33+
catkin_package(
34+
# INCLUDE_DIRS include
35+
LIBRARIES turtlebot3_auto_docking
36+
CATKIN_DEPENDS roscpp std_msgs geometry_msgs sensor_msgs nav_msgs laser_filters laser_geometry tf message_runtime
37+
# DEPENDS system_lib
38+
)
39+
40+
###########
41+
## Build ##
42+
###########
43+
include_directories(
44+
# include
45+
${catkin_INCLUDE_DIRS}
46+
)
47+
48+
add_executable(get_goal_position src/get_goal_position.cpp)
49+
add_dependencies(get_goal_position ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
50+
target_link_libraries(get_goal_position ${catkin_LIBRARIES} )
51+
52+
add_executable(goal_position_broadcaster src/goal_position_broadcaster.cpp)
53+
add_dependencies(goal_position_broadcaster ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
54+
target_link_libraries(goal_position_broadcaster ${catkin_LIBRARIES} )
55+
56+
add_executable(turtlebot3_auto_docking src/turtlebot3_auto_docking.cpp)
57+
add_dependencies(turtlebot3_auto_docking ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
58+
target_link_libraries(turtlebot3_auto_docking ${catkin_LIBRARIES} )
59+
60+
add_executable(searching_docking_station src/searching_docking_station.cpp)
61+
add_dependencies(searching_docking_station ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
62+
target_link_libraries(searching_docking_station ${catkin_LIBRARIES} )
63+
64+
add_executable(change_node src/change_node.cpp)
65+
add_dependencies(change_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
66+
target_link_libraries(change_node ${catkin_LIBRARIES} )
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
scan_filter_chain:
2+
3+
- name: exist intensity 3000 to infinite
4+
type: laser_filters/LaserScanIntensityFilter
5+
params:
6+
lower_threshold: 4000
7+
upper_threshold: .inf
8+
disp_histogram: 0
9+
10+
- name: interpolation
11+
type: laser_filters/InterpolationFilter
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<launch>
2+
<node pkg="turtlebot3_auto_docking" type="change_node" output="screen" name="change_node_turtlebot3_auto_docking">
3+
</node>
4+
</launch>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<launch>
2+
<node pkg="laser_filters" type="scan_to_scan_filter_chain" output="screen" name="laser_filter">
3+
<remap from="scan" to="/scan" />
4+
<rosparam command="load" file="$(find turtlebot3_auto_docking)/filter/turtlebot3_follow_filter.yaml" />
5+
<remap from="scan_filtered" to="/scan_filtered" />
6+
</node>
7+
8+
<node pkg="turtlebot3_auto_docking" type="get_goal_position" output="screen" name="get_goal_position">
9+
</node>
10+
</launch>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<launch>
2+
<node pkg="turtlebot3_auto_docking" type="goal_position_broadcaster" output="screen" name="goal_position_broadcaster">
3+
</node>
4+
</launch>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<launch>
2+
<node pkg="laser_filters" type="scan_to_scan_filter_chain" output="screen" name="laser_filtered">
3+
<remap from="scan" to="/scan" />
4+
<rosparam command="load" file="$(find turtlebot3_auto_docking)/filter/turtlebot3_follow_filter.yaml" />
5+
<remap from="scan_filtered" to="/scan_filtered" />
6+
</node>
7+
<node pkg="turtlebot3_auto_docking" type="searching_docking_station" output="screen" name="searching_docking_station">
8+
</node>
9+
</launch>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<launch>
2+
<node pkg="turtlebot3_auto_docking" type="turtlebot3_auto_docking" output="screen" name="turtlebot3_auto_docking">
3+
</node>
4+
</launch>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0"?>
2+
<package>
3+
<name>turtlebot3_auto_docking</name>
4+
<version>0.1.0</version>
5+
<description>The turtlebot3_auto_docking package</description>
6+
7+
<maintainer email="[email protected]">ashe</maintainer>
8+
9+
<license>BSD</license>
10+
11+
<buildtool_depend>catkin</buildtool_depend>
12+
<build_depend>roscpp</build_depend>
13+
<build_depend>tf</build_depend>
14+
<build_depend>std_msgs</build_depend>
15+
<build_depend>geometry_msgs</build_depend>
16+
<build_depend>sensor_msgs</build_depend>
17+
<build_depend>nav_msgs</build_depend>
18+
<build_depend>laser_filters</build_depend>
19+
<build_depend>laser_geometry</build_depend>
20+
<build_depend>message_generation</build_depend>
21+
22+
<run_depend>roscpp</run_depend>
23+
<run_depend>tf</run_depend>
24+
<run_depend>std_msgs</run_depend>
25+
<run_depend>geometry_msgs</run_depend>
26+
<run_depend>sensor_msgs</run_depend>
27+
<run_depend>nav_msgs</run_depend>
28+
<run_depend>laser_filters</run_depend>
29+
<run_depend>laser_geometry</run_depend>
30+
<run_depend>message_runtime</run_depend>
31+
32+
<export>
33+
</export>
34+
</package>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include "ros/ros.h"
2+
#include "turtlebot3_auto_docking/ChangeNode.h"
3+
4+
bool change_node(turtlebot3_auto_docking::ChangeNode::Request &req,
5+
turtlebot3_auto_docking::ChangeNode::Response &res)
6+
{
7+
res.change_node = req.next_node;
8+
return true;
9+
}
10+
11+
int main(int argc, char **argv)
12+
{
13+
ros::init(argc, argv, "change_node");
14+
ros::NodeHandle node;
15+
16+
ros::ServiceServer service = node.advertiseService("change_node", change_node);
17+
ROS_INFO("change_node");
18+
ros::spin();
19+
return 0;
20+
}
21+
22+
//
23+
// int main(int argc, char **argv)
24+
// {
25+
// ros::init(argc, argv, "add_two_ints_client");
26+
// if (argc != 3)
27+
// {
28+
// ROS_INFO("usage: add_two_ints_client X Y");
29+
// return 1;
30+
// }
31+
//
32+
// ros::NodeHandle n;
33+
// ros::ServiceClient client = n.serviceClient<beginner_tutorials::AddTwoInts>("add_two_ints");
34+
// beginner_tutorials::AddTwoInts srv;
35+
// srv.request.a = atoll(argv[1]);
36+
// srv.request.b = atoll(argv[2]);
37+
// if (client.call(srv))
38+
// {
39+
// ROS_INFO("Sum: %ld", (long int)srv.response.sum);
40+
// }
41+
// else
42+
// {
43+
// ROS_ERROR("Failed to call service add_two_ints");
44+
// return 1;
45+
// }
46+
//
47+
// return 0;
48+
// }
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#include <ros/ros.h>
2+
#include <laser_geometry/laser_geometry.h>
3+
#include <sensor_msgs/PointCloud.h>
4+
#include <sensor_msgs/LaserScan.h>
5+
#include <geometry_msgs/Point32.h>
6+
#include <geometry_msgs/Twist.h>
7+
#include <nav_msgs/Odometry.h>
8+
#include <std_msgs/Int8.h>
9+
#include <float.h>
10+
11+
#define SEARCH 0
12+
#define GET_GOAL 1
13+
#define FIND 1
14+
15+
ros::Publisher goal_poisition_pub;
16+
ros::Publisher get_goal_state_pub;
17+
ros::Subscriber turtlebot_position_sub;
18+
ros::Subscriber scan_filtered_sub;
19+
ros::Subscriber searching_dock_state_sub;
20+
21+
sensor_msgs::PointCloud cloud;
22+
geometry_msgs::Point32 final_goal_point;
23+
geometry_msgs::Point32 turtlebot_point;
24+
std_msgs::Int8 searching_dock_state_msg;
25+
std_msgs::Int8 get_goal_state_msg;
26+
laser_geometry::LaserProjection projector;
27+
28+
float material_intensities_array[360] = {0};
29+
float point_x_sum = 0.0;
30+
float point_y_sum = 0.0;
31+
float point_z_sum = 0.0;
32+
float average_intensity = 0.0;
33+
float material_intensity_sum = 0.0;
34+
int j = 0;
35+
int k = 0;
36+
int count = 0;
37+
38+
void get_goal_position(void);
39+
40+
void searching_dock_state_Callback(const std_msgs::Int8::ConstPtr &searching_dock_state_sub_msg)
41+
{
42+
searching_dock_state_msg.data = searching_dock_state_sub_msg->data;
43+
}
44+
45+
void odom_Callback(const nav_msgs::Odometry &odom)
46+
{
47+
turtlebot_point.x = odom.pose.pose.position.x;
48+
turtlebot_point.y = odom.pose.pose.position.y;
49+
}
50+
51+
void scan_point_Callback(const sensor_msgs::LaserScan &scan_filtered)
52+
{
53+
if(searching_dock_state_msg.data == FIND)
54+
{
55+
// put a condition statement with count == 0 for do it once.
56+
if(count == 0)
57+
{
58+
// Replace LaserScan values ​​with x, y, z coordinates.
59+
projector.projectLaser(scan_filtered, cloud); //index = cloud.channels[1].values //indensity = cloud.channels[0].values
60+
for(int i=0; i<360; i++)
61+
{
62+
// Scan_filtered.ranges [i] and scan_filtered.intensities [i] may have nan. It makes conditional statements when not nan.
63+
if(isnan(scan_filtered.ranges[i]) == 0.0 && isnan(scan_filtered.intensities[i]) == 0.0)
64+
{
65+
// Gets the average of material_intensities. Distinguishes the intensities of the safety reflector
66+
material_intensities_array[j] = scan_filtered.intensities[i] * scan_filtered.ranges[i];
67+
material_intensity_sum += material_intensities_array[j];
68+
j += 1;
69+
}
70+
}
71+
//Gets the average of material_intensity
72+
average_intensity = material_intensity_sum / j;
73+
74+
for(int i=0; i<j; i++)
75+
{
76+
if(material_intensities_array[i] > average_intensity)
77+
{
78+
// Count the number of coordinates.
79+
k += 1;
80+
// Add x and y ​​of scanned laser values.
81+
// Get the average of x and y coordinates to get the goal coordinates
82+
point_x_sum += cloud.points[i].x;
83+
point_y_sum += cloud.points[i].y;
84+
//ROS_INFO("%d goal_x %f, goal_y %f ",i, cloud.points[i].x, cloud.points[i].y);
85+
}
86+
}
87+
// Add the turtlebot's current position and 1/2 the size of the goal coordinates to get the final coordinates.
88+
final_goal_point.x = turtlebot_point.x + (point_x_sum / (2 * k));
89+
final_goal_point.y = turtlebot_point.y + (point_y_sum / (2 * k));
90+
91+
ROS_INFO("goal_x %f, goal_y %f ", final_goal_point.x, final_goal_point.y);
92+
ROS_INFO("average_intensity %f", average_intensity);
93+
count = 1;
94+
}
95+
get_goal_state_msg.data = GET_GOAL;
96+
goal_poisition_pub.publish(final_goal_point);
97+
get_goal_state_pub.publish(get_goal_state_msg);
98+
}
99+
}
100+
101+
int main(int argc, char** argv)
102+
{
103+
ros::init(argc, argv, "get_goal_position");
104+
ros::NodeHandle node;
105+
106+
goal_poisition_pub = node.advertise<geometry_msgs::Point32>("/goal_poisition", 10);
107+
get_goal_state_pub = node.advertise<std_msgs::Int8>("/get_goal_state", 10);
108+
searching_dock_state_sub = node.subscribe("/searching_dock_state", 10, &searching_dock_state_Callback);
109+
turtlebot_position_sub = node.subscribe("/odom", 10, &odom_Callback);
110+
scan_filtered_sub = node.subscribe("/scan_filtered", 10, &scan_point_Callback);
111+
112+
ros::spin();
113+
114+
return 0;
115+
}

0 commit comments

Comments
 (0)