ridgeback_cooling.cpp
Go to the documentation of this file.
00001 
00034 #include <math.h>
00035 
00036 #include "ridgeback_base/ridgeback_cooling.h"
00037 
00038 
00039 namespace ridgeback_base
00040 {
00041 
00042 const double RidgebackCooling::LINEAR_VEL_THRESHOLD = 0.1;  // m/s
00043 const double RidgebackCooling::ANGULAR_VEL_THRESHOLD = 0.4;  // rad/s
00044 const double RidgebackCooling::MOITON_COMMAND_TIMEOUT = 3.0;  // Seconds.
00045 
00046 RidgebackCooling::RidgebackCooling(ros::NodeHandle* nh) :
00047   nh_(nh),
00048   charger_disconnected_(true)
00049 {
00050   cmd_fans_pub_ = nh_->advertise<ridgeback_msgs::Fans>("mcu/cmd_fans", 1);
00051 
00052   status_sub_ = nh_->subscribe("mcu/status", 1, &RidgebackCooling::statusCallback, this);
00053   cmd_vel_sub_ = nh_->subscribe("cmd_vel", 1, &RidgebackCooling::cmdVelCallback, this);
00054 
00055   cmd_fans_timer_ = nh_->createTimer(ros::Duration(1.0/10), &RidgebackCooling::cmdFansCallback, this);
00056 
00057   for (int i = 0; i < 6; i++)
00058   {
00059     cmd_fans_msg_.fans[i] = ridgeback_msgs::Fans::FAN_ON_LOW;
00060   }
00061 }
00062 
00063 void RidgebackCooling::statusCallback(const ridgeback_msgs::Status::ConstPtr& status)
00064 {
00065   if (status->charger_connected)
00066   {
00067     cmd_fans_msg_.fans[ridgeback_msgs::Fans::CHARGER_BAY_INTAKE] = ridgeback_msgs::Fans::FAN_ON_HIGH;
00068     cmd_fans_msg_.fans[ridgeback_msgs::Fans::CHARGER_BAY_EXHAUST] = ridgeback_msgs::Fans::FAN_ON_HIGH;
00069     charger_disconnected_ = false;
00070   }
00071   else if (!charger_disconnected_)
00072   {
00073     cmd_fans_msg_.fans[ridgeback_msgs::Fans::CHARGER_BAY_INTAKE] = ridgeback_msgs::Fans::FAN_ON_LOW;
00074     cmd_fans_msg_.fans[ridgeback_msgs::Fans::CHARGER_BAY_EXHAUST] = ridgeback_msgs::Fans::FAN_ON_LOW;
00075     charger_disconnected_ = true;
00076   }
00077 }
00078 void RidgebackCooling::cmdVelCallback(const geometry_msgs::Twist::ConstPtr& twist)
00079 {
00080   if (fabs(twist->linear.x) >= LINEAR_VEL_THRESHOLD ||
00081       fabs(twist->linear.y) >= LINEAR_VEL_THRESHOLD ||
00082       fabs(twist->angular.z) >= ANGULAR_VEL_THRESHOLD)
00083   {
00084     for (int i = 0; i < 6; i++)
00085     {
00086       cmd_fans_msg_.fans[i] = ridgeback_msgs::Fans::FAN_ON_HIGH;
00087     }
00088   }
00089   last_motion_cmd_time_ = ros::Time::now().toSec();
00090 }
00091 
00092 void RidgebackCooling::cmdFansCallback(const ros::TimerEvent&)
00093 {
00094   if ((ros::Time::now().toSec() - last_motion_cmd_time_ > MOITON_COMMAND_TIMEOUT) && charger_disconnected_)
00095   {
00096     for (int i = 0; i < 6; i++)
00097     {
00098       cmd_fans_msg_.fans[i] = ridgeback_msgs::Fans::FAN_ON_LOW;
00099     }
00100   }
00101   cmd_fans_pub_.publish(cmd_fans_msg_);
00102 }
00103 
00104 }  // namespace ridgeback_base


ridgeback_base
Author(s): Mike Purvis , Tony Baltovski
autogenerated on Sun Mar 24 2019 03:01:13