7 #include "RbMovableItem.h"
10 #include "RbMotorizedJoint.h"
11 #include "RbHingeLimit.h"
13 #include "RbRigidBody.h"
15 #include "RbFirmataPart.h"
16 #include "RbFirmataController.h"
22 namespace RobotIOControls
31 RbFirmataController::RbFirmataController()
41 m_EInitializedConnection = this->EInitialized.connect(boost::bind(&RbFirmataController::setupArduino,
this, _1));
45 RbFirmataController::~RbFirmataController()
51 {
Std_TraceMsg(0,
"Caught Error in desctructor of RbFirmataController\r\n",
"", -1,
false,
true);}
54 void RbFirmataController::ComPort(std::string strPort)
57 THROW_PARAM_ERROR(Rb_Err_lInvalidPort, Rb_Err_strInvalidPort,
"ComPort", strPort);
62 std::string RbFirmataController::ComPort() {
return m_strComPort;}
64 void RbFirmataController::BaudRate(
int iRate)
67 THROW_PARAM_ERROR(Rb_Err_lInvalidBaudRate, Rb_Err_strInvalidBaudRate,
"Baud rate", iRate);
71 int RbFirmataController::BaudRate() {
return m_iBaudRate;}
73 #pragma region DataAccesMethods
79 if(strType ==
"MOTORSENDTIME")
82 return RobotIOControl::GetDataPointer(strDataType);
89 if(RobotIOControl::SetData(strDataType, strValue,
false))
92 if(strType ==
"COMPORT")
97 else if(strType ==
"BAUDRATE")
99 BaudRate((
int) atoi(strValue.c_str()));
105 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
110 void RbFirmataController::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
112 RobotIOControl::QueryProperties(aryProperties);
114 aryProperties.Add(
new TypeProperty(
"ComPort", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
115 aryProperties.Add(
new TypeProperty(
"BaudRate", AnimatPropertyType::Integer, AnimatPropertyDirection::Set));
122 RobotIOControl::ResetSimulation();
128 bool RbFirmataController::OpenIO()
132 THROW_PARAM_ERROR(Rb_Err_lErrorConnectingToArduino, Rb_Err_strErrorConnectingToArduino,
"ComPort",
m_strComPort);
137 void RbFirmataController::CloseIO()
142 void RbFirmataController::ProcessIO()
148 std::cout <<
"Sending firmware version request\r\n";
155 boost::this_thread::sleep(boost::posix_time::microseconds(10));
157 sendFirmwareVersionRequest();
160 int iSendFirmwareCount=0;
163 if(!_firmwareReceived)
176 boost::this_thread::sleep(boost::posix_time::microseconds(300));
189 boost::this_thread::sleep(boost::posix_time::microseconds(1000));
201 if(_dynamixelMoveAdds > 0)
208 sendDynamixelSynchMoveExecute();
216 catch(CStdErrorInfo oError)
229 void RbFirmataController::setupArduino(
const int & version)
231 m_EInitializedConnection.disconnect();
286 void RbFirmataController::digitalPinChanged(
const int & pinNum)
299 void RbFirmataController::analogPinChanged(
const int & pinNum)
309 RobotIOControl::Load(oXml);
313 BaudRate(oXml.
GetChildInt(
"BaudRate", m_iBaudRate));
virtual void ResetSimulation()
Resets the simulation back to time 0.
Simulator * m_lpSim
The pointer to a Simulation.
virtual bool Paused()
Gets whether the Simulation is paused.
virtual bool IntoElem()
Goes into the next element where the cursor is located.
boost::interprocess::interprocess_condition m_WaitForIOSetupCond
Condition used to determine when the IO is setup.
bool m_bStopIO
Flags the thread processing loop to exit.
virtual Simulator * GetSimulator()
Gets the simulator pointer.
virtual int GetChildInt(std::string strElementName)
Gets an integer value from the element with the specified name.
virtual void StepIO()
This method is called from within the IO thread. It calls StepIO for each part.
Declares the vortex structure class.
virtual float * GetDataPointer(const std::string &strDataType)
Returns a float pointer to a data item of interest in this object.
Declares the vortex hinge class.
A standard xml manipulation class.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
bool m_bIOPaused
Is set to true once the IO loop is paused.
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 bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
unsigned long long m_lMotorSendStart
Tick to measure the the timing for sending motor commands.
bool m_bPauseIO
Set to true to pause the IO processing. Set back to false to resume it.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
float m_fltMotorSendTime
The time between when synchronous motor commands are sent.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
virtual void SetupIO()
This method is called after all connections to whatever control board have been made. It calls each parts SetupIO method. 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.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
std::string m_strComPort
Com port for the connection to the Arduino.
bool m_bIOThreadProcessing
True while the io thread processing loop is going on.
bool m_bSetupComplete
Set to true once the IO is setup correctly.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
bool m_bSetupStarted
Set to true once the IO begins its setup.