14 #ifndef RANDOM_WALKER_CONTROLLER_HPP_ 15 #define RANDOM_WALKER_CONTROLLER_HPP_ 20 #define _USE_MATH_DEFINES 24 #include <geometry_msgs/Twist.h> 25 #include <kobuki_msgs/BumperEvent.h> 26 #include <kobuki_msgs/CliffEvent.h> 27 #include <kobuki_msgs/Led.h> 28 #include <kobuki_msgs/WheelDropEvent.h> 30 #include <std_msgs/Empty.h> 83 <<
", angular velocity = " <<
vel_ang_ <<
" [" <<
name_ <<
"]");
84 std::srand(std::time(0));
151 void enableCB(
const std_msgs::EmptyConstPtr msg);
157 void disableCB(
const std_msgs::EmptyConstPtr msg);
163 void bumperEventCB(
const kobuki_msgs::BumperEventConstPtr msg);
169 void cliffEventCB(
const kobuki_msgs::CliffEventConstPtr msg);
206 if (msg->state == kobuki_msgs::BumperEvent::PRESSED)
210 case kobuki_msgs::BumperEvent::LEFT:
217 case kobuki_msgs::BumperEvent::CENTER:
224 case kobuki_msgs::BumperEvent::RIGHT:
244 kobuki_msgs::LedPtr led_msg_ptr;
245 led_msg_ptr.reset(
new kobuki_msgs::Led());
246 led_msg_ptr->value = kobuki_msgs::Led::ORANGE;
252 kobuki_msgs::LedPtr led_msg_ptr;
253 led_msg_ptr.reset(
new kobuki_msgs::Led());
254 led_msg_ptr->value = kobuki_msgs::Led::BLACK;
267 if (msg->state == kobuki_msgs::CliffEvent::CLIFF)
271 case kobuki_msgs::CliffEvent::LEFT:
278 case kobuki_msgs::CliffEvent::CENTER:
285 case kobuki_msgs::CliffEvent::RIGHT:
305 kobuki_msgs::LedPtr led_msg_ptr;
306 led_msg_ptr.reset(
new kobuki_msgs::Led());
307 led_msg_ptr->value = kobuki_msgs::Led::ORANGE;
313 kobuki_msgs::LedPtr led_msg_ptr;
314 led_msg_ptr.reset(
new kobuki_msgs::Led());
315 led_msg_ptr->value = kobuki_msgs::Led::BLACK;
327 if (msg->state == kobuki_msgs::WheelDropEvent::DROPPED)
331 case kobuki_msgs::WheelDropEvent::LEFT:
337 case kobuki_msgs::WheelDropEvent::RIGHT:
355 kobuki_msgs::LedPtr led_msg_ptr;
356 led_msg_ptr.reset(
new kobuki_msgs::Led());
357 led_msg_ptr->value = kobuki_msgs::Led::RED;
365 kobuki_msgs::LedPtr led_msg_ptr;
366 led_msg_ptr.reset(
new kobuki_msgs::Led());
367 led_msg_ptr->value = kobuki_msgs::Led::BLACK;
384 geometry_msgs::TwistPtr cmd_vel_msg_ptr;
385 cmd_vel_msg_ptr.reset(
new geometry_msgs::Twist());
400 if (((
double)std::rand() / (
double)RAND_MAX) >= 0.5)
411 <<
" degrees. [" <<
name_ <<
"]");
428 cmd_vel_msg_ptr->linear.x =
vel_lin_;
bool cliff_center_detected_
Flag for center cliff sensor's state.
double vel_ang_
Angular velocity for rotating.
bool led_bumper_on_
Flag for bumper LED's state.
double vel_lin_
Linear velocity for moving straight.
void cliffEventCB(const kobuki_msgs::CliffEventConstPtr msg)
Trigger direction change and LED blink, when a cliff is detected.
ros::Subscriber disable_controller_subscriber_
bool led_wheel_drop_on_
Flag for wheel drop sensor LED's state.
void publish(const boost::shared_ptr< M > &message) const
bool bumper_center_pressed_
Flag for center bumper's state.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void bumperEventCB(const kobuki_msgs::BumperEventConstPtr msg)
Trigger direction change and LED blink, when a bumper is pressed.
void wheelDropEventCB(const kobuki_msgs::WheelDropEventConstPtr msg)
Trigger stopping and LED blink, when a wheel drop is detected.
ros::Subscriber wheel_drop_event_subscriber_
void disableCB(const std_msgs::EmptyConstPtr msg)
ROS logging output for disabling the controller.
ros::Subscriber bumper_event_subscriber_
Subscribers.
bool stop_
Flag for stopping.
bool cliff_right_detected_
Flag for right cliff sensor's state.
std::string name_
Node(let) name.
ros::Time turning_start_
Start time of turning.
bool wheel_drop_right_detected_
Flag for right wheel drop sensor's state.
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void enableCB(const std_msgs::EmptyConstPtr msg)
ROS logging output for enabling the controller.
int turning_direction_
Randomly chosen turning direction.
ros::Duration turning_duration_
Randomly chosen turning duration.
ros::Publisher cmd_vel_publisher_
Publishers.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Subscriber cliff_event_subscriber_
~RandomWalkerController()
bool cliff_left_detected_
Flag for left cliff sensor's state.
#define ROS_INFO_STREAM(args)
ros::Publisher led1_publisher_
bool change_direction_
Flag for changing direction.
ros::NodeHandle nh_priv_
Private ROS handle.
bool wheel_drop_left_detected_
Flag for left wheel drop sensor's state.
bool led_cliff_on_
Flag for cliff sensor LED's state.
bool turning_
Flag for turning state.
bool bumper_right_pressed_
Flag for right bumper's state.
ros::Publisher led2_publisher_
RandomWalkerController(ros::NodeHandle &nh_priv, std::string &name)
bool bumper_left_pressed_
Flag for left bumper's state.
ros::Subscriber enable_controller_subscriber_
Subscribers.
void spin()
Publishes velocity commands and triggers the LEDs.