Error message: no match for operator< as battery_sub_ is a subscriber and battery is a double
Hi, I am currently doing on a project that requires me to create a publisher and subscriber. The idea of this project is that I have to subscribe to the battery information of the driverless vehicle, and once the battery level of the vehicle is lower than the specified battery level (around 30%), the buzzer will ring and the red led will light up. I have managed to subscribe to the rostopic named agv_battery_level, and I have created a variable named battery for the specified battery level. However, the problem I faced was I was unable to pass the subscriber to the conditional statement, as the error message will pop out. I would like to know on how to create a variable for the battery_sub_ and pass it into the conditional statement. Thanks so much!
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <nav_msgs/Odometry.h>
#include <sstream>
#include <std_msgs/UInt16.h>
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#define CRC16 0x8005
#define REPLY_SIZE 1
#define TIMEOUT 1000
#define btoa(x) ((x)?"true":"false")
//ROS Parameter Default
#define MAIN_FREQ 1.0 //Controller main frequency
#define MODBUS_CMD_SEND_DELAY_T 0.05 //unit:s, 0: not appcation, >0: appcation
#define MODBUS_CMD_RESEND_MAX 0 //0: not appcation, >0: appcation
#define MODBUS_CMD_RESEND_TIME 0.5 //unit:s
#define MODBUS_RECVEIE_TIMEOUT 1.0 //unit:s
#define TF_OUTPUT_ENABLE 0
#define FRAME_BUFF_MAX 256
//------------------------------------------
unsigned char data[6];
//------------------------------------------
ros::Publisher estop_pub_;
//------------------------------------------
//ROS Parameter
double main_freq_=MAIN_FREQ ;
double modbus_cmd_send_delay_t_=MODBUS_CMD_SEND_DELAY_T;
std::string modbus_port_;
std::string modbus_baud_;
std_msgs::String bmsg;
double modbus_cmd_resend_max_=MODBUS_CMD_RESEND_MAX;
double modbus_cmd_resend_time_=MODBUS_CMD_RESEND_TIME;
double modbus_recveie_timeout_=MODBUS_RECVEIE_TIMEOUT;
bool tf_output_enable_=TF_OUTPUT_ENABLE;
double battery;
//---------------------------------------------------
//for UART recveier time-out setting
fd_set rset;
int ret = 0;
struct timeval tv;
//---------------------------------------------------
int rev_frame_size=0;
int frame_sent=0;
int frame_recved=0;
int frame_checked=0;
unsigned char frame_bytes[FRAME_BUFF_MAX];
unsigned int frame_idx=0;
unsigned short frame_crc16=0;
int frame_resend_cnt=0;
int trans_step=0;
int trans_next=0;
static int get_new_cmd=0;
static short trans_vLa=0;
static short trans_vRa=0;
//------------------------------------------
double cmd_vel_v=0;
double cmd_vel_w=0;
static char fault_clear = 1;
static char temp_count = 0;
int count = 0;
int fd; /* File descriptor for the port */
unsigned buffer[1000];
unsigned int buf_cnt=0;
bool frame_get_flag=0;
unsigned int frame_rev_freq_cnt=0;
unsigned char read_bytes[800];
unsigned int read_idx=0;
bool syn_flag=0;
int syn_num=0;
ros::Time current_ctime, last_ctime;
double cdt=0;
bool get_ctime=0;
//Odometry
ros::Time time1, time2, odom_current_time, odom_last_time;
ros::Time current_time;
unsigned short crc_fn(unsigned char *dpacket, unsigned int len) // CRC Function(Error calcualtion)
{
unsigned short crc = 0xffff,poly = 0xa001; //Modbus CRC-16
unsigned short i=0;
for(i=0;i<len;i++)
{
crc^= (unsigned short) dpacket[i];
for(int j=0;j<8;j++)
{
if(crc & 0x01)
{
crc >>= 1;
crc ^= poly;
}
else
crc >>= 1;
}
}
return (crc);
}
void write_modbus(unsigned char *data, unsigned int len)
{
unsigned short crc16;
unsigned char buff[40];
unsigned char crc16_data[2];
unsigned short i ...
I believe this is either followed-up in #q373178 or a more generic version of this question is asked in #q373178.