7 #include "RbMovableItem.h"
10 #include "RbMotorizedJoint.h"
11 #include "RbHingeLimit.h"
13 #include "RbRigidBody.h"
15 #include "RbXBeeCommander.h"
21 namespace RobotIOControls
28 RbXBeeCommander::RbXBeeCommander()
53 RbXBeeCommander::~RbXBeeCommander()
59 {
Std_TraceMsg(0,
"Caught Error in desctructor of RbXBeeCommander\r\n",
"", -1,
false,
true);}
62 void RbXBeeCommander::CreateDataIDMap()
81 void RbXBeeCommander::Port(std::string strPort)
86 std::string RbXBeeCommander::Port() {
return m_strPort;}
88 void RbXBeeCommander::BaudRate(
int iRate)
94 int RbXBeeCommander::BaudRate() {
return m_iBaudRate;}
96 #pragma region DataAccesMethods
105 if(strType ==
"PORT")
111 else if(strType ==
"BAUDRATE")
113 BaudRate((
int) atoi(strValue.c_str()));
119 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
124 void RbXBeeCommander::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
128 aryProperties.Add(
new TypeProperty(
"Port", AnimatPropertyType::String, AnimatPropertyDirection::Set));
129 aryProperties.Add(
new TypeProperty(
"BaudRate", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
130 aryProperties.Add(
new TypeProperty(
"ChangeSimStepCount", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
132 aryProperties.Add(
new TypeProperty(
"WalkV", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
133 aryProperties.Add(
new TypeProperty(
"WalkVStart", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
134 aryProperties.Add(
new TypeProperty(
"WalkVStop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
136 aryProperties.Add(
new TypeProperty(
"WalkH", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
137 aryProperties.Add(
new TypeProperty(
"WalkHStart", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
138 aryProperties.Add(
new TypeProperty(
"WalkHStop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
140 aryProperties.Add(
new TypeProperty(
"LookV", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
141 aryProperties.Add(
new TypeProperty(
"LookVStart", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
142 aryProperties.Add(
new TypeProperty(
"LookVStop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
144 aryProperties.Add(
new TypeProperty(
"LookH", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
145 aryProperties.Add(
new TypeProperty(
"LookHStart", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
146 aryProperties.Add(
new TypeProperty(
"LookHStop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
148 aryProperties.Add(
new TypeProperty(
"Pan", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
149 aryProperties.Add(
new TypeProperty(
"PanStart", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
150 aryProperties.Add(
new TypeProperty(
"PanStop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
152 aryProperties.Add(
new TypeProperty(
"Tilt", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
153 aryProperties.Add(
new TypeProperty(
"TiltStart", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
154 aryProperties.Add(
new TypeProperty(
"TiltStop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
156 aryProperties.Add(
new TypeProperty(
"R1", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
157 aryProperties.Add(
new TypeProperty(
"R1Start", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
158 aryProperties.Add(
new TypeProperty(
"R1Stop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
160 aryProperties.Add(
new TypeProperty(
"R2", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
161 aryProperties.Add(
new TypeProperty(
"R2Start", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
162 aryProperties.Add(
new TypeProperty(
"R2Stop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
164 aryProperties.Add(
new TypeProperty(
"R3", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
165 aryProperties.Add(
new TypeProperty(
"R3Start", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
166 aryProperties.Add(
new TypeProperty(
"R3Stop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
168 aryProperties.Add(
new TypeProperty(
"L4", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
169 aryProperties.Add(
new TypeProperty(
"L4Start", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
170 aryProperties.Add(
new TypeProperty(
"L4Stop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
172 aryProperties.Add(
new TypeProperty(
"L5", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
173 aryProperties.Add(
new TypeProperty(
"L5Start", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
174 aryProperties.Add(
new TypeProperty(
"L5Stop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
176 aryProperties.Add(
new TypeProperty(
"L6", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
177 aryProperties.Add(
new TypeProperty(
"L6Start", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
178 aryProperties.Add(
new TypeProperty(
"L6Stop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
180 aryProperties.Add(
new TypeProperty(
"RT", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
181 aryProperties.Add(
new TypeProperty(
"RTStart", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
182 aryProperties.Add(
new TypeProperty(
"RTStop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
184 aryProperties.Add(
new TypeProperty(
"LT", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
185 aryProperties.Add(
new TypeProperty(
"LTStart", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
186 aryProperties.Add(
new TypeProperty(
"LTStop", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
207 for(
int iIndex=0; iIndex<iCount; iIndex++)
216 bool RbXBeeCommander::OpenIO()
221 THROW_PARAM_ERROR(Rb_Err_lFailedUartSBeeConnection, Rb_Err_strFailedUartSBeeConnection,
"ComPort",
m_strPort);
227 void RbXBeeCommander::CloseIO()
232 void RbXBeeCommander::ResetData()
234 RemoteControl::ResetData();
247 if(!m_Port.isInitialized())
254 void RbXBeeCommander::WaitForThreadNotifyReady()
256 RobotIOControl::WaitForThreadNotifyReady();
259 boost::this_thread::sleep(boost::posix_time::microseconds(10000));
271 while(m_Port.available() > 0 && !bFound)
275 if(m_Port.readByte() == 0xff)
283 vals[index] = (
unsigned char) m_Port.readByte();
284 if(vals[index] != 0xff)
286 checksum += (int) vals[index];
294 vals[index] = (
unsigned char) m_Port.readByte();
295 checksum += (int) vals[index];
299 if(checksum%256 != 255)
307 if((status&0x01) > 0)
309 SetDataValue(BUT_ID_WALKV, (
float) ((
signed char)( (
int)vals[0]-128 )));
310 SetDataValue(BUT_ID_WALKH, (
float) ((
signed char)( (
int)vals[1]-128 ) + 1));
311 SetDataValue(BUT_ID_LOOKV, (
float) ((
signed char)( (
int)vals[2]-128 )));
312 SetDataValue(BUT_ID_LOOKH, (
float) ((
signed char)( (
int)vals[3]-128 )));
316 SetDataValue(BUT_ID_LOOKV, (
float) ((
signed char)( (
int)vals[0]-128 )));
317 SetDataValue(BUT_ID_LOOKH, (
float) ((
signed char)( (
int)vals[1]-128 )));
318 SetDataValue(BUT_ID_WALKV, (
float) ((
signed char)( (
int)vals[2]-128 )));
319 SetDataValue(BUT_ID_WALKH, (
float) ((
signed char)( (
int)vals[3]-128 ) - 1));
322 SetDataValue(BUT_ID_PAN, (
float) ((vals[0]<<8) + vals[1]));
323 SetDataValue(BUT_ID_TILT, (
float) ((vals[2]<<8) + vals[3]));
328 SetDataValue(BUT_ID_R1, (
m_iButtons & BUT_R1));
329 SetDataValue(BUT_ID_R2, (
m_iButtons & BUT_R2));
330 SetDataValue(BUT_ID_R3, (
m_iButtons & BUT_R3));
331 SetDataValue(BUT_ID_L4, (
m_iButtons & BUT_L4));
332 SetDataValue(BUT_ID_L5, (
m_iButtons & BUT_L5));
333 SetDataValue(BUT_ID_L6, (
m_iButtons & BUT_L6));
334 SetDataValue(BUT_ID_RT, (
m_iButtons & BUT_RT));
335 SetDataValue(BUT_ID_LT, (
m_iButtons & BUT_LT));
346 CheckStartedStopped();
353 AnimatSim::Robotics::RemoteControl::Load(oXml);
CStdPtrArray< RemoteControlLinkage > m_aryLinks
virtual bool InSimulation()
Used to determine if we are running in a simulation, or in a real control mode.
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 QueryProperties(CStdPtrArray< TypeProperty > &aryProperties)
Queries this object for a list of properties that can be changed using SetData.
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
Simulator * m_lpSim
The pointer to a Simulation.
virtual void StepIO()
This method is called from within the IO thread. It calls StepIO for each part.
virtual bool Paused()
Gets whether the Simulation is paused.
virtual bool IntoElem()
Goes into the next element where the cursor is located.
virtual void ShutdownIO()
This method is called just before the IO thread is closed down. It gives the IO objects a chance to d...
virtual int GetChildInt(std::string strElementName)
Gets an integer value from the element with the specified name.
bool Std_IsAboveMin(int iMinVal, int iVal, bool bThrowError, std::string strParamName, bool bInclusiveLimit)
Tests if a number is above a minimum value.
int m_iBaudRate
The baud rate of communications for this XBee.
Declares the vortex structure class.
Declares the vortex hinge class.
A standard xml manipulation class.
virtual void StepIO()
This method is called from within the IO thread. It calls StepIO for each part.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
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.
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
CStdMap< std::string, int > m_aryDataIDMap
Used to map property names to IDs when UseRemoteDataTypes is true.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual void SimStarting()
Called just before the simulation starts.
virtual void Initialize()
Initializes this object.
bool m_bSetupComplete
Set to true once the IO is setup correctly.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
std::string m_strPort
The serial port this Xbee communicates on.
unsigned char m_iButtons
buttons are 0 or 1 (PRESSED), and bitmapped