ScitosBase.h
Go to the documentation of this file.
00001 #ifndef __SCITOSBASE__
00002 #define __SCITOSBASE__
00003 
00004 #include <boost/thread.hpp>
00005 #include <boost/noncopyable.hpp>
00006 
00007 #include <MetraLabsBase.h>
00008 #include <config/MLRobotic_config.h>
00009 #include <base/Application.h>
00010 #include <robot/Robot.h>
00011 #include <robot/RangeData.h>
00012 
00013 #include <ros/ros.h>
00014 
00015 #include <tf/transform_broadcaster.h>
00016 
00017 #include <std_msgs/Empty.h>
00018 #include <diagnostic_msgs/DiagnosticStatus.h>
00019 #include <diagnostic_msgs/DiagnosticArray.h>
00020 #include <sensor_msgs/Range.h>
00021 #include <nav_msgs/Odometry.h>
00022 
00023 #include <metralabs_msgs/ScitosG5Bumper.h>
00024 
00025 #include <dynamic_reconfigure/server.h>
00026 #include <metralabs_ros/ScitosG5Config.h>
00027 
00028 
00029 using namespace MetraLabs::base;
00030 using namespace MetraLabs::robotic::base;
00031 using namespace MetraLabs::robotic::robot;
00032 
00033 
00034 #define FEATURE_SONAR   ( "SonarsActive" )
00035 
00036 
00037 class ScitosBase : public BlackboardDataUpdateCallback, private boost::noncopyable {
00038 
00039 public:
00040         ScitosBase(const char*, int pArgc, char* pArgv[], ros::NodeHandle& nh);
00041         ~ScitosBase();
00042 
00043         virtual void dataChanged(const BlackboardData* pData) {
00044                 if(pData == odometry_data_) {
00045                         odometryCallbackHandler();
00046                 } else if(pData == sonar_data_) {
00047                         sonarCallbackHandler();
00048                 } else if(pData == bumper_data_) {
00049                         bumperDataCallbackHandler();
00050                 }
00051         }
00052 
00053 private:
00054         // wrapping the type specific Robot.set/getFeatureTYPE methods with templates
00055         template<typename FeatureType>
00056         void setFeature(std::string name, FeatureType value);
00057         template<typename FeatureType>
00058         FeatureType getFeature(std::string name);
00059 
00060         void odometryCallbackHandler();
00061         void sonarCallbackHandler();
00062         void bumperDataCallbackHandler();
00063 
00064         void diagnosticsPublishingLoop(ros::Rate loop_rate);
00065         void checkSubscribersLoop(ros::Rate loop_rate);
00066         void dynamicReconfigureUpdaterLoop(
00067                         dynamic_reconfigure::Server<metralabs_ros::ScitosG5Config> &dynamic_reconfigure_server,
00068                         boost::recursive_mutex &mutex, ros::Rate loop_rate);
00069 
00070         void dynamicReconfigureCallback(metralabs_ros::ScitosG5Config& config, uint32_t level);
00071 
00072         void getFeatures(metralabs_ros::ScitosG5Config& config);
00073 
00074 
00075         void setVelocity(double translational_velocity, double rotational_velocity) {
00076                 velocity_cmd_->writeLock();
00077                 velocity_cmd_->setVelocity(translational_velocity, rotational_velocity);
00078                 velocity_cmd_->writeUnlock(MTime::now());
00079                 velocity_cmd_->setModified();
00080         }
00081 
00082         void resetBumper() {
00083                 bumper_reset_cmd_->set(0, true, true, MetraLabs::base::MTime::now());
00084         }
00085 
00086 
00087         void driveCommandCallback(const geometry_msgs::TwistConstPtr& msg) {
00088                 setVelocity(msg->linear.x, msg->angular.z);
00089                 ROS_DEBUG("Received some speeds [%f %f]", msg->linear.x, msg->angular.z);
00090         }
00091 
00092         void bumperResetCallback(const std_msgs::EmptyConstPtr& dummy) {
00093                 ROS_INFO("Resetting bumper");
00094                 resetBumper();
00095         }
00096 
00097 
00098 private:
00099         Application* app_;
00100         ClassFactory* class_factory_;
00101         Blackboard* blackboard_;
00102         Robot* robot_;
00103 
00104         BlackboardDataOdometry* odometry_data_;
00105         BlackboardDataRange* sonar_data_;
00106         BlackboardDataBatteryState* battery_state_data_;
00107         BlackboardDataBumper* bumper_data_;
00108 
00109         BlackboardDataVelocity* velocity_cmd_;
00110         BlackboardDataUInt8* bumper_reset_cmd_;
00111 
00112 
00113         ros::NodeHandle& node_handle_;
00114         tf::TransformBroadcaster tf_broadcaster_;
00115 
00116         ros::Publisher diagnostics_publisher_;
00117         ros::Publisher odom_publisher_;
00118         ros::Publisher sonar_publisher_;
00119         ros::Publisher bumper_publisher_;
00120 
00121         ros::Subscriber cmd_vel_subscriber_;
00122         ros::Subscriber bumper_reset_subscriber_;
00123 
00124         boost::recursive_mutex dynamic_reconfigure_mutex_;
00125         dynamic_reconfigure::Server<metralabs_ros::ScitosG5Config> dynamic_reconfigure_server_;
00126 
00127         bool sonar_is_requested_;
00128 };
00129 
00130 #endif


metralabs_ros
Author(s): Yianni Gatsoulis and Chris Burbridge and Lorenzo Riano and Felix Kolbe
autogenerated on Mon Oct 6 2014 07:27:58