catkin_make errors while subscribing to diagnostic topic
I am trying to subscribe to diagnostic
topic and based on the level
published by the topic, I am trying to start and stop my operation. I have created 2 functions requestStart
and requestNotStart
for these purposes. I am getting the CMake
errors which I am unable to fix (posted at the end of the post).
Following is my code -
using namespace std;
namespace errorLib
{
class errorH
{
public:
errorH(EC value, string text, int sec):
value_(value),
text_(text),
is_started_(false),
sec_(sec)
{
}
EC value_;
string text_;
bool is_started_;
int retry_seconds_;
};
}
void diagnosticCallback(const diagnostic_msgs::DiagnosticArrayPtr &diags_msg)
{
if (diags_msg[0].level == diagnostic_msgs::DiagnosticStatus::ERROR)
errorcode = NodeToErrorCode[diags_msg[0].name];
requestStart();
else (diags_msg[0].level == diagnostic_msgs::DiagnosticStatus::OK)
errorcode = NodeToErrorCode[diags_msg[0].name];
requestNotStart();
}
int requestStart(errorLib::errorH& c)
{
if(!c.is_started_)
retry_seconds_ = 2;
// Start timer
// Timer expired
c.is_started_ = true;
return 0;
}
int requestNotStart(errorLib::errorH& c)
{
return 0;
}
int main(int argc, char **argv)
{
errorLib::errorH c("For starting/ending", 2);
requestStart(c);
requestNotStart(c);
ros::init(argc, argv, "<node_name>");
ros::NodeHandle nh;
std::map<std::string, int> NodeToErrorCode =
{{"rosout", 1},
{"<Node1>", 2},
{"<Node2>", 3}};
ros::Subscriber sub = nh.subscribe("diagnostics", 1000, diagnosticCallback);
ros::spin();
return 0;
}
Following are the errors for reference -
In function ‘void diagnosticCallback(const DiagnosticArrayPtr&)’:
/home/default_ws/src/err_pack/src/errors_node.cpp:52:21: error: invalid use of ‘boost::detail::sp_array_access<diagnostic_msgs::DiagnosticArray_<std::allocator<void> > >::type {aka void}’
if (diags_msg[0].level == diagnostic_msgs::DiagnosticStatus::ERROR)
^
/home/default_ws/src/err_pack/src/errors_node.cpp:54:7: error: ‘errorcode’ was not declared in this scope
errorcode = NodeToErrorCode[diags_msg[0].name];
^
/home/default_ws/src/err_pack/src/errors_node.cpp:54:19: error: ‘NodeToErrorCode’ was not declared in this scope
errorcode = NodeToErrorCode[diags_msg[0].name];
^
/home/default_ws/src/err_pack/src/errors_node.cpp:54:47: error: invalid use of ‘boost::detail::sp_array_access<diagnostic_msgs::DiagnosticArray_<std::allocator<void> > >::type {aka void}’
errorcode = NodeToErrorCode[diags_msg[0].name];
^
/home/default_ws/src/err_pack/src/errors_node.cpp:55:18: error: ‘requestStart’ was not declared in this scope
requestStart();
^
/home/default_ws/src/err_pack/src/errors_node.cpp:58:26: error: invalid use of ‘boost::detail::sp_array_access<diagnostic_msgs::DiagnosticArray_<std::allocator<void> > >::type {aka void}’
else if (diags_msg[0].level == diagnostic_msgs::DiagnosticStatus::OK)
^
/home/default_ws/src/err_pack/src/errors_node.cpp:59:47: error: invalid use of ‘boost::detail::sp_array_access<diagnostic_msgs::DiagnosticArray_<std::allocator<void> > >::type {aka void}’
errorcode = NodeToErrorCode[diags_msg[0].name];
^
/home/default_ws/src/err_pack/src/errors_node.cpp:60:21: error: ‘requestNotStart’ was not declared in this scope
requestNotStart();
^
/home/default_ws/src/err_pack/src/errors_node.cpp: In function ‘int requestStart(errorLib::errorH&)’:
/home/default_ws/src/err_pack/src/errors_node.cpp: In function ‘int main(int, char**)’:
/home/default_ws/src/err_pack/src/errors_node.cpp:93:53: error: no matching function for call to ‘errorLib::errorH::errorH(const char [21], int)’
errorLib::errorH c("For starting/ending", 2);
^
/home/default_ws/src/err_pack/src/errors_node.cpp:93:53: note: candidates are:
/home/default_ws/src/err_pack/src/errors_node.cpp:21:7: note: errorLib::errorH::errorH(EC, std::string, int)
errorH(EC value, string ...