AnimatLab  2
Test
RbFirmataPWMOutput.cpp
1 // RbFirmataPWMOutput.cpp: implementation of the RbFirmataPWMOutput class.
2 //
4 
5 #include "StdAfx.h"
6 #include <stdarg.h>
7 #include "RbMovableItem.h"
8 #include "RbBody.h"
9 #include "RbJoint.h"
10 #include "RbMotorizedJoint.h"
11 #include "RbHingeLimit.h"
12 #include "RbHinge.h"
13 #include "RbRigidBody.h"
14 #include "RbStructure.h"
15 #include "RbFirmataPart.h"
16 #include "RbFirmataPWMOutput.h"
17 #include "RbFirmataController.h"
18 
19 namespace RoboticsAnimatSim
20 {
21  namespace Robotics
22  {
23  namespace RobotIOControls
24  {
25  namespace Firmata
26  {
27 
29 // Construction/Destruction
31 
32 RbFirmataPWMOutput::RbFirmataPWMOutput()
33 {
34 }
35 
36 RbFirmataPWMOutput::~RbFirmataPWMOutput()
37 {
38 }
39 
41 {
42  if(!m_lpSim->InSimulation() && m_lpFirmata)
43  m_lpFirmata->sendDigitalPinMode(m_iIOComponentID, ARD_PWM);
44 }
45 
46 void RbFirmataPWMOutput::StepIO(int iPartIdx)
47 {
48  if(!m_lpSim->InSimulation())
49  {
50  if(m_iIOValue != m_lpFirmata->getPwm(m_iIOComponentID))
51  {
52  std::cout << "PWM: " << m_iIOValue << " OFF." << "\r\n";
53 
54  m_lpFirmata->sendPwm(m_iIOComponentID, m_iIOValue, false);
55  }
56  }
57 }
58 
60 {
61  RobotPartInterface::StepSimulation();
62 
63  //If it is associated with a part property then we need to get that value.
64  //run it through the gain to transform it, round it out to int, and then
65  //send it if the value has changed.
66  if(m_lpProperty &&m_lpGain && m_lpFirmata)
67  {
68  m_fltIOScaledValue = m_lpGain->CalculateGain(*m_lpProperty);
69 
71  if(m_fltIOScaledValue > 255) m_fltIOScaledValue = 255;
72 
75  }
76 }
77 
78  } //Firmata
79  } //RobotIOControls
80  } // Robotics
81 } //RoboticsAnimatSim
82 
virtual bool InSimulation()
Used to determine if we are running in a simulation, or in a real control mode.
Definition: Simulator.cpp:1673
Simulator * m_lpSim
The pointer to a Simulation.
Definition: AnimatBase.h:43
virtual void StepSimulation()
Step the simulation for this object.
Declares the vortex structure class.
Declares the vortex hinge class.
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 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...
Gain * m_lpGain
Pointer to the Gain that will be used to convert the source value into the target value...
int m_iIOValue
This stores the temporary IO value to be used later in IO calculations.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.