7 #include "RbMovableItem.h"
10 #include "RbMotorizedJoint.h"
11 #include "RbHingeLimit.h"
13 #include "RbRigidBody.h"
15 #include "RbDynamixelUSB.h"
16 #include "RbDynamixelUSBServo.h"
19 #define DYN_LENGTH (3)
20 #define DYN_INSTRUCTION (4)
21 #define DYN_ERRBIT (4)
22 #define DYN_PARAMETER (5)
23 #define DYN_DEFAULT_BAUDNUMBER (1)
29 namespace RobotIOControls
31 namespace DynamixelUSB
38 RbDynamixelUSBServo::RbDynamixelUSBServo()
45 RbDynamixelUSBServo::~RbDynamixelUSBServo()
51 {
Std_TraceMsg(0,
"Caught Error in desctructor of RbDynamixelUSBServo\r\n",
"", -1,
false,
true);}
54 void RbDynamixelUSBServo::IOComponentID(
int iID)
57 RobotPartInterface::IOComponentID(iID);
61 void RbDynamixelUSBServo::UpdateAllParamsCount(
int iVal)
71 void RbDynamixelUSBServo::UpdateQueueIndex(
int iVal)
77 void RbDynamixelUSBServo::SetRegister(
unsigned char reg,
unsigned char length,
unsigned int value)
80 m_lpParentUSB->SetRegister(
m_iServoID, reg, length, value);
83 int RbDynamixelUSBServo::GetRegister(
unsigned char reg,
unsigned char length)
86 return m_lpParentUSB->GetRegister(
m_iServoID, reg, length);
91 #pragma region DataAccesMethods
95 float *fltVal = RbDynamixelServo::GetDataPointer(strDataType);
99 return RobotPartInterface::GetDataPointer(strDataType);
106 if(RobotPartInterface::SetData(strDataType, strValue,
false))
109 if(strType ==
"UPDATEALLPARAMSCOUNT")
111 UpdateAllParamsCount((
int) atoi(strValue.c_str()));
115 if(strType ==
"UPDATEQUEUEINDEX")
117 UpdateQueueIndex((
int) atoi(strValue.c_str()));
121 if(RbDynamixelServo::SetData(strDataType, strValue))
126 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
131 void RbDynamixelUSBServo::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
133 RobotPartInterface::QueryProperties(aryProperties);
134 RbDynamixelServo::QueryProperties(aryProperties);
136 aryProperties.Add(
new TypeProperty(
"UpdateAllParamsCount", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
137 aryProperties.Add(
new TypeProperty(
"UpdateQueueIndex", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
142 void RbDynamixelUSBServo::MicroSleep(
unsigned int iTime)
148 Simulator *RbDynamixelUSBServo::GetSimulator()
155 return RbDynamixelServo::QuantizeServoPosition(fltPos);
160 return RbDynamixelServo::QuantizeServoVelocity(fltVel);
167 RobotPartInterface::Initialize();
170 m_lpParentUSB =
dynamic_cast<RbDynamixelUSB *
>(m_lpParentIOControl);
191 void RbDynamixelUSBServo::AddMotorUpdate(
int iPos,
int iSpeed)
203 unsigned long long lStepStartTick =
m_lpSim->GetTimerTick();
219 unsigned long long lEndStartTick =
m_lpSim->GetTimerTick();
220 m_fltStepIODuration =
m_lpSim->TimerDiff_m(lStepStartTick, lEndStartTick);
230 void RbDynamixelUSBServo::StepSimulation()
234 RobotPartInterface::StepSimulation();
235 RbDynamixelServo::StepSimulation();
242 RbDynamixelServo::ResetSimulation();
247 RobotPartInterface::Load(oXml);
248 RbDynamixelServo::Load(oXml);
265 std::vector<int> aryData;
266 unsigned long long lStart = GetSimulator()->GetTimerTick(), lEnd;
272 m_iLoad = dxl_makeword(aryData[4], aryData[5]);
283 lEnd = GetSimulator()->GetTimerTick();
296 std::vector<int> aryData;
297 unsigned long long lStart = GetSimulator()->GetTimerTick(), lEnd;
303 m_iLoad = dxl_makeword(aryData[4], aryData[5]);
310 lEnd = GetSimulator()->GetTimerTick();
331 dxl_set_txpacket_id(
id);
332 dxl_set_txpacket_instruction(INST_READ);
333 dxl_set_txpacket_parameter(0, address);
334 dxl_set_txpacket_parameter(1, length);
335 dxl_set_txpacket_length(4);
339 int CommStatus = dxl_get_result();
347 for(
int iIdx=0; iIdx<length; iIdx++)
349 int iParam = dxl_get_rxpacket_parameter(iIdx);
350 aryData.push_back(iParam);
366 if(dxl_get_rxpacket_error(ERRBIT_VOLTAGE) == 1)
367 return "Input voltage error!";
369 if(dxl_get_rxpacket_error(ERRBIT_ANGLE) == 1)
370 return "Angle limit error!\n";
372 if(dxl_get_rxpacket_error(ERRBIT_OVERHEAT) == 1)
373 return "Overheat error!\n";
375 if(dxl_get_rxpacket_error(ERRBIT_RANGE) == 1)
376 return "Out of range error!\n";
378 if(dxl_get_rxpacket_error(ERRBIT_CHECKSUM) == 1)
379 return "Checksum error!\n";
381 if(dxl_get_rxpacket_error(ERRBIT_OVERLOAD) == 1)
382 return "Overload error!\n";
384 if(dxl_get_rxpacket_error(ERRBIT_INSTRUCTION) == 1)
385 return "Instruction code error!\n";
387 return "Unknown error";
390 std::string RbDynamixelUSBServo::GetCommStatus(
int CommStatus)
395 return "COMM_TXFAIL: Failed transmit instruction packet!";
399 return "COMM_TXERROR: Incorrect instruction packet!";
403 return "COMM_RXFAIL: Failed get status packet from device!";
407 return "COMM_RXWAITING: Now recieving status packet!";
411 return "COMM_RXTIMEOUT: There is no status packet!";
415 return "COMM_RXCORRUPT: Incorrect status packet!";
419 return "This is unknown error code!";
virtual float ConvertFPVelocity(int iVel)
Gets the floating point value of the servo actual velocity. The fixed point value is retrieved from t...
virtual bool InSimulation()
Used to determine if we are running in a simulation, or in a real control mode.
virtual void ReadAllParams()
Reads all major data parameters from the servo in one read packet. This include present position...
virtual void ShutdownIO()
This method is called just before the IO thread is closed down. It gives the IO objects a chance to d...
float m_fltLowLimit
Low constraint limit value.
Simulator * m_lpSim
The pointer to a Simulation.
virtual float QuantizeServoPosition(float fltPos)
If this is a servo controller interface then it will take a continuous positon and return back a vali...
virtual bool IntoElem()
Goes into the next element where the cursor is located.
int m_iVoltage
The current voltage that was last read in for this servo.
virtual float ConvertFPLoad(int iLoad)
Gets the floating point value of the servo load. The fixed point value is retrieved from the servo an...
int m_iLastGoalVelocity
Keeps track of the last servo goal velocity that we set.
int m_iServoID
ID used for communications with this servo.
int m_iNextGoalVelocity
This is the goal velocity that you would like to use in the next time step.
int m_iLastGoalPos
Keeps track of the last servo goal position that we set.
virtual void Initialize()
Initializes this object.
virtual int GetChildInt(std::string strElementName)
Gets an integer value from the element with the specified name.
float m_fltHiLimit
Hi constraint limit value.
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
float m_fltPresentPos
The current position that was last read in for this servo.
int m_iUpdateIdx
Keeps track of the number of update loops that have occurred since we last updated all params...
int m_iTemperature
The current temperature that was last read in for this servo.
virtual int ServoID()
Gets the servo ID being used for communications.
int m_iPresentPos
The current position that was last read in for this servo.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
virtual void ShutdownMotor()
Shuts the motor down cleanly and ensures that it is not continuing to move after processing has stopp...
Declares the vortex structure class.
virtual void StepIO(int iPartIdx)
This method is used to send/recieve the actual IO. This will often be in a seperate thread than the S...
float m_fltReadParamTime
The time taken to read the params of this motor for the current step.
int m_iNextGoalPos
This is the goal position that you would like to use in the next time step.
Declares the vortex hinge class.
A standard xml manipulation class.
int m_iLoad
The current load that was last read in for this servo.
virtual void ReadKeyParams()
Reads only the key data parameters from the servo in one read packet. This include present position a...
float m_fltPresentVelocity
The current velocity that was last read in for this servo.
MotorizedJoint * m_lpMotorJoint
Pointer to an associated motorized joint.
float m_fltLoad
The current load that was last read in for this servo.
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
virtual void ResetSimulation()
Resets the simulation back to time 0.
virtual void SetMaxSimPos(float fltVal)
Sets the maximum position that the simulation will allow for this joint in radians.
virtual void SetMinSimPos(float fltVal)
Sets the minimum position that the simulation will allow for this joint in radians.
virtual bool dxl_read_block(int id, int address, int length, std::vector< int > &aryData)
Reads an entire block of data from a dynamixel servo. This is used to allow us to read back a number ...
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
float m_fltVoltage
The current voltage that was last read in for this servo.
int m_iUpdateAllParamsCount
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual std::string GetErrorCode()
Checks the error code and returns an associated error message.
virtual void InitMotorData()
Initializes the internal data on position and velocity from the actual motor.
virtual void SetupIO()
This method is called after all connections to whatever control board have been made. It is meant to be used to setup connection information specific to this part. For example, We connect to a Firmata microcontroller like an Arduino, and then do a setup that could take some time. We should not attempt to setup any of the pins until after the board itself has been setup. After that we need to loop through and setup all the parts. That is what this method is for.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
virtual float QuantizeServoVelocity(float fltVel)
If this is a servo controller interface then it will take a continuous velocity and return back a val...
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
float m_fltTemperature
The current temperature that was last read in for this servo.
int m_iPresentVelocity
The current velocity that was last read in for this servo.
virtual void ResetSimulation()
Resets the simulation back to time 0.