motion_safety.h
Go to the documentation of this file.
00001 
00002 
00003 #include <ros/ros.h>
00004 #include "grizzly_motion/change_limiter.h"
00005 
00006 #include "diagnostic_updater/diagnostic_updater.h"
00007 #include "diagnostic_updater/publisher.h"
00008 
00009 using boost::shared_ptr;
00010 
00011 namespace grizzly_msgs {
00012 ROS_DECLARE_MESSAGE(Drive);
00013 ROS_DECLARE_MESSAGE(RawStatus);
00014 }
00015 
00016 namespace std_msgs {
00017 ROS_DECLARE_MESSAGE(Bool);
00018 }
00019 
00020 namespace diagnostic_updater {
00021 class Updater;
00022 class HeaderlessTopicDiagnostic;
00023 }
00024 
00025 class EncodersMonitor;
00026 class MotorsMonitor;
00027 
00028 typedef ChangeLimiter<grizzly_msgs::Drive> DriveChangeLimiter;
00029 
00030 namespace MotionStates
00031 {
00032   enum MotionState
00033   {
00034     // State of non-error, non-moving vehicle. As soon as the vehicle has been
00035     // stationary for a brief period, the Moving state transitions to this one.
00036     // Certain errors that will trigger an MCU estop in the Moving or Startup
00037     // states will not do so in the Stopped state.
00038     Stopped,
00039 
00040     // State when movement has been requested but is being held pending the
00041     // mandatory delay period (and accompanying ambience).
00042     Starting,
00043 
00044     // State when vehicle is moving without error.
00045     Moving,
00046 
00047     // State when an estop has been triggered (by the MCU or otherwise). Wait for
00048     // the encoders to report the vehicle as stationary, with no motion being
00049     // commanded, then transition to Stopped.
00050     PendingStopped,
00051 
00052     // State when vehicle is faulted and will remain so until ROS is restarted.
00053     // Assert and hold an MCU estop.
00054     Fault
00055   };
00056 }
00057 typedef MotionStates::MotionState MotionState;
00058 
00059 class MotionSafety
00060 {
00061 public:
00062   MotionSafety() {}
00063   MotionSafety(ros::NodeHandle* nh);
00064 
00065   bool isEstopped();
00066   void setStop(const std::string reason, bool estop, bool fault);
00067   void checkFaults();
00068 
00069 protected:
00070   ros::NodeHandle* nh_;
00071 
00072   // Main watchdog function, which takes care of calling the other components
00073   // to assess overall system health (and thus safety of driving), and manage
00074   // state transitions.
00075   void watchdogCallback(const ros::TimerEvent&);
00076   ros::Timer watchdog_timer_;
00077   MotionState state_;
00078   std::string reason_;
00079 
00080   // Keeps the time of the last received command message with a non-stationary
00081   // movement request to at least one of the wheels.
00082   ros::Time last_commanded_movement_time_;
00083   ros::Time last_non_precharge_time_;
00084 
00085   // Duration of time to spend in the Starting phase.
00086   ros::Duration starting_duration_;
00087 
00088   // Tracks the absolute time when we will transition from Starting to Moving,
00089   // as that's a timed transition.
00090   ros::Time transition_to_moving_time_;
00091 
00092   // Topics directly monitored in this class.
00093   void driveCallback(const grizzly_msgs::DriveConstPtr&);
00094   void estopCallback(const std_msgs::BoolConstPtr&);
00095   void mcuStatusCallback(const grizzly_msgs::RawStatusConstPtr&);
00096   ros::Subscriber sub_drive_, sub_mcu_status_, sub_user_estop_; 
00097   grizzly_msgs::RawStatusConstPtr last_mcu_status_; 
00098 
00099   // Publish cmd_drive through to safe_cmd_drive.
00100   ros::Publisher pub_safe_drive_;
00101     
00102   // Communication to the MCU.
00103   ros::Publisher pub_ambience_;
00104   ros::Publisher pub_estop_;
00105 
00106   // Publish diagnostics for the whole node from here.
00107   shared_ptr<diagnostic_updater::Updater> diagnostic_updater_;
00108   void diagnostic(diagnostic_updater::DiagnosticStatusWrapper& stat);
00109 
00110   // Monitor the frequency of the MCU status and incoming cmd_drive messages for
00111   // acceptable range.
00112   double expected_mcu_status_frequency_;
00113   double min_cmd_drive_freq_, max_cmd_drive_freq_;
00114   shared_ptr<diagnostic_updater::HeaderlessTopicDiagnostic> diag_mcu_status_freq_, diag_cmd_drive_freq_;
00115 
00116   // Separate class for monitoring encoders for sanity.
00117   shared_ptr<EncodersMonitor> encoders_monitor_; 
00118   shared_ptr<MotorsMonitor> motor_drivers_monitor_;
00119   shared_ptr<DriveChangeLimiter> accel_limiters_[4];
00120 
00121   double width_;
00122   double radius_;
00123   double max_accel_;
00124 };
00125 
00126 


grizzly_motion
Author(s):
autogenerated on Fri Aug 28 2015 10:55:30