diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ac02008dc3a24dca889bd76e5041f07449f6bf7..aaedd5706cc6c83bfd97f7bd60acb85fe701d00e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ project(cobot_1) #add_compile_options(-std=c++14) set(GCC_COVERAGE_COMPILE_FLAGS "-fpermissive") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS} ${GAZEBO_CXX_FLAGS}") +# Wichtig für VSCode debugging +set(CMAKE_BUILD_TYPE Debug) # Find catkin macros and libraries if COMPONENTS list like `find_package(catkin REQUIRED COMPONENTS xyz)` is used, # also find other catkin packages diff --git a/launch/cobot1_mock_test.launch b/launch/cobot1_mock_test.launch index fc3f7a42f6325bb5cd08935f2862df46c53b4d77..ddc9405321dfdd73b6075b24eba5a95f4416c582 100644 --- a/launch/cobot1_mock_test.launch +++ b/launch/cobot1_mock_test.launch @@ -9,6 +9,7 @@ <include file="$(find pressure_sensor)/launch/pressure_sensor_mock.launch" /> <node name="Cobot1_TRONAdapter" pkg="cobot_1" type="TRON_Adapter" respawn="false" output="screen"/> + <node name="Cobot1_Controller" pkg="cobot_1" type="CobotController" respawn="false" output="screen"> <rosparam command="load" file="$(find cobot_1)/config/cobot1_config.yaml" /> </node> diff --git a/src/tron_adapter.cpp b/src/tron_adapter.cpp index d4fc92ef916e05138153f085cd51f980cab59037..3a34852a92d3b24c9251e2960061fd2117b8fa94 100644 --- a/src/tron_adapter.cpp +++ b/src/tron_adapter.cpp @@ -7,6 +7,8 @@ #include <boost/make_shared.hpp> #include <memory> #include <cooperation_msgs/PressureMsg.h> +#include <moveit_msgs/PickupActionResult.h> +#include <moveit_msgs/MoveItErrorCodes.h> const std::string IP = "127.0.0.1"; const uint16_t PORT = 8080; @@ -185,7 +187,7 @@ struct Mapping { this->channel = *send_channel_decl_msg(channelIsInput, channel).get(); } - void add_var_to_mapping(std::string name_tron, int byte_offset, + void add_var_to_mapping(std::string name_tron, int byte_offset = 0, int32_t (*conv_to_TRON)(byte*, int*) = nullptr, void (*conv_to_topic)(int32_t, byte*, int*) = nullptr){ add_var_to_channel(this->channel, this->channel.is_input, name_tron); @@ -353,6 +355,14 @@ void report_now(Channel& chan, uint16_t var_count = 0, int32_t *vars = nullptr){ acks_missing++; } +void report_now(std::string chan, uint16_t var_count = 0, int32_t *vars = nullptr){ + for (Mapping& map : mappings) + if (map.channel.name == chan) { + report_now(map.channel, var_count, vars); + return; + } +} + // callback reports to TRON like defined in mappings template<class T> void mappings_callback_to_TRON(const ros::MessageEvent<T>& event){ @@ -381,25 +391,35 @@ void mappings_callback_to_TRON(const ros::MessageEvent<T>& event){ } -void on_pressure(const cooperation_msgs::PressureMsg::ConstPtr &msg) { +int32_t retry_count; + +void on_pressure(const cooperation_msgs::PressureMsg::ConstPtr &msg) { if (msg->pressed) - for (Mapping& map : mappings) { - if (map.channel.name == "pressed" && map.channel.is_input == false) - report_now(map.channel); - } + report_now("pressed", 1, &retry_count); +} + +void on_pickup_result(const moveit_msgs::PickupActionResult::ConstPtr &msg) { + if (msg->result.error_code.val == moveit_msgs::MoveItErrorCodes::SUCCESS) + report_now("pickup_success"); + else report_now("pickup_fail"); } void configuration_phase(ros::NodeHandle& nh){ /* note: for configuration phase maximum message length is 256 Bytes, therefore heap allocation can be avoided most of the time in called functions */ + nh.getParam("/planning/retries", retry_count); // note: since we are not an actual client (or server) // we need to use the high level packet::*Action* messages. // custom callbacks are implemented in order to not worry about header size Mapping map = Mapping("/pressure", "pressed", false); + map.add_var_to_mapping("init_retry_count"); mappings.push_back(map); output_subscribers.push_back(nh.subscribe("/pressure", 10, on_pressure)); + map = Mapping("/pickup/result", "pickup_fail", false); + map = Mapping("/pickup/result", "pickup_success", false); + output_subscribers.push_back(nh.subscribe("/pickup/result", 10, on_pickup_result)); // not obvious in documentation: local variables are not supported // add_var_to_channel(socketfd, "ausloesen", "lokal"); uint64_t microseconds = 1000000; // one second