Skip to content
Snippets Groups Projects
Commit 4bcc17cd authored by Christoph Schröter's avatar Christoph Schröter
Browse files

No commit message

No commit message
parent 9fdff7ab
No related branches found
No related tags found
No related merge requests found
......@@ -104,7 +104,7 @@ struct Mapping {
Channel channel = Channel("", 0, true); // TRON channel
// Callback used if TRON sends some message
// output callbacks must be specified when subscribing to topics
void(*input_callback)(Mapping& map, int32_t*) = nullptr;
boost::function<void(Mapping& map, int32_t*)> input_callback = 0;
// note: since ROS messages can be complex, using byte positions might be cumbersome to use
// it is easy to implement custom callbacks using ROS message types
......@@ -258,7 +258,7 @@ struct TRON_Adapter {
pub.publish(ptr);
return;
}
throw "did not find publisher for topic";
throw "did not find publisher";
}
/**
......@@ -293,7 +293,6 @@ struct TRON_Adapter {
publish_to_topic<T>(map.topic, shared_ptr);
}
/**
* callback reports to TRON like defined in byte-mappings
* note: this callback reports to all channels associated with calling topic
......
#include <ros/ros.h>
#include <actionlib_example/TriggerAction.h>
#include "tron_adapter.h"
#include <std_msgs/Int32.h>
TRON_Adapter adapter;
......@@ -73,6 +74,23 @@ int main(int argc, char**argv){
configuration_phase(nh);
// example use of template callbacks
/*
Mapping map = adapter.createMapping("/test_in", "oeffnen", true);
adapter.add_var_to_mapping(map, "akt_position");
map.input_callback = boost::bind(&TRON_Adapter::mapping_callback_to_topic<std_msgs::Int32>, &adapter, _1, _2);
adapter.input_publishers.push_back(nh.advertise<std_msgs::Int32>("/test_in", 10));
adapter.mappings.push_back(map);
map = adapter.createMapping("/test_out", "position", false);
adapter.add_var_to_mapping(map, "akt_position");
adapter.output_subscribers.push_back(nh.subscribe<std_msgs::Int32>("/test_out", 10,
boost::function<void(const ros::MessageEvent<std_msgs::Int32>&)>(
boost::bind(&TRON_Adapter::mappings_callback_to_TRON<std_msgs::Int32>, &adapter, _1))));
adapter.mappings.push_back(map);
adapter.set_time_unit_and_timeout(1000000L, 300);
*/
adapter.request_start();
// testing phase loop
......
......@@ -2,6 +2,7 @@
#include <actionlib_example/TriggerAction.h>
#include <actionlib/server/simple_action_server.h>
#include <stdlib.h>
#include <std_msgs/Int32.h>
class Garage {
private:
......@@ -61,14 +62,29 @@ class Garage {
}
};
/*
ros::Publisher pub;
void test_in_cb(ros::MessageEvent<std_msgs::Int32> event) {
std_msgs::Int32 i;
i.data = 100;
pub.publish(i);
}
*/
int main(int argc, char** argv){
ros::init(argc, argv, "gar_serv");
ros::NodeHandle nh;
ROS_INFO("server here");
// not working on stack for some reason,
// might be too big, no stackoverflow thrown though
// Garage gar();
Garage* gar = new Garage();
/*
pub = nh.advertise<std_msgs::Int32>("test_out", 10);
ros::Subscriber sub = nh.subscribe<std_msgs::Int32>("test_in", 10, test_in_cb);
*/
ros::spin();
delete gar;
return 0;
......
......@@ -308,7 +308,7 @@ void TRON_Adapter::process_TRONs_msgs(){
for (Mapping& map : mappings)
if (map.channel.name == chan->name && map.channel.is_input) {
if (map.input_callback != nullptr)
if (!map.input_callback.empty())
map.input_callback(map, vals);
else throw "no callback declared";
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment