FakeServo.cpp
Go to the documentation of this file.
00001 /*
00002  * FakeServo.cpp
00003  *
00004  *  Created on: 22-09-2010
00005  *      Author: Konrad Banachowicz
00006  */
00007 
00008 #include <ocl/Component.hpp>
00009 
00010 #include "FakeServo.h"
00011 
00012 FakeServo::FakeServo(const std::string& name) :
00013     RTT::TaskContext(name, PreOperational), number_of_joints_prop_("number_of_joints", "", 0)
00014 {
00015 
00016   this->ports()->addPort("JointPositionCommand", cmd_jnt_pos_port_);
00017   this->ports()->addPort("JointPosition", msr_jnt_pos_port_);
00018   this->ports()->addPort("DesiredJointPosition", des_jnt_pos_port_);
00019   this->ports()->addPort("CommandPeriod", command_period_port_);
00020 
00021   this->addProperty(number_of_joints_prop_);
00022 }
00023 
00024 FakeServo::~FakeServo()
00025 {
00026 
00027 }
00028 
00029 bool FakeServo::configureHook()
00030 {
00031   if ((number_of_joints_ = number_of_joints_prop_.get()) == 0)
00032     return false;
00033   initial_pos_.resize(number_of_joints_);
00034   for (unsigned int i = 0; i < number_of_joints_; i++)
00035   {
00036     RTT::base::PropertyBase* prop;
00037     prop = this->getProperty(std::string("joint") + (char) (i + 48) + "_position");
00038     if(prop)
00039     {
00040       initial_pos_[i] = ((RTT::Property<double>*) prop)->get();
00041     } else
00042     {
00043       initial_pos_[i] = 0.0;
00044     }
00045   }
00046 
00047   jnt_pos_.resize(number_of_joints_);
00048   return true;
00049 }
00050 
00051 bool FakeServo::startHook()
00052 {
00053   jnt_pos_ = initial_pos_;
00054 
00055   dt_ = this->getPeriod();
00056 
00057   return true;
00058 }
00059 
00060 void FakeServo::updateHook()
00061 {
00062   cmd_jnt_pos_port_.read(jnt_pos_);
00063 
00064   des_jnt_pos_port_.write(jnt_pos_);
00065   msr_jnt_pos_port_.write(jnt_pos_);
00066   
00067   command_period_port_.write(dt_);
00068   
00069 }
00070 
00071 ORO_CREATE_COMPONENT( FakeServo )


fake_servo
Author(s): Konrad Banachowicz
autogenerated on Mon Oct 6 2014 03:09:59