Skip to content

Commit bfcadcf

Browse files
committed
Testing behaviour. Ability to control pioneer P3DX using navigation stack. Creating demo worlds and preparing to make standard test/demo launch files.
1 parent 4251b51 commit bfcadcf

29 files changed

+955
-101
lines changed

arc_behaviour/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ include_directories(
193193

194194
## Add folders to be run by python nosetests
195195
# catkin_add_nosetests(test)
196-
add_executable(arc_base src/arc_base_node.cpp src/ArcBase.cpp include/ArcBase.h src/RandomWanderMS.cpp src/RandomWanderMS.h)
196+
add_executable(arc_base src/arc_base_node.cpp src/ArcBase.cpp include/ArcBase.h src/RandomWanderMS.cpp src/RandomWanderMS.h src/MotorSchema.h)
197197

198198
target_link_libraries(arc_base
199199
${catkin_LIBRARIES}
@@ -205,7 +205,7 @@ add_executable(detect_robot_ps src/detect_robot_ps_node.cpp src/DetectRobotPS.cp
205205
add_executable(detect_debris_ps src/detect_debris_ps_node.cpp src/DetectDebrisPS.cpp include/DetectDebrisPS.h)
206206
add_executable(detect_victim_ps src/detect_victim_ps_node.cpp src/DetectVictimPS.cpp include/DetectVictimPS.h)
207207
add_executable(navigation_adapter src/NavigationAdapter.cpp include/NavigationAdapter.h src/navigation_adapter_node.cpp)
208-
add_executable(random_wander_ms src/RandomWanderMS.cpp src/RandomWanderMS.h src/random_wander_ms_node.cpp)
208+
add_executable(random_wander_ms src/RandomWanderMS.cpp src/RandomWanderMS.h src/random_wander_ms_node.cpp src/MotorSchema.h)
209209

210210
target_link_libraries(detect_victim_ps ${catkin_LIBRARIES} )
211211
target_link_libraries(detect_marker_ps ${catkin_LIBRARIES} )

arc_behaviour/include/ArcBase.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* DATE: 13/02/17
44
* AUTHOR: Kyle Morris
55
* DESCRIPTION: Central entry point for behaviour in arc_ros.
6-
* Manages motor/perceptual schemas and receives motor schema activation vectors and adds them together,
7-
* then publishes final result on cmd_vel.
86
*/
97
#include "ros/ros.h"
108
#include "geometry_msgs/TwistStamped.h"
9+
#include <map>
10+
#include "arc_msgs/ToggleSchema.h"
1111

1212
#ifndef ARC_BEHAVIOUR_ARCBASE_H
1313
#define ARC_BEHAVIOUR_ARCBASE_H
@@ -16,25 +16,28 @@ namespace arc_behaviour {
1616

1717
class ArcBase {
1818
private:
19-
/**
20-
* MOTOR SCHEMAS
21-
*/
22-
2319
/*
2420
* Node that this object is working on.
2521
*/
2622
ros::NodeHandle *nh;
2723

24+
ros::NodeHandle global_handle;
25+
ros::ServiceServer toggle_server;
26+
2827
/**
2928
* Setup all of the motor schemas.
3029
*/
31-
bool setupSchemas(); //TODO: Throw exception if fail.
30+
bool setupSchemas();
3231

32+
/**
33+
* list of clients that will allow for toggling motor schemas.
34+
*/
35+
std::map<std::string, ros::ServiceClient> motor_clients;
3336
public:
3437
ArcBase(ros::NodeHandle *nh);
3538

3639
/**
37-
* Activates schemas and ros publishers.
40+
* Connect to various schemas.
3841
*/
3942
void setup();
4043

@@ -48,17 +51,21 @@ class ArcBase {
4851
/**
4952
* Turn on a specified motor schema.
5053
* @param type: Name of the schema to toggle, as specified in ros message request.
54+
* @param state: True or false, depending on if you want to enable/disable schema.
5155
* @return bool: True if the schema was toggled, false if otherwise.
5256
*/
53-
bool toggleSchema(std::string type);
54-
57+
bool toggleSchema(std::string type, bool state);
5558

5659
/**
5760
* Does calculation of final action vector by taking sum of all intermediate
5861
* motor schema action vectors.
5962
* @return Twist message representing final vector.
6063
*/
6164
geometry_msgs::Twist getActionVector();
65+
66+
bool toggle_schema_cb(arc_msgs::ToggleSchema::Request &req, arc_msgs::ToggleSchema::Response &res);
67+
68+
void run();
6269
};
6370
};
6471

arc_behaviour/include/DetectMarkerPS.h

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,63 @@
99
#ifndef ARC_BEHAVIOUR_MARKERDETECTORPS_H
1010
#define ARC_BEHAVIOUR_MARKERDETECTORPS_H
1111

12-
namespace arc_behaviour {
12+
namespace arc_behaviour
13+
{
14+
class DetectMarkerPS
15+
{
16+
private:
17+
/**
18+
* Collection of the markers found in given perceptual instance.
19+
*/
20+
marker_msgs::MarkerDetection found_markers;
1321

14-
class DetectMarkerPS {
15-
private:
16-
/**
17-
* Collection of the markers found in given perceptual instance.
18-
*/
19-
marker_msgs::MarkerDetection found_markers;
22+
/**
23+
* Maximum range that we can detect markers from robots position.
24+
*/
25+
int max_range;
2026

21-
/**
22-
* Maximum range that we can detect markers from robots position.
23-
*/
24-
int max_range;
27+
/**
28+
* Publish marker information, ie a simple boolean if markers are nearby.
29+
*/
30+
ros::Publisher marker_status_publisher;
31+
ros::Subscriber marker_detector_sub;
2532

26-
/**
27-
* Publish marker information, ie a simple boolean if markers are nearby.
28-
*/
29-
ros::Publisher marker_status_publisher;
30-
ros::Subscriber marker_detector_sub;
33+
//for public interface with ros
34+
ros::NodeHandle *global_handle; //the handler for this node.
3135

32-
//for public interface with ros
33-
ros::NodeHandle *global_handle; //the handler for this node.
36+
//for private node material
37+
ros::NodeHandle local_handle;
3438

35-
//for private node material
36-
ros::NodeHandle local_handle;
39+
//callbacks
3740

38-
//callbacks
41+
//update us with most recent stage information
42+
void process_detect_marker_cb(const marker_msgs::MarkerDetection &marker_info);
43+
public:
44+
/**
45+
* Setup the detector with all of the ros topic publishers.
46+
* @param handle : the node handle to setup with.
47+
*/
48+
DetectMarkerPS();
3949

40-
//update us with most recent stage information
41-
void process_detect_marker_cb(const marker_msgs::MarkerDetection marker_info);
42-
public:
43-
/**
44-
* Setup the detector with all of the ros topic publishers.
45-
* @param handle : the node handle to setup with.
46-
*/
47-
DetectMarkerPS();
50+
/**
51+
* Check output from stage and prune markers to ones only within our maximum range.
52+
*/
53+
void ProcessStageFiducial();
4854

49-
/**
50-
* Check output from stage and prune markers to ones only within our maximum range.
51-
*/
52-
void ProcessStageFiducial();
55+
/**
56+
* @return True if at least 1 marker is nearby. False otherwise.
57+
*/
58+
bool areMarkersNearby();
5359

54-
/**
55-
* @return True if at least 1 marker is nearby. False otherwise.
56-
*/
57-
bool areMarkersNearby();
60+
void setMaxRange(int new_range);
5861

59-
void setMaxRange(int new_range);
62+
ros::NodeHandle *getNodeHandle();
6063

61-
ros::NodeHandle *getNodeHandle();
62-
63-
/**
64-
* Main loop. Publishes marker status information.
65-
*/
66-
void run();
67-
};
64+
/**
65+
* Main loop. Publishes marker status information.
66+
*/
67+
void run();
68+
};
6869
}
6970

7071
#endif //ARC_BEHAVIOUR_MARKERDETECTORPS_H

arc_behaviour/include/DetectRobotPS.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,5 @@ class DetectRobotPS {
7171
};
7272
}
7373

74-
7574
#endif //ARC_BEHAVIOUR_DETECTROBOTPS_H
7675
//TODO: Change stage to not publish marker information, ie for every single marker on a topic. Just let robot detect it in map, and publish info when it finds them. We have to mod stage to move markers using a service, not by having cmd_vel publishing nonsense. ROS can't handle 100's of markers all publishing odom info, they aren't robots.

arc_behaviour/include/NavigationAdapter.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ namespace arc_behaviour {
5959
* @param req: The accepted navigation request.
6060
*/
6161
void sendGoal(arc_msgs::NavigationRequest::Request &req);
62-
6362
public:
6463
NavigationAdapter();
6564

@@ -80,10 +79,21 @@ namespace arc_behaviour {
8079
*/
8180
void move_to_goal_result_cb(const actionlib::SimpleClientGoalState& state, const move_base_msgs::MoveBaseResultConstPtr& result);
8281

82+
bool isGoal_active() const;
83+
84+
void setGoal_active(bool goal_active);
85+
86+
int getCurrent_nav_priority() const;
87+
88+
void setCurrent_nav_priority(int current_nav_priority);
89+
90+
bool isIs_stuck() const;
91+
92+
void setIs_stuck(bool is_stuck);
93+
8394
//run the main loop of node.
8495
void run();
8596
};
86-
//TODO: make sure getters/setters are set for all classes in behaviour module
8797
}
8898

8999
#endif //PROJECT_NAVIGATIONADAPTOR_H

arc_behaviour/launch/default.launch

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<launch>
2-
<node name="arc_base" pkg="arc_behaviour" type="arc_base" />
2+
<node name="arc_base" pkg="arc_behaviour" type="arc_base">
3+
<rosparam param="schemas">[random_wander_ms]</rosparam>
4+
</node>
35
<node name="detect_marker_ps" pkg="arc_behaviour" type="detect_marker_ps">
46
<param name="max_range" value="5"/>
57
</node>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<launch>
2+
<node name="arc_base" pkg="arc_behaviour" type="arc_base">
3+
<rosparam param="schemas">["random_wander_ms"]</rosparam>
4+
</node>
5+
<node name="detect_marker_ps" pkg="arc_behaviour" type="detect_marker_ps">
6+
<param name="max_range" value="5"/>
7+
</node>
8+
<node name="detect_robot_ps" pkg="arc_behaviour" type="detect_robot_ps">
9+
<param name="max_range" value="5"/>
10+
</node>
11+
<node name="detect_victim_ps" pkg="arc_behaviour" type="detect_victim_ps">
12+
<param name="max_range" value="6"/>
13+
</node>
14+
<node name="detect_debris_ps" pkg="arc_behaviour" type="detect_debris_ps">
15+
<param name="max_range" value="6"/>
16+
</node>
17+
18+
<node name="navigation_adapter" pkg="arc_behaviour" type="navigation_adapter">
19+
</node>
20+
21+
<node name="random_wander_ms" pkg="arc_behaviour" type="random_wander_ms">
22+
<param name="max_range" value="15"/>
23+
<param name="update_goal_freq" value="0.05"/>
24+
<param name="priority" value="1"/>
25+
</node>
26+
</launch>

arc_behaviour/src/ArcBase.cpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
1+
#include <XmlRpcException.h>
12
#include "../include/ArcBase.h"
3+
#include "ros/ros.h"
4+
#include "std_srvs/SetBool.h"
5+
#include "std_srvs/Empty.h"
26

37
using namespace arc_behaviour;
8+
using namespace XmlRpc;
9+
#define DEFAULT_RATE 10
410

511
ArcBase::ArcBase(ros::NodeHandle *nh) {
12+
ros::NodeHandle global_handle;
613
this->nh = nh;
14+
this->global_handle = global_handle;
15+
this->toggle_server = this->nh->advertiseService("toggle_schema", &ArcBase::toggle_schema_cb, this);
716
}
817

918
bool ArcBase::setupSchemas() {
1019
ROS_INFO("Setting up motor schemas.");
20+
XmlRpcValue schema_list;
21+
22+
try {
23+
24+
ros::param::get("/arc_base/schemas", schema_list);
25+
26+
for(unsigned i=0; i< schema_list.size(); i++) {
27+
ROS_DEBUG("Schema list contains: %s", schema_list[i]);
28+
if(schema_list[i].getType()==XmlRpcValue::TypeString) {
29+
std::string content = schema_list[i];
30+
std::string topic_name = content + "/toggle";
31+
ROS_INFO("Found schema: %s. subscribing to topic %s", content.c_str(), topic_name.c_str());
32+
ros::ServiceClient client = this->global_handle.serviceClient<std_srvs::SetBool>(topic_name);
33+
34+
this->motor_clients.insert({content, client});
35+
} else {
36+
ROS_WARN("ArcBase::setupSchemas: found non-string value in schema list. value ignored.");
37+
}
38+
}
39+
} catch(XmlRpc::XmlRpcException problem) {
40+
ROS_WARN("error in arc_base::setupSchemas: %s. Make sure /arc_base/schemas param is set to strings.", problem.getMessage().c_str());
41+
}
42+
1143
return true;
1244
}
1345

@@ -21,8 +53,28 @@ void ArcBase::setup() {
2153
}
2254

2355

24-
bool ArcBase::toggleSchema(std::string type) {
25-
return false;
56+
bool ArcBase::toggleSchema(std::string type, bool state) {
57+
std_srvs::SetBool req;
58+
req.request.data = state;
59+
this->motor_clients[type].call(req);
60+
}
61+
62+
bool ArcBase::toggle_schema_cb(arc_msgs::ToggleSchema::Request &req, arc_msgs::ToggleSchema::Response &res) {
63+
if(this->motor_clients[req.schema]!=NULL) {
64+
this->toggleSchema(req.schema, req.state);
65+
} else {
66+
ROS_WARN("ArcBase::toggleSchema: %s was not found as a schema.", req.schema.c_str());
67+
}
68+
return true;
69+
}
70+
71+
void ArcBase::run() {
72+
ros::Rate r(DEFAULT_RATE);
73+
74+
while(ros::ok()) {
75+
ros::spinOnce();
76+
r.sleep();
77+
}
2678
}
2779

2880
geometry_msgs::Twist ArcBase::getActionVector() {

arc_behaviour/src/DetectDebrisPS.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#define PUBLISH_RATE 10
1212

1313
//TODO: Test this overall schema. Setup a specific world and test to make sure it works properly on that world.
14-
//TODO: Find way to set /use_sim_time param to false by default, so these nodes publish. Right now you must manually disable using rosparam.
1514
using namespace arc_behaviour;
1615

1716
DetectDebrisPS::DetectDebrisPS() {
@@ -26,7 +25,6 @@ DetectDebrisPS::DetectDebrisPS() {
2625

2726
int max_range;
2827
local_handle.getParam("max_range", max_range);
29-
//TODO: Stage has it's own max_range. Make stage use the max_range from parameter server, so they are both in sync. This way in stage the debris_detection will use the same max range as the behaviour module does.
3028
this->setMaxRange(max_range);
3129
}
3230

arc_behaviour/src/DetectMarkerPS.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
#define PUBLISH_RATE 10
1010

1111
//TODO: Test this overall schema. Setup a specific world and test to make sure it works properly on that world.
12-
//TODO: Find way to set /use_sim_time param to false by default, so these nodes publish. Right now you must manually disable using rosparam.
1312
using namespace arc_behaviour;
1413

1514
DetectMarkerPS::DetectMarkerPS() {
1615
ros::NodeHandle nh;
1716
this->global_handle = &nh;
1817
ros::NodeHandle local_handle("detect_marker_ps");
19-
this->local_handle = local_handle;
18+
this->local_handle = local_handle; //TODO: be consistent with pointers/nonpointer
2019
ROS_INFO("Setting up Marker detection perceptual schema.");
2120
this->marker_status_publisher = local_handle.advertise<std_msgs::Bool>("marker_status", MAX_QUEUE_SIZE);
2221
this->marker_detector_sub = this->getNodeHandle()->subscribe("marker_detector", MAX_QUEUE_SIZE, &DetectMarkerPS::process_detect_marker_cb, this); //TODO: Check if publisher exists
@@ -28,7 +27,8 @@ DetectMarkerPS::DetectMarkerPS() {
2827
this->setMaxRange(max_range);
2928
}
3029

31-
void DetectMarkerPS::process_detect_marker_cb(const marker_msgs::MarkerDetection marker_info) {
30+
void DetectMarkerPS::process_detect_marker_cb(const marker_msgs::MarkerDetection &marker_info)
31+
{
3232
ROS_DEBUG("process detect marker cb called.");
3333
this->found_markers = marker_info;
3434
}

0 commit comments

Comments
 (0)