AnimatLab  2
Test
RbFirmataAnalogInput.cpp
1 // RbFirmataAnalogInput.cpp: implementation of the RbFirmataAnalogInput 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 "RbFirmataAnalogInput.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 RbFirmataAnalogInput::RbFirmataAnalogInput()
33 {
34 }
35 
36 RbFirmataAnalogInput::~RbFirmataAnalogInput()
37 {
38 }
39 
41 {
42  if(!m_lpSim->InSimulation())
43  m_lpFirmata->sendAnalogPinReporting(m_iIOComponentID, ARD_ANALOG);
44 }
45 
46 void RbFirmataAnalogInput::StepIO(int iPartIdx)
47 {
48  if(!m_lpSim->InSimulation())
49  {
50  int iValue = m_lpFirmata->getAnalog(m_iIOComponentID);
51  if(iValue != -1 && m_iIOValue != iValue)
52  {
53  //std::cout << "Analog In: " << iValue << "\r\n";
54 
55  IOValue(iValue);
56  m_bChanged = true;
57  }
58  }
59 }
60 
62 {
63  RobotPartInterface::StepSimulation();
64 
65  if(m_bChanged)
66  {
67  m_bChanged = false;
68 
69  //Calculate the gain of the IO value.
70  float fltValue = m_lpGain->CalculateGain(m_fltIOValue);
71 
72  if(fltValue >= 1)
73  fltValue = fltValue;
74 
75  //Remove any previously added value from the param
76  *m_lpProperty -= m_fltIOScaledValue;
77 
78  m_fltIOScaledValue = fltValue;
79 
80  //Add the value back.
81  *m_lpProperty += m_fltIOScaledValue;
82  }
83 }
84 
85  } //Firmata
86  } //RobotIOControls
87  } // Robotics
88 } //RoboticsAnimatSim
89 
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
Declares the vortex structure class.
Declares the vortex hinge class.
bool m_bChanged
True when the value changes.
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.