kobuki_ros.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Yujin Robot.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Yujin Robot nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
36 /*****************************************************************************
37  ** Ifdefs
38  *****************************************************************************/
39 
40 #ifndef KOBUKI_ROS_HPP_
41 #define KOBUKI_ROS_HPP_
42 
43 /*****************************************************************************
44  ** Includes
45  *****************************************************************************/
46 
47 #include <string>
48 #include <boost/shared_ptr.hpp>
49 
50 #include <ros/ros.h>
51 #include <angles/angles.h>
52 #include <std_msgs/Empty.h>
53 #include <std_msgs/String.h>
54 #include <std_msgs/Int16MultiArray.h>
55 #include <sensor_msgs/JointState.h>
56 #include <sensor_msgs/Imu.h>
57 #include <ecl/sigslots.hpp>
58 #include <kobuki_msgs/ButtonEvent.h>
59 #include <kobuki_msgs/BumperEvent.h>
60 #include <kobuki_msgs/CliffEvent.h>
61 #include <kobuki_msgs/ControllerInfo.h>
62 #include <kobuki_msgs/DigitalOutput.h>
63 #include <kobuki_msgs/DigitalInputEvent.h>
64 #include <kobuki_msgs/ExternalPower.h>
65 #include <kobuki_msgs/DockInfraRed.h>
66 #include <kobuki_msgs/Led.h>
67 #include <kobuki_msgs/MotorPower.h>
68 #include <kobuki_msgs/PowerSystemEvent.h>
69 #include <kobuki_msgs/RobotStateEvent.h>
70 #include <kobuki_msgs/SensorState.h>
71 #include <kobuki_msgs/Sound.h>
72 #include <kobuki_msgs/VersionInfo.h>
73 #include <kobuki_msgs/WheelDropEvent.h>
74 #include <kobuki_driver/kobuki.hpp>
75 #include "diagnostics.hpp"
76 #include "odometry.hpp"
77 
78 /*****************************************************************************
79  ** Namespaces
80  *****************************************************************************/
81 
82 namespace kobuki
83 {
84 class KobukiRos
85 {
86 public:
87  KobukiRos(std::string& node_name);
88  ~KobukiRos();
89  bool init(ros::NodeHandle& nh, ros::NodeHandle& nh_pub);
90  bool update();
91 
92  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
93 private:
94  /*********************
95  ** Variables
96  **********************/
97  std::string name; // name of the ROS node
99  sensor_msgs::JointState joint_states;
101  bool cmd_vel_timed_out_; // stops warning spam when cmd_vel flags as timed out more than once in a row
102  bool serial_timed_out_; // stops warning spam when serial connection timed out more than once in a row
103 
104  /*********************
105  ** Ros Comms
106  **********************/
112 
117 
120 
121  /*********************
122  ** Ros Callbacks
123  **********************/
124  void subscribeVelocityCommand(const geometry_msgs::TwistConstPtr);
125  void subscribeLed1Command(const kobuki_msgs::LedConstPtr);
126  void subscribeLed2Command(const kobuki_msgs::LedConstPtr);
127  void subscribeDigitalOutputCommand(const kobuki_msgs::DigitalOutputConstPtr);
128  void subscribeExternalPowerCommand(const kobuki_msgs::ExternalPowerConstPtr);
129  void subscribeResetOdometry(const std_msgs::EmptyConstPtr);
130  void subscribeSoundCommand(const kobuki_msgs::SoundConstPtr);
131  void subscribeMotorPower(const kobuki_msgs::MotorPowerConstPtr msg);
132  void subscribeControllerInfoCommand(const kobuki_msgs::ControllerInfoConstPtr msg);
133 
134  /*********************
135  ** SigSlots
136  **********************/
152 
153  /*********************
154  ** Slot Callbacks
155  **********************/
156  void processStreamData();
157  void publishWheelState();
158  void publishInertia();
159  void publishRawInertia();
160  void publishSensorState();
161  void publishDockIRData();
162  void publishVersionInfo(const VersionInfo &version_info);
163  void publishControllerInfo();
164  void publishButtonEvent(const ButtonEvent &event);
165  void publishBumperEvent(const BumperEvent &event);
166  void publishCliffEvent(const CliffEvent &event);
167  void publishWheelEvent(const WheelEvent &event);
168  void publishPowerEvent(const PowerEvent &event);
169  void publishInputEvent(const InputEvent &event);
170  void publishRobotEvent(const RobotEvent &event);
171 
172 
173  // debugging
174  void rosDebug(const std::string &msg) { ROS_DEBUG_STREAM("Kobuki : " << msg); }
175  void rosInfo(const std::string &msg) { ROS_INFO_STREAM("Kobuki : " << msg); }
176  void rosWarn(const std::string &msg) { ROS_WARN_STREAM("Kobuki : " << msg); }
177  void rosError(const std::string &msg) { ROS_ERROR_STREAM("Kobuki : " << msg); }
178  void rosNamed(const std::vector<std::string> &msgs) {
179  if (msgs.size()==0) return;
180  if (msgs.size()==1) { ROS_INFO_STREAM("Kobuki : " << msgs[0]); }
181  if (msgs.size()==2) {
182  if (msgs[0] == "debug") { ROS_DEBUG_STREAM("Kobuki : " << msgs[1]); }
183  else if (msgs[0] == "info" ) { ROS_INFO_STREAM ("Kobuki : " << msgs[1]); }
184  else if (msgs[0] == "warn" ) { ROS_WARN_STREAM ("Kobuki : " << msgs[1]); }
185  else if (msgs[0] == "error") { ROS_ERROR_STREAM("Kobuki : " << msgs[1]); }
186  else if (msgs[0] == "fatal") { ROS_FATAL_STREAM("Kobuki : " << msgs[1]); }
187  }
188  if (msgs.size()==3) {
189  if (msgs[0] == "debug") { ROS_DEBUG_STREAM_NAMED(msgs[1], "Kobuki : " << msgs[2]); }
190  else if (msgs[0] == "info" ) { ROS_INFO_STREAM_NAMED (msgs[1], "Kobuki : " << msgs[2]); }
191  else if (msgs[0] == "warn" ) { ROS_WARN_STREAM_NAMED (msgs[1], "Kobuki : " << msgs[2]); }
192  else if (msgs[0] == "error") { ROS_ERROR_STREAM_NAMED(msgs[1], "Kobuki : " << msgs[2]); }
193  else if (msgs[0] == "fatal") { ROS_FATAL_STREAM_NAMED(msgs[1], "Kobuki : " << msgs[2]); }
194  }
195  }
196 
199  void publishRawControlCommand(const std::vector<short> &velocity_commands);
200 
201  /*********************
202  ** Diagnostics
203  **********************/
215 };
216 
217 } // namespace kobuki
218 
219 #endif /* KOBUKI_ROS_HPP_ */
void publishPowerEvent(const PowerEvent &event)
BatteryTask battery_diagnostics
Definition: kobuki_ros.hpp:205
ecl::Slot< const RobotEvent & > slot_robot_event
Definition: kobuki_ros.hpp:146
WheelDropTask wheel_diagnostics
Definition: kobuki_ros.hpp:209
ros::Publisher wheel_event_publisher
Definition: kobuki_ros.hpp:110
void rosWarn(const std::string &msg)
Definition: kobuki_ros.hpp:176
ecl::Slot< const std::string & > slot_info
Definition: kobuki_ros.hpp:147
void subscribeMotorPower(const kobuki_msgs::MotorPowerConstPtr msg)
#define ROS_DEBUG_STREAM_NAMED(name, args)
void rosInfo(const std::string &msg)
Definition: kobuki_ros.hpp:175
#define ROS_ERROR_STREAM_NAMED(name, args)
void subscribeDigitalOutputCommand(const kobuki_msgs::DigitalOutputConstPtr)
void publishWheelEvent(const WheelEvent &event)
ecl::Slot< const std::vector< std::string > & > slot_named
Definition: kobuki_ros.hpp:148
ros::Publisher robot_event_publisher
Definition: kobuki_ros.hpp:109
KobukiRos(std::string &node_name)
Default constructor.
Definition: kobuki_ros.cpp:61
ecl::Slot< const ButtonEvent & > slot_button_event
Definition: kobuki_ros.hpp:140
File comment.
ros::Publisher raw_imu_data_publisher
Definition: kobuki_ros.hpp:108
ros::Publisher version_info_publisher
Definition: kobuki_ros.hpp:107
void rosError(const std::string &msg)
Definition: kobuki_ros.hpp:177
#define ROS_INFO_STREAM_NAMED(name, args)
ecl::Slot< const BumperEvent & > slot_bumper_event
Definition: kobuki_ros.hpp:141
Diagnostics for the kobuki node.
ecl::Slot slot_stream_data
Definition: kobuki_ros.hpp:138
ecl::Slot< const PowerEvent & > slot_power_event
Definition: kobuki_ros.hpp:144
void publishButtonEvent(const ButtonEvent &event)
AnalogInputTask ainput_diagnostics
Definition: kobuki_ros.hpp:214
void publishInputEvent(const InputEvent &event)
sensor_msgs::JointState joint_states
Definition: kobuki_ros.hpp:99
WallSensorTask bumper_diagnostics
Definition: kobuki_ros.hpp:208
void subscribeControllerInfoCommand(const kobuki_msgs::ControllerInfoConstPtr msg)
MotorCurrentTask motor_diagnostics
Definition: kobuki_ros.hpp:210
ecl::Slot< Command::Buffer & > slot_raw_data_command
Definition: kobuki_ros.hpp:149
ros::Publisher bumper_event_publisher
Definition: kobuki_ros.hpp:110
void subscribeSoundCommand(const kobuki_msgs::SoundConstPtr)
Play a predefined sound (single sound or sound sequence)
ecl::Slot< PacketFinder::BufferType & > slot_raw_data_stream
Definition: kobuki_ros.hpp:150
void publishCliffEvent(const CliffEvent &event)
void subscribeLed1Command(const kobuki_msgs::LedConstPtr)
void publishRobotEvent(const RobotEvent &event)
ros::Publisher cliff_event_publisher
Definition: kobuki_ros.hpp:110
ros::Publisher raw_data_stream_publisher
Definition: kobuki_ros.hpp:111
ros::Publisher controller_info_publisher
Definition: kobuki_ros.hpp:107
Odometry for the kobuki node.
Definition: odometry.hpp:39
ecl::Slot< const std::string & > slot_warn
Definition: kobuki_ros.hpp:147
#define ROS_FATAL_STREAM(args)
ros::Publisher input_event_publisher
Definition: kobuki_ros.hpp:109
#define ROS_FATAL_STREAM_NAMED(name, args)
ros::Publisher imu_data_publisher
Definition: kobuki_ros.hpp:108
ros::Subscriber digital_output_command_subscriber
Definition: kobuki_ros.hpp:113
void publishRawDataStream(PacketFinder::BufferType &buffer)
Prints the raw data stream to a publisher.
GyroSensorTask gyro_diagnostics
Definition: kobuki_ros.hpp:212
WatchdogTask watchdog_diagnostics
Definition: kobuki_ros.hpp:206
ecl::Slot< const InputEvent & > slot_input_event
Definition: kobuki_ros.hpp:145
void subscribeExternalPowerCommand(const kobuki_msgs::ExternalPowerConstPtr)
ros::Publisher sensor_state_publisher
Definition: kobuki_ros.hpp:108
ecl::Slot< const VersionInfo & > slot_version_info
Definition: kobuki_ros.hpp:137
ros::Subscriber external_power_command_subscriber
Definition: kobuki_ros.hpp:113
ecl::Slot< const CliffEvent & > slot_cliff_event
Definition: kobuki_ros.hpp:142
void subscribeLed2Command(const kobuki_msgs::LedConstPtr)
ros::Subscriber controller_info_command_subscriber
Definition: kobuki_ros.hpp:114
ros::Subscriber velocity_command_subscriber
Definition: kobuki_ros.hpp:113
MotorStateTask state_diagnostics
Definition: kobuki_ros.hpp:211
void rosDebug(const std::string &msg)
Definition: kobuki_ros.hpp:174
ros::Publisher raw_data_command_publisher
Definition: kobuki_ros.hpp:111
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
ros::Subscriber led2_command_subscriber
Definition: kobuki_ros.hpp:115
void publishBumperEvent(const BumperEvent &event)
void publishRawDataCommand(Command::Buffer &buffer)
Prints the raw data stream to a publisher.
DigitalInputTask dinput_diagnostics
Definition: kobuki_ros.hpp:213
bool init(ros::NodeHandle &nh, ros::NodeHandle &nh_pub)
Definition: kobuki_ros.cpp:104
void publishVersionInfo(const VersionInfo &version_info)
Publish fw, hw, sw version information.
#define ROS_INFO_STREAM(args)
ros::Subscriber led1_command_subscriber
Definition: kobuki_ros.hpp:115
ros::Publisher power_event_publisher
Definition: kobuki_ros.hpp:110
ros::Publisher joint_state_publisher
Definition: kobuki_ros.hpp:108
void rosNamed(const std::vector< std::string > &msgs)
Definition: kobuki_ros.hpp:178
CliffSensorTask cliff_diagnostics
Definition: kobuki_ros.hpp:207
ros::Subscriber motor_power_subscriber
Definition: kobuki_ros.hpp:116
void advertiseTopics(ros::NodeHandle &nh)
Definition: kobuki_ros.cpp:303
std::string name
Definition: kobuki_ros.hpp:97
ros::Publisher dock_ir_publisher
Definition: kobuki_ros.hpp:108
ros::Publisher raw_control_command_publisher
Definition: kobuki_ros.hpp:111
ros::Subscriber reset_odometry_subscriber
Definition: kobuki_ros.hpp:116
#define ROS_ERROR_STREAM(args)
void subscribeResetOdometry(const std_msgs::EmptyConstPtr)
Reset the odometry variables.
void publishRawControlCommand(const std::vector< short > &velocity_commands)
void subscribeTopics(ros::NodeHandle &nh)
Definition: kobuki_ros.cpp:335
ecl::Slot< const std::string & > slot_error
Definition: kobuki_ros.hpp:147
ecl::Slot< const std::string & > slot_debug
Definition: kobuki_ros.hpp:147
ros::Publisher button_event_publisher
Definition: kobuki_ros.hpp:109
diagnostic_updater::Updater updater
Definition: kobuki_ros.hpp:204
ecl::Slot< const std::vector< short > & > slot_raw_control_command
Definition: kobuki_ros.hpp:151
void subscribeVelocityCommand(const geometry_msgs::TwistConstPtr)
ros::Subscriber sound_command_subscriber
Definition: kobuki_ros.hpp:115
#define ROS_WARN_STREAM_NAMED(name, args)
ecl::Slot< const WheelEvent & > slot_wheel_event
Definition: kobuki_ros.hpp:143
ecl::Slot slot_controller_info
Definition: kobuki_ros.hpp:139


kobuki_node
Author(s): Daniel Stonier, Younghun Ju, Jorge Santos Simon
autogenerated on Mon Jun 10 2019 13:45:13