00001 #ifndef YOUBOT_YOUBOTJOINT_H 00002 #define YOUBOT_YOUBOTJOINT_H 00003 00004 /**************************************************************** 00005 * 00006 * Copyright (c) 2011 00007 * All rights reserved. 00008 * 00009 * Hochschule Bonn-Rhein-Sieg 00010 * University of Applied Sciences 00011 * Computer Science Department 00012 * 00013 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00014 * 00015 * Author: 00016 * Jan Paulus, Nico Hochgeschwender, Michael Reckhaus, Azamat Shakhimardanov 00017 * Supervised by: 00018 * Gerhard K. Kraetzschmar 00019 * 00020 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00021 * 00022 * This sofware is published under a dual-license: GNU Lesser General Public 00023 * License LGPL 2.1 and BSD license. The dual-license implies that users of this 00024 * code may choose which terms they prefer. 00025 * 00026 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00027 * 00028 * Redistribution and use in source and binary forms, with or without 00029 * modification, are permitted provided that the following conditions are met: 00030 * 00031 * * Redistributions of source code must retain the above copyright 00032 * notice, this list of conditions and the following disclaimer. 00033 * * Redistributions in binary form must reproduce the above copyright 00034 * notice, this list of conditions and the following disclaimer in the 00035 * documentation and/or other materials provided with the distribution. 00036 * * Neither the name of the Hochschule Bonn-Rhein-Sieg nor the names of its 00037 * contributors may be used to endorse or promote products derived from 00038 * this software without specific prior written permission. 00039 * 00040 * This program is free software: you can redistribute it and/or modify 00041 * it under the terms of the GNU Lesser General Public License LGPL as 00042 * published by the Free Software Foundation, either version 2.1 of the 00043 * License, or (at your option) any later version or the BSD license. 00044 * 00045 * This program is distributed in the hope that it will be useful, 00046 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00047 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00048 * GNU Lesser General Public License LGPL and the BSD license for more details. 00049 * 00050 * You should have received a copy of the GNU Lesser General Public 00051 * License LGPL and BSD license along with this program. 00052 * 00053 ****************************************************************/ 00054 #include <vector> 00055 #include <sstream> 00056 #include <cmath> 00057 #include <boost/thread.hpp> 00058 #include <boost/scoped_ptr.hpp> 00059 #include "generic/Logger.hpp" 00060 #include "generic/Units.hpp" 00061 #include "generic/Time.hpp" 00062 #include "generic/Exceptions.hpp" 00063 #include "generic-joint/Joint.hpp" 00064 #include "generic-joint/JointData.hpp" 00065 #include "youbot/YouBotJointStorage.hpp" 00066 #include "youbot/ProtocolDefinitions.hpp" 00067 #include "youbot/YouBotJointParameter.hpp" 00068 #include "youbot/YouBotJointParameterPasswordProtected.hpp" 00069 #include "youbot/YouBotSlaveMsg.hpp" 00070 #include "youbot/YouBotSlaveMailboxMsg.hpp" 00071 #include "youbot/EthercatMaster.hpp" 00072 #include "youbot/EthercatMasterInterface.hpp" 00073 #include "youbot/EthercatMasterWithThread.hpp" 00074 #include "youbot/EthercatMasterWithoutThread.hpp" 00075 #include "youbot/JointTrajectoryController.hpp" 00076 #include "youbot/JointLimitMonitor.hpp" 00077 00078 namespace youbot { 00079 00080 /////////////////////////////////////////////////////////////////////////////// 00081 /// youBot joint for the base and the manipulator. 00082 /// Every motor, encoder, transmition combination of the youBot base or manipulator is a YouBotJoint 00083 /////////////////////////////////////////////////////////////////////////////// 00084 class YouBotJoint : public Joint { 00085 public: 00086 YouBotJoint(const unsigned int jointNo, const std::string& configFilePath = "../config/"); 00087 00088 ~YouBotJoint(); 00089 00090 00091 private: 00092 YouBotJoint(const YouBotJoint & source); 00093 00094 YouBotJoint & operator=(const YouBotJoint & source); 00095 00096 00097 protected: 00098 virtual void setConfigurationParameter(const JointParameter& parameter); 00099 00100 virtual void getConfigurationParameter(JointParameter& parameter); 00101 00102 00103 public: 00104 virtual void getConfigurationParameter(YouBotJointParameterReadOnly& parameter); 00105 00106 virtual void getConfigurationParameter(YouBotJointParameter& parameter); 00107 00108 virtual void setConfigurationParameter(const YouBotJointParameter& parameter); 00109 00110 virtual void getConfigurationParameter(JointName& parameter); 00111 00112 virtual void setConfigurationParameter(const JointName& parameter); 00113 00114 virtual void getConfigurationParameter(GearRatio& parameter); 00115 00116 virtual void setConfigurationParameter(const GearRatio& parameter); 00117 00118 virtual void getConfigurationParameter(EncoderTicksPerRound& parameter); 00119 00120 virtual void setConfigurationParameter(const EncoderTicksPerRound& parameter); 00121 00122 virtual void setConfigurationParameter(const CalibrateJoint& parameter); 00123 00124 virtual void setConfigurationParameter(const InverseMovementDirection& parameter); 00125 00126 virtual void getConfigurationParameter(InverseMovementDirection& parameter); 00127 00128 virtual void setConfigurationParameter(const JointLimits& parameter); 00129 00130 virtual void getConfigurationParameter(JointLimits& parameter); 00131 00132 virtual void getConfigurationParameter(JointLimitsRadian& parameter); 00133 00134 /// commutation method for firmware 1.48 and below 00135 virtual void setConfigurationParameter(const InitializeJoint& parameter); 00136 00137 virtual void getConfigurationParameter(FirmwareVersion& parameter); 00138 00139 ///this method should be only used if you know what you are doing 00140 virtual void setConfigurationParameter(const YouBotSlaveMailboxMsg& parameter); 00141 00142 ///this method should be only used if you know what you are doing 00143 virtual void getConfigurationParameter(YouBotSlaveMailboxMsg& parameter); 00144 00145 virtual void getConfigurationParameter(TorqueConstant& parameter); 00146 00147 virtual void setConfigurationParameter(const TorqueConstant& parameter); 00148 00149 ///stores the joint parameter permanent in the EEPROM of the motor contoller 00150 ///Attentions: The EEPROM has only a finite number of program-erase cycles 00151 void storeConfigurationParameterPermanent(const YouBotJointParameter& parameter); 00152 00153 /// Restores the joint parameter from the EEPROM. 00154 void restoreConfigurationParameter(YouBotJointParameter& parameter); 00155 00156 00157 protected: 00158 virtual void setData(const JointDataSetpoint& data); 00159 00160 virtual void getData(JointData& data); 00161 00162 00163 public: 00164 ///commands a position or angle to one joint 00165 ///@param data the to command position 00166 virtual void setData(const JointAngleSetpoint& data); 00167 00168 ///commands a encoder value (position) to one joint 00169 ///@param data the to command encoder value 00170 virtual void setData(const JointEncoderSetpoint& data); 00171 00172 ///gets the position or angle of one joint which have been calculated from the actual encoder value 00173 ///@param data returns the angle by reference 00174 virtual void getData(JointSensedAngle& data); 00175 00176 ///commands a velocity to one joint 00177 ///@param data the to command velocity 00178 virtual void setData(const JointVelocitySetpoint& data); 00179 00180 ///gets the velocity of one joint 00181 ///@param data returns the velocity by reference 00182 virtual void getData(JointSensedVelocity& data); 00183 00184 ///gets the velocity in round per minute of one joint 00185 ///@param data returns the velocity by reference 00186 virtual void getData(JointSensedRoundsPerMinute& data); 00187 00188 ///sets the velocity in round per minute to one joint 00189 ///@param data the setpoint velocity 00190 virtual void setData(const JointRoundsPerMinuteSetpoint& data); 00191 00192 ///gets the motor current of one joint which have been measured by a hal sensor 00193 ///@param data returns the actual motor current by reference 00194 virtual void getData(JointSensedCurrent& data); 00195 00196 ///commands a current to one joint 00197 ///@param data the to command current 00198 virtual void setData(const JointCurrentSetpoint& data); 00199 00200 ///gets the encoder ticks of one joint 00201 ///@param data returns the ticks by reference 00202 virtual void getData(JointSensedEncoderTicks& data); 00203 00204 ///sets the output part of a EtherCAT slave message 00205 ///this methode should be only used if you know what you are doing 00206 ///@param data output part of a EtherCAT slave message 00207 virtual void setData(const SlaveMessageOutput& data); 00208 00209 ///gets the input and ouput part of a EtherCAT slave message 00210 ///this methode should be only used if you know what you are doing 00211 ///@param data returns the sensor values by reference 00212 virtual void getData(YouBotSlaveMsg& data); 00213 00214 ///commands a torque to one joint 00215 ///@param data the to command torque 00216 virtual void setData(const JointTorqueSetpoint& data); 00217 00218 ///gets the motor torque of one joint which have been calculated from the current 00219 ///@param data returns the actual motor torque by reference 00220 virtual void getData(JointSensedTorque& data); 00221 00222 ///gets the target or setpoint position of one joint (only firmware 2.0 or higher) 00223 ///@param data returns the angle by reference 00224 virtual void getData(JointAngleSetpoint& data); 00225 00226 ///gets the target or setpoint velocity of one joint (only firmware 2.0 or higher) 00227 ///@param data returns the velocity by reference 00228 virtual void getData(JointVelocitySetpoint& data); 00229 00230 ///gets the motor current target or setpoint of one joint (only firmware 2.0 or higher) 00231 ///@param data returns the motor current by reference 00232 virtual void getData(JointCurrentSetpoint& data); 00233 00234 ///gets the ramp generator velocity of one joint (only firmware 2.0 or higher) 00235 ///@param data returns the velocity by reference 00236 virtual void getData(JointRampGeneratorVelocity& data); 00237 00238 void getUserVariable(const unsigned int index, int& data); 00239 00240 void setUserVariable(const unsigned int index, const int data); 00241 00242 /// Returns the status messages for the motor controller. 00243 virtual void getStatus(std::vector<std::string>& statusMessages); 00244 00245 /// Returns the status messages as status flags for the motor controller. The status flag bits are assigned like this: 00246 /// 0: Overcurrent 00247 /// 1: Undervoltage 00248 /// 2: Overvoltage 00249 /// 3: Overtemperature 00250 /// 4: Motor halted 00251 /// 5: Hall error flag 00252 /// 6: --- 00253 /// 7: --- 00254 /// 8: PWM mode active 00255 /// 9: Velocity mode active 00256 /// 10: Position mode active 00257 /// 11: Torque mode active 00258 /// 12: --- 00259 /// 13: --- 00260 /// 14: Position end flag 00261 /// 15: Module initialized 00262 /// 16: EtherCAT timeout flag 00263 /// 17: I2t exceeded flag 00264 virtual void getStatus(unsigned int& statusFlags); 00265 00266 /// set the encoder values of the joint to zero. This postion will be the new reference. 00267 void setEncoderToZero(); 00268 00269 void noMoreAction(); 00270 00271 void stopJoint(); 00272 00273 unsigned int getJointNumber(); 00274 00275 00276 private: 00277 void parseYouBotErrorFlags(const YouBotSlaveMsg& messageBuffer); 00278 00279 void parseMailboxStatusFlags(const YouBotSlaveMailboxMsg& mailboxMsg); 00280 00281 bool retrieveValueFromMotorContoller(YouBotSlaveMailboxMsg& message); 00282 00283 bool setValueToMotorContoller(const YouBotSlaveMailboxMsg& mailboxMsg); 00284 00285 00286 public: 00287 JointTrajectoryController trajectoryController; 00288 00289 00290 private: 00291 EthercatMasterInterface* ethercatMaster; 00292 00293 bool positionReferenceToZero; 00294 00295 unsigned int timeTillNextMailboxUpdate; 00296 00297 unsigned int mailboxMsgRetries; 00298 00299 YouBotJointStorage storage; 00300 00301 YouBotSlaveMsg messageBuffer; 00302 00303 quantity<si::angular_velocity> lastVelocity; 00304 00305 quantity<plane_angle> lastPosition; 00306 00307 boost::scoped_ptr<JointLimitMonitor> limitMonitor; 00308 00309 }; 00310 00311 } // namespace youbot 00312 #endif