Skip to content

Commit 48b3f58

Browse files
committed
basic navigation adapter setup. Can receive custom navigation request, and respond with yes/no indicating if the navigation stack was able to reach desired goal. Also did loadtesting on ROS service architecture. It can handle frequent service requests, but move_base cannot, so I will use a priority system to ensure only prioritised services are sent to stack.
1 parent 9792067 commit 48b3f58

File tree

9 files changed

+163
-9
lines changed

9 files changed

+163
-9
lines changed

arc_behaviour/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ find_package(catkin REQUIRED COMPONENTS
1010
rospy
1111
marker_msgs
1212
geometry_msgs
13+
actionlib
14+
move_base_msgs
15+
actionlib_msgs
1316
)
1417

1518
## System dependencies are found with CMake's conventions
@@ -200,12 +203,15 @@ add_executable(detect_marker_ps src/DetectMarkerPS.cpp src/DetectMarkerPS.h src/
200203
add_executable(detect_robot_ps src/detect_robot_ps_node.cpp src/DetectRobotPS.cpp src/DetectRobotPS.h)
201204
add_executable(detect_debris_ps src/detect_debris_ps_node.cpp src/DetectDebrisPS.cpp src/DetectDebrisPS.h)
202205
add_executable(detect_victim_ps src/detect_victim_ps_node.cpp src/DetectVictimPS.cpp src/DetectVictimPS.h)
206+
add_executable(navigation_adapter src/NavigationAdapter.cpp src/NavigationAdapter.h src/navigation_adapter_node.cpp)
203207

204208
target_link_libraries(detect_victim_ps ${catkin_LIBRARIES} )
205209
target_link_libraries(detect_marker_ps ${catkin_LIBRARIES} )
206210
target_link_libraries(detect_robot_ps ${catkin_LIBRARIES} )
207211
target_link_libraries(detect_debris_ps ${catkin_LIBRARIES} )
212+
target_link_libraries(navigation_adapter ${catkin_LIBRARIES} )
208213

209-
add_dependencies(detect_victim_ps arc_msgs_generate_messages_cpp)
210-
add_dependencies(detect_debris_ps arc_msgs_generate_messages_cpp)
211-
#add_dependencies(detect_robot_ps arc_msgs_generate_messages_cpp)
214+
add_dependencies(detect_debris_ps marker_msgs_generate_messages_cpp arc_msgs_generate_messages_cpp)
215+
add_dependencies(detect_victim_ps marker_msgs_generate_messages_cpp arc_msgs_generate_messages_cpp)
216+
add_dependencies(detect_robot_ps marker_msgs_generate_messages_cpp arc_msgs_generate_messages_cpp)
217+
add_dependencies(navigation_adapter arc_msgs_generate_messages_cpp)

arc_behaviour/launch/default.launch

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212
<node name="detect_debris_ps" pkg="arc_behaviour" type="detect_debris_ps">
1313
<param name="max_range" value="6"/>
1414
</node>
15+
16+
<node name="navigation_adapter" pkg="arc_behaviour" type="navigation_adapter">
17+
</node>
18+
1519
</launch>

arc_behaviour/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
<!-- <test_depend>gtest</test_depend> -->
4242
<buildtool_depend>catkin</buildtool_depend>
4343
<build_depend>roscpp</build_depend>
44+
<build_depend>actionlib_msgs</build_depend>
4445
<run_depend>roscpp</run_depend>
46+
<run_depend>actionlib_msgs</run_depend>
4547
<build_depend>std_msgs</build_depend>
4648
<build_depend>geometry_msgs</build_depend>
4749
<build_depend>arc_msgs</build_depend>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include "NavigationAdapter.h"
2+
#include <actionlib/client/simple_action_client.h>
3+
#include "arc_msgs/NavigationRequest.h"
4+
#include "std_srvs/Empty.h"
5+
6+
using namespace arc_behaviour;
7+
8+
NavigationAdapter::NavigationAdapter() {
9+
ros::NodeHandle nh;
10+
this->global_handle = nh;
11+
ros::NodeHandle local_handle("navigation_adapter");
12+
this->local_handle = local_handle;
13+
ROS_INFO("Setting up navigation adapter..");
14+
this->move_to_goal_server = local_handle.advertiseService("move_to_goal",&NavigationAdapter::move_to_goal_request_cb, this);
15+
this->move_client = new MoveBaseClient("move_base", true);
16+
//wait for the action server to come up
17+
while(!move_client->waitForServer(ros::Duration(5.0))) { //TODO: Better checking to ensure action server is actually up. If it's not, we need to let user know.
18+
ROS_INFO("Waiting for the move_base action server to come up");
19+
}
20+
ROS_INFO("Found move_base action server!");
21+
}
22+
23+
void NavigationAdapter::move_to_goal_result_cb(const actionlib::SimpleClientGoalState& state, const move_base_msgs::MoveBaseResultConstPtr& result) {
24+
if (state == actionlib::SimpleClientGoalState::ABORTED){
25+
ROS_INFO("Failed to move");
26+
}else if(state == actionlib::SimpleClientGoalState::SUCCEEDED){
27+
ROS_INFO("successfully moved to goal!!!");
28+
}
29+
30+
//either way, we are done navigating (until another request is sent)
31+
this->goal_active = false;
32+
}
33+
34+
bool NavigationAdapter::move_to_goal_request_cb(arc_msgs::NavigationRequest::Request &req, arc_msgs::NavigationRequest::Response &res) {
35+
ROS_INFO("Received request to move to goal (%d, %d) with priority %d", req.pose.position.x, req.pose.position.y, req.priority);
36+
37+
move_base_msgs::MoveBaseGoal goal;
38+
if(this->goal_active) {
39+
} else {
40+
//If no goal is currently active, we can send request to move_base
41+
//we'll send a goal to the robot to move 1 meter forward
42+
goal.target_pose.header.frame_id = "base_link";
43+
goal.target_pose.header.stamp = ros::Time::now();
44+
45+
goal.target_pose.pose.position.x = req.pose.position.x;
46+
goal.target_pose.pose.orientation.w = 1.0;
47+
48+
ROS_INFO("Sending navigation goal");
49+
this->move_client->sendGoal(goal, boost::bind(&NavigationAdapter::move_to_goal_result_cb, this,_1,_2));
50+
return true;
51+
}
52+
}
53+
54+
void NavigationAdapter::run() {
55+
ros::Rate r(10); //TODO: Make this a parameter, just get rid of magic numbers.
56+
57+
while(ros::ok()) {
58+
59+
/*if(this->move_client.getState() == actionlib::SimpleClientGoalState::ACTIVE) {
60+
ROS_INFO("Navigation goal is active.");
61+
} else {
62+
ROS_INFO("navigation is not active");
63+
}*/
64+
ros::spinOnce();
65+
r.sleep();
66+
}
67+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* CLASS: NavigationAdaptor
3+
* DATE: 16/02/17
4+
* AUTHOR: Kyle Morris
5+
* DESCRIPTION: Provides adapted interface between arc_base and ros navigation stack.
6+
* Allow for filtering navigation requests based on priority. For example... when randomly wandering,
7+
* multiple navigation requests may be sent to the navigation stack. When a request to move to a robot is sent,
8+
* this will have a higher priority, and will not be interrupted by other requests. This ensures important navigation is completed.
9+
*/
10+
11+
#ifndef PROJECT_NAVIGATIONADAPTER_H
12+
#define PROJECT_NAVIGATIONADAPTER_H
13+
14+
#include <ros/ros.h>
15+
#include "std_srvs/Empty.h"
16+
#include <geometry_msgs/Pose.h>
17+
#include "arc_msgs/NavigationRequest.h"
18+
#include <move_base_msgs/MoveBaseAction.h>
19+
#include <actionlib/client/simple_action_client.h>
20+
21+
typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient;
22+
namespace arc_behaviour {
23+
class NavigationAdapter{
24+
private:
25+
ros::NodeHandle global_handle;
26+
27+
ros::NodeHandle local_handle;
28+
29+
/*
30+
* Any requests to move to some location will be checked here before calling upon navigation stack.
31+
*/
32+
ros::ServiceServer move_to_goal_server;
33+
34+
/**
35+
* Our communication with the navigation stack.
36+
*/
37+
MoveBaseClient *move_client;
38+
39+
/**
40+
* Whether or not the navigation stack is currently being used to reach a goal.
41+
*/
42+
bool goal_active;
43+
44+
public:
45+
NavigationAdapter();
46+
47+
/**
48+
* Move to navigation target location.
49+
*/
50+
bool move_to_goal_request_cb(arc_msgs::NavigationRequest::Request &req, arc_msgs::NavigationRequest::Response &res);
51+
52+
/**
53+
* When move_base is done, it will send a callback to signal the result of navigation. This may be either when the navigation is completed
54+
* succesfully or it fails to navigate.
55+
*/
56+
void move_to_goal_result_cb(const actionlib::SimpleClientGoalState& state, const move_base_msgs::MoveBaseResultConstPtr& result);
57+
58+
//run the main loop of node.
59+
void run();
60+
};
61+
//TODO: make sure getters/setters are set for all classes in behaviour module
62+
}
63+
64+
#endif //PROJECT_NAVIGATIONADAPTOR_H

arc_behaviour/src/detect_marker_ps_node.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
int main(int argc, char **argv) {
55
ros::init(argc, argv, "detect_marker_ps_node");
6-
76
arc_behaviour::DetectMarkerPS detector;
87
detector.run();
98

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "ros/ros.h"
2+
#include "NavigationAdapter.h"
3+
4+
int main(int argc, char **argv) {
5+
ros::init(argc, argv, "navigation_adaptor");
6+
arc_behaviour::NavigationAdapter adapter;
7+
adapter.run();
8+
return 0;
9+
}

arc_msgs/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ add_message_files(
5656
)
5757

5858
## Generate services in the 'srv' folder
59-
# add_service_files(
60-
# FILES
61-
# Service1.srv
62-
# Service2.srv
63-
# )
59+
add_service_files(
60+
FILES
61+
NavigationRequest.srv
62+
)
6463

6564
## Generate actions in the 'action' folder
6665
# add_action_files(

arc_msgs/srv/NavigationRequest.srv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int32 priority #how important is this request? The higher, the better.
2+
geometry_msgs/Pose pose #where to move to
3+
---
4+
bool result #true if the request was accepted. False if rejected.

0 commit comments

Comments
 (0)