segway_rmp400_driver.cpp
Go to the documentation of this file.
00001 #include <iridrivers/segway_RMP400_exception.h>
00002 #include <exception>
00003 #include "segway_rmp200_status.h" // used to build ROS status messages
00004 #include "segway_rmp400_driver.h"
00005 
00006 SegwayRmp400Driver::SegwayRmp400Driver()
00007 {
00008     //setDriverId(driver string id);
00009     try
00010     {
00011         segway_ = new CSegwayRMP400();
00012     }
00013     catch (CSegwayRMP400Exception & e)
00014     {
00015         ROS_FATAL("'%s'",e.what().c_str());
00016     }
00017 }
00018 
00019 bool
00020 SegwayRmp400Driver::openDriver(void)
00021 {
00022     try
00023     {
00024         segway_->start();
00025         segway_->reset_integrators();
00026     }
00027     catch (CException & e)
00028     {
00029         ROS_ERROR("'%s'", e.what().c_str());
00030         return false;
00031     }
00032     catch (std::exception & e)
00033     {
00034         ROS_ERROR("Unexpected exception '%s': ",e.what());
00035         return false;
00036     }
00037 
00038     return true;
00039 }
00040 
00041 bool
00042 SegwayRmp400Driver::closeDriver(void)
00043 {
00044     try
00045     {
00046         segway_->stop();
00047     }
00048     catch (CException & e)
00049     {
00050         ROS_ERROR("'%s'", e.what().c_str());
00051         return false;
00052     }
00053 
00054     return true;
00055 }
00056 
00057 bool
00058 SegwayRmp400Driver::startDriver(void)
00059 {
00060     return true;
00061 }
00062 
00063 bool
00064 SegwayRmp400Driver::stopDriver(void)
00065 {
00066     return true;
00067 }
00068 
00069 void
00070 SegwayRmp400Driver::config_update(const Config& new_cfg, uint32_t level)
00071 {
00072   this->lock();
00073 
00074   //update driver with new_cfg data
00075 
00076   // save the current configuration
00077   this->config_=new_cfg;
00078 
00079   this->unlock();
00080 }
00081 
00082 iri_segway_rmp_msgs::SegwayRMP400Status
00083 SegwayRmp400Driver::get_status(void)
00084 {
00085     iri_segway_rmp_msgs::SegwayRMP400Status ROS_status;
00086     TSegwayRMP400Status segway_status = segway_->get_status();
00087 
00088     ROS_status.rmp200[0] = segway_rmp200_node::build_ROS_status_msg(segway_status.rmp200[0]);
00089     ROS_status.rmp200[1] = segway_rmp200_node::build_ROS_status_msg(segway_status.rmp200[1]);
00090 
00091     return ROS_status;
00092 }
00093 
00094 void
00095 SegwayRmp400Driver::move(const geometry_msgs::Twist::ConstPtr & msg)
00096 {
00097     lock();
00098 
00099     // For movement we define axis X as only possible segway linear movement
00100     double vT = msg->linear.x;
00101     double vR = msg->angular.z;
00102 
00103     ROS_DEBUG("Movement sent to platform. vT = '%f' vR = '%f'", vT, vR);
00104     segway_->move(vT,vR);
00105 
00106     unlock();
00107 }
00108 
00109 SegwayRmp400Driver::~SegwayRmp400Driver()
00110 {
00111     delete segway_;
00112 }


iri_segway_rmp400
Author(s): Jose Luis Rivero
autogenerated on Fri Dec 6 2013 22:52:14