3 #include <igvc_msgs/lights.h>
4 #include <std_msgs/Bool.h>
5 #include <std_msgs/Int8.h>
14 int main(
int argc,
char** argv)
16 ros::init(argc, argv,
"light_controller");
20 SerialPort port{
"/dev/igvc_light_arduino", 9600};
24 ROS_ERROR_STREAM(
"Failed to open port: " << port.devicePath());
28 ros::Subscriber lights_sub = nh.subscribe(
"/lights", 1,
lights_callback);
30 ros::Publisher enabled_pub = nh.advertise<std_msgs::Bool>(
"/robot_enabled", 1);
32 ros::Publisher battery_pub = nh.advertise<std_msgs::Int8>(
"/battery", 1);
34 ROS_INFO_STREAM(
"Light controller ready.");
39 while(ros::ok() && port.isOpen())
41 unsigned char msg[12] = {2,
42 state.safety_flashing,
43 state.underglow_color[0],
44 state.underglow_color[1],
45 state.underglow_color[2],
46 state.underglow_brightness[0],
47 state.underglow_brightness[1],
48 state.underglow_brightness[2],
49 state.underglow_brightness[3],
50 state.underglow_brightness[4],
51 state.underglow_brightness[5],
56 unsigned char *ret = (
unsigned char*)port.read(4);
58 if(ret[0] != 2 || ret[3] != 4)
59 ROS_ERROR_STREAM(
"Bad format for return packet.");
61 ROS_ERROR_STREAM(
"Light controller gave error code " << ret[2]);
64 std_msgs::Bool estop_msg;
65 estop_msg.data = !(bool)(ret[1]);
67 enabled_pub.publish(estop_msg);
69 std_msgs::Int8 battery_msg;
70 battery_msg.data = ret[2];
72 battery_pub.publish(battery_msg);
void lights_callback(const igvc_msgs::lightsConstPtr &msg)
int main(int argc, char **argv)
Helper class to simplify interfacing with serial port hardware.