7 #include "RbMovableItem.h"
10 #include "RbMotorizedJoint.h"
11 #include "RbHingeLimit.h"
13 #include "RbRigidBody.h"
15 #include "RbFirmataPart.h"
16 #include "RbFirmataHingeServo.h"
17 #include "RbFirmataController.h"
23 namespace RobotIOControls
32 RbFirmataHingeServo::RbFirmataHingeServo()
37 m_bResetToStartPos =
false;
43 m_fltMaxAngle = RB_PI/2;
44 m_fltMinAngle = -RB_PI/2;
46 m_fltPosFloatToFPSlope = (m_iMaxAngle-m_iMinAngle+1)/(m_fltMaxAngle-m_fltMinAngle);
47 m_fltPosFloatToFPIntercept = m_iCenterAngle;
55 RbFirmataHingeServo::~RbFirmataHingeServo()
63 {
Std_TraceMsg(0,
"Caught Error in desctructor of RbFirmataHingeServo\r\n",
"", -1,
false,
true);}
66 int RbFirmataHingeServo::MaxPulse() {
return m_iMaxPulse;}
68 void RbFirmataHingeServo::MaxPulse(
int iPulse)
74 int RbFirmataHingeServo::MinPulse() {
return m_iMinPulse;}
76 void RbFirmataHingeServo::MinPulse(
int iPulse)
83 bool RbFirmataHingeServo::ResetToStartPos() {
return m_bResetToStartPos;}
85 void RbFirmataHingeServo::ResetToStartPos(
bool bVal) {m_bResetToStartPos = bVal;}
87 float RbFirmataHingeServo::ConvertPosFPToRad(
int iPos)
93 int RbFirmataHingeServo::ConvertPosRadToFP(
float fltPos)
95 int iPos = (m_fltPosFloatToFPSlope*fltPos) + m_fltPosFloatToFPIntercept;
109 if(iPos < m_iMinAngle) iPos = m_iMinAngle;
110 if(iPos > m_iMaxAngle) iPos = m_iMaxAngle;
113 if(m_iLastGoalPos == iPos)
116 m_iLastGoalPos = iPos;
118 std::cout <<
"Servo: " << iPos <<
"\r\n";
135 int iPos = ConvertPosRadToFP(fltPos);
140 #pragma region DataAccesMethods
149 return RobotPartInterface::GetDataPointer(strDataType);
156 if(strType ==
"MAXPULSE")
158 MaxPulse((
int) atoi(strValue.c_str()));
162 if(strType ==
"MINPULSE")
164 MinPulse((
int) atoi(strValue.c_str()));
168 if(strType ==
"RESETTOSTARTPOS")
174 return RobotPartInterface::SetData(strDataType, strValue, bThrowError);
177 void RbFirmataHingeServo::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
179 RobotPartInterface::QueryProperties(aryProperties);
181 aryProperties.Add(
new TypeProperty(
"MaxPulse", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
182 aryProperties.Add(
new TypeProperty(
"MinPulse", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
183 aryProperties.Add(
new TypeProperty(
"ResetToStartPos", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
190 RobotPartInterface::Initialize();
192 m_lpJoint =
dynamic_cast<MotorizedJoint *
>(m_lpPart);
201 if(m_bResetToStartPos)
204 IOValue(m_iCenterAngle);
217 RobotPartInterface::StepSimulation();
222 float fltSetPosition = m_lpJoint->JointPosition();
223 m_iIOValue = ConvertPosRadToFP(fltSetPosition);
232 void RbFirmataHingeServo::Load(CStdXml &oXml)
234 RobotPartInterface::Load(oXml);
237 MinPulse(oXml.GetChildInt(
"MinPulse", m_iMinPulse));
238 MaxPulse(oXml.GetChildInt(
"MaxPulse", m_iMaxPulse));
239 ResetToStartPos(oXml.GetChildBool(
"ResetToStartPos", m_bResetToStartPos));
virtual void StepSimulation()
Step the simulation for this object.
virtual bool InSimulation()
Used to determine if we are running in a simulation, or in a real control mode.
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...
Simulator * m_lpSim
The pointer to a Simulation.
virtual void Initialize()
Initializes this object.
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.
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
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 void SetGoalPosition_FP(int iPos)
Sets the fixed point value of the servo goal position. This is the exact value that will be sent to t...
Declares the vortex structure class.
Declares the vortex hinge class.
float m_fltPosFPToFloatSlope
The conversion factor to convert radians to FP angle position.
bool Std_ToBool(int iVal)
Converts a value toa bool.
bool Std_IsBelowMax(int iMaxVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is below a maximum value.
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.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
int m_iIOValue
This stores the temporary IO value to be used later in IO calculations.
virtual void SetGoalPosition(float fltPos)
Sets the floating point value of the servo goal position. This is the position in radians...
Classes for implementing the cm-labs vortex physics engine for AnimatLab.