150 #include <std_msgs/Float32.h>
151 #include <std_msgs/Float64.h>
152 #include <std_msgs/Int8.h>
153 #include <std_msgs/Int16.h>
154 #include <std_msgs/Int32.h>
155 #include <std_msgs/Int64.h>
156 #include <std_msgs/UInt8.h>
157 #include <std_msgs/UInt16.h>
158 #include <std_msgs/UInt32.h>
159 #include <std_msgs/UInt64.h>
163 #include <std_msgs/Bool.h>
164 #include <boost/algorithm/string.hpp>
165 #include <sensor_msgs/Joy.h>
166 #include <h4r_x52_joyext/x52_mfd.h>
198 return this->second < other.second;
224 n->param<
int>(
"line",
line, 0);
225 n->param<
int>(
"pos",
pos, 0);
227 n->param<
int>(
"align",
align, 0);
237 ROS_WARN(
"%s: char_as_int = %i (assuming 0 -> interpred as char)",ros::this_node::getName().c_str(), char_as_int);
240 if (field_length + pos > 16)
242 ROS_ERROR(
"%s: Field does not fit into display, will be cut!",
243 ros::this_node::getName().c_str());
244 field_length -= (field_length +
pos) - 16;
247 if (field_length == 0)
249 ROS_ERROR(
"%s: Field length is zero!",
250 ros::this_node::getName().c_str());
256 std::vector<std::string> separatedSetup;
257 boost::split(separatedSetup, stringprint_setup,
258 boost::is_any_of(
"|"));
259 ROS_INFO(
"%s",stringprint_setup.c_str());
263 for (i = 0; i < separatedSetup.size(); ++i)
269 ROS_ERROR(
"%s: String: %s too big for field!",
270 ros::this_node::getName().c_str(),
271 separatedSetup[i].c_str());
272 separatedSetup[i].erase(field_length,
273 separatedSetup[i].size() - field_length);
275 pair.first = separatedSetup[i];
276 ROS_INFO(
"%s",separatedSetup[i].c_str());
280 std::istringstream ss(separatedSetup[i]);
283 if(ss.bad() || ss.fail() || !ss.eof())
285 ROS_ERROR(
"Error in setup string: %s",separatedSetup[i].c_str());
289 this->
ranges.insert(pair);
293 if (!i % 2 || i == 0)
295 ROS_ERROR(
"Error in setup string, missing string for upper end!");
299 pair.second = std::numeric_limits<T>::max();
300 this->
ranges.insert(pair);
304 pub = n->advertise<h4r_x52_joyext::x52_mfd>(
"mfd_text", 1,1);
305 h4r_x52_joyext::x52_mfd init_msg;
306 init_msg.clearDisplay=
false;
312 pub.publish(init_msg);
319 template <
typename V>
323 h4r_x52_joyext::x52_mfd msg;
324 std::ostringstream ss;
325 std::string value_string;
335 h4r_x52_joyext::x52_mfd msg;
336 std::ostringstream ss;
337 std::string value_string;
341 ROS_ERROR(
"%s: Error in creating (char) value string",ros::this_node::getName().c_str());
354 ss<<(
signed int)value;
358 ss<<(
unsigned int)value;
372 template <
typename V>
375 h4r_x52_joyext::x52_mfd msg;
376 msg.clearDisplay =
false;
380 for (
typename std::set<PairSortMod>::iterator it =
ranges.begin();
383 if (it->second > value)
387 msg.data = it->first;
394 msg.clearDisplay =
false;
410 for (
int s = 0; s < (msg.data.length() -
field_length); ++s)
412 msg.data.push_back(
' ');
417 for (
int s = 0; s < ((msg.data.length() -
field_length) / 2); ++s)
420 msg.data.insert(0,
" ");
422 msg.data.push_back(
' ');
428 for (
int s = 0; s < (msg.data.length() -
field_length); ++s)
430 msg.data.insert(0,
" ");
439 int dec_pos=msg.data.find(
'.');
441 std::cout<<msg.data<<std::endl;
475 ROS_ERROR(
"Axis %i not available for that Joystick!",
487 ROS_ERROR(
"Button %i not available for that Joystick!",
493 template<
class MSGPTR>
499 template<
class MSG,
class MSGPTR>
509 sub =
n->subscribe<sensor_msgs::Joy>(
"in", 1000,
522 int main(
int argc,
char **argv)
524 ros::init(argc, argv,
"mfd_writer");
525 ros::NodeHandle n(
"~");
527 #define casem(CASE,TYPE,TYPEROS)\
530 PublishMFD< TYPE > obj(&n);\
531 obj.start<std_msgs::TYPEROS, std_msgs:: TYPEROS## ConstPtr>();\
557 ROS_ERROR(
"Unkown Input Type %i!",type);
std::string positive_oversize
String to show if the integer part of a value is bigger then the size (positiv)
ros::Publisher pub
The publisher.
int line
The line where the string will be placed.
bool operator<(const PairSortMod &other) const
ros::NodeHandle * n
The node handler.
std::string get_value_string(char value)
bool axis_or_button
Joy topic addition.
PublishMFD(ros::NodeHandle *n)
A char is interpreted as integer if this is 1 or as unsigned integer if this is 2 and as char on any ...
bool stringprint
If this is true, there will be strings instead of values.
#define casem(CASE, TYPE, TYPEROS)
std::string negative_oversize
String to show if the integer part of a value is bigger then the size (negative)
int pos
Position from the beginning of the line.
std::set< PairSortMod > ranges
void Callback(const MSGPTR &msg)
int align
Align of the text in the field, 0=Left, 1=Center, 2 (or anything else)=Right.
std::string stringprint_setup
if stringprint is enabled, this will store the strings to be displayed
ros::Subscriber sub
The subscriber.
void progressValue(V value)
int main(int argc, char **argv)
std::string get_value_string(V value)
int field_length
Field length.
void JoyCallback(const sensor_msgs::JoyConstPtr &msg)
int axis_button
The button or axis number if using Joy topic.