diff --git a/src/liboncilla/nodes/L1L2.cpp b/src/liboncilla/nodes/L1L2.cpp index 55177cb..df51449 100644 --- a/src/liboncilla/nodes/L1L2.cpp +++ b/src/liboncilla/nodes/L1L2.cpp @@ -1,79 +1,91 @@ #include "L1L2.h" #include #include using namespace std; namespace rci{ namespace oncilla{ L1L2::L1L2(Synchronizer &s, const std::string &name) : ResourceNode(name) , Controlled() , Sensing() , PositionControlled() , PositionSensing() , TorqueControlled() , ImpedanceControlled() , d_synchronizer(s) { /// \todo add default value as setting this->_controlMode = modeJointPositionControl; this->_lastCommandedPosition = JointAngles::create(1,0.0); this->_latestJointPosition = JointAngles::create(2,0.0); } L1L2::~L1L2() { } std::string L1L2::print() const { ostringstream outstream(ostringstream::out); outstream.precision(3); // Precision when printing double values outstream << "" << endl; return outstream.str(); } + +void L1L2::setControlMode(ControlModePtr c){ + if(d_synchronizer.tooBusy()) { + throw UnavailableInterfaceError("Control mode could not be set once Synchronizer is started.", + "liboncilla","setControlMode","L1L2", + "Synchronizer is started by either start(), process() or processAsync()," + "you can stop() it first"); + } + return Controlled::setControlMode(c); +} + + bool L1L2::setJointImpedance(JointImpedancePtr ji){ if(d_synchronizer.tooBusy()) { throw UnavailableInterfaceError("Joint impedance could not be set once Synchronizer is started.", "liboncilla","setJointImpedance","L1L2", "Synchronizer is started by either start(), process() or processAsync()," "you can stop() it first"); } return ImpedanceControlled::setJointImpedance(ji); } bool L1L2::isConverged() const{ throw NotImplementedError("liboncilla","isConverged","L1L2"); } void L1L2::unsafeSetCommand(double value){ this->_lastCommandedPosition->setValue(0,value); } double L1L2::unsafeGetCommand() const{ return this->_lastCommandedPosition->asDouble(0); } double L1L2::unsafeGetMotorAxisPosition() const{ return this->_latestJointPosition->asDouble(MotorAxisIndex); } double L1L2::unsafeGetMagneticEncoderPosition() const{ return this->_latestJointPosition->asDouble(MagneticEncoderIndex); } void L1L2::unsafeUpdateMotorAxisPosition(double value){ this->_latestJointPosition->setValue(MotorAxisIndex,value); } void L1L2::unsafeUpdateMagneticEncoderPosition(double value){ this->_latestJointPosition->setValue(MagneticEncoderIndex,value); } } } diff --git a/src/liboncilla/nodes/L1L2.h b/src/liboncilla/nodes/L1L2.h index a40b90e..e1d71ff 100644 --- a/src/liboncilla/nodes/L1L2.h +++ b/src/liboncilla/nodes/L1L2.h @@ -1,85 +1,87 @@ #pragma once #include #include #include #include #include namespace rci{ namespace oncilla{ class Synchronizer; class L1L2; /** * Node class, representing the hip node of the quadruped robot. * * @todo In case of simulation, this node can also sense the power consumption. */ class L1L2: public rci::ResourceNode, public rci::Controlled, public rci::Sensing, public rci::PositionControlled, public rci::PositionSensing, // Two encoder values public rci::VelocityControlled, public rci::TorqueControlled, public rci::ImpedanceControlled { public: typedef boost::shared_ptr Ptr; const static unsigned int MotorAxisIndex = 0; const static unsigned int MagneticEncoderIndex = 1; /** * Special constructor to also link to webots */ L1L2(rci::oncilla::Synchronizer & s, const std::string & name = "Oncilla Hip"); virtual ~L1L2(); + virtual void setControlMode(ControlModePtr controlMode); + bool setJointImpedance(JointImpedancePtr ); bool isConverged() const; /** * Print */ std::string print() const; protected : void unsafeSetCommand(double value); double unsafeGetCommand() const; double unsafeGetMotorAxisPosition() const; double unsafeGetMagneticEncoderPosition() const; void unsafeUpdateMotorAxisPosition(double value); void unsafeUpdateMagneticEncoderPosition(double value); private: /** * Reference to OncillaSynchronizer * @todo This is a dangerous reference which will become invalid as soon as * OncillaSynchronizer gets deleted outside. */ rci::oncilla::Synchronizer & d_synchronizer; }; typedef L1L2 L1; typedef L1L2 L2; } }