cob_controller_manager_node.cpp
Go to the documentation of this file.
00001 #include <cob_hardware_interface/cob_hwinterface_topics.h>
00002 #include <controller_manager/controller_manager.h>
00003 
00004 #include <boost/thread.hpp>
00005 
00006 
00007 class CobControllerManager
00008 {
00009   public:
00010     ~CobControllerManager()
00011     {
00012       //start_thread.join();
00013     }
00014     
00015     void initialize()
00016     {
00017       nh_p = ros::NodeHandle("~");
00018       //ROS_INFO("Namespace private %s", nh_p.getNamespace().c_str());
00019       //if (nh_p.hasParam("load_controller"))
00020       //{
00021         //nh_p.getParam("load_controller", load_controller);
00022         //ROS_INFO("Loading %s", load_controller.c_str());
00023       //}
00024       //else
00025       //{
00026         //ROS_ERROR("No parameter 'load_controller' specified. Aborting.");
00027         //return;
00028       //}
00029 
00030       cm = new controller_manager::ControllerManager(&robot);
00031       
00032       //start_thread = boost::thread(boost::bind(&CobControllerManager::start_controller, this, load_controller));
00033       
00034       update_rate = 100;  //[hz]
00035       timer = nh_p.createTimer(ros::Duration(1/update_rate), &CobControllerManager::update, this);
00036     }
00037     
00038     void update(const ros::TimerEvent& event)
00039     {
00040       ros::Duration period = event.current_real - event.last_real;
00041       
00042       robot.read();
00043       cm->update(event.current_real, period);
00044       
00045       robot.write();
00046     }
00047     
00048   private:
00049     ros::NodeHandle nh_p;
00050     
00051     CobHWInterfaceTopics robot;
00052     controller_manager::ControllerManager* cm;
00053     //std::string load_controller;
00054     
00055     ros::Timer timer;
00056     double update_rate;
00057     
00058     //boost::thread start_thread;
00059     
00060     //void start_controller(std::string load_controller)
00061     //{
00062       //bool success = false;
00063       //std::vector<std::string> start_controllers;
00064       //std::vector<std::string> stop_controllers;
00065       
00066       //start_controllers.push_back(load_controller);
00067       
00068       //success = cm->loadController(load_controller);
00069       
00070       //if(success)
00071       //{
00072         //success = cm->switchController(start_controllers, stop_controllers, 2);
00073       //}
00074       
00075       //if(success)
00076       //{
00077         //ROS_INFO("Controller should be running!");
00078       //}
00079       //else
00080         //ROS_ERROR("Failed to start controller!");
00081     //}
00082    
00083 };
00084 
00085 
00086 int main(int argc, char** argv)
00087 {
00088   ros::init(argc, argv, "cob_controller_manager_node");
00089   ros::AsyncSpinner spinner(0);
00090   spinner.start();
00091   
00092   CobControllerManager* ccm = new CobControllerManager();
00093   ccm->initialize();
00094 
00095   ros::waitForShutdown();
00096   delete ccm;
00097   return 0;
00098 }
00099 
00100 
00101 
00102 


cob_hardware_interface
Author(s): Felix Messmer
autogenerated on Sun Mar 1 2015 13:56:44