controller_manager_layer.cpp
Go to the documentation of this file.
00001 
00002 #include <canopen_motor_node/controller_manager_layer.h>
00003 #include <controller_manager/controller_manager.h>
00004 
00005 using namespace canopen;
00006 
00007 void ControllerManagerLayer::handleRead(canopen::LayerStatus &status, const LayerState &current_state) {
00008     if(current_state > Shutdown){
00009         if(!cm_) status.error("controller_manager is not intialized");
00010     }
00011 }
00012 
00013 void ControllerManagerLayer::handleWrite(canopen::LayerStatus &status, const LayerState &current_state) {
00014     if(current_state > Shutdown){
00015         if(!cm_){
00016             status.error("controller_manager is not intialized");
00017         }else{
00018             time_point abs_now = canopen::get_abs_time();
00019             ros::Time now = ros::Time::now();
00020 
00021             ros::Duration period = fixed_period_;
00022 
00023             if(period.isZero()) {
00024                 period.fromSec(boost::chrono::duration<double>(abs_now -last_time_).count());
00025             }
00026 
00027             last_time_ = abs_now;
00028 
00029             bool recover = recover_.exchange(false);
00030             cm_->update(now, period, recover);
00031             robot_->enforce(period, recover);
00032         }
00033     }
00034 }
00035 
00036 void ControllerManagerLayer::handleInit(canopen::LayerStatus &status) {
00037     if(cm_){
00038         status.warn("controller_manager is already intialized");
00039     }else{
00040         recover_ = true;
00041         last_time_ = canopen::get_abs_time();
00042         cm_.reset(new controller_manager::ControllerManager(robot_.get(), nh_));
00043     }
00044 }
00045 
00046 void ControllerManagerLayer::handleRecover(canopen::LayerStatus &status) {
00047     if(!cm_) status.error("controller_manager is not intialized");
00048     else recover_ = true;
00049 }
00050 
00051 void ControllerManagerLayer::handleShutdown(canopen::LayerStatus &status) {
00052     cm_.reset();
00053 }
00054 


canopen_motor_node
Author(s): Mathias Lüdtke
autogenerated on Sun Sep 3 2017 03:10:55