Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laelaps::LaeMotorCtlrEnable Class Reference

Laelaps motor controller power enable class. More...

#include <laeGpio.h>

Inheritance diagram for laelaps::LaeMotorCtlrEnable:
laelaps::LaeGpio

Public Member Functions

 LaeMotorCtlrEnable ()
 Default constructor.
 
virtual ~LaeMotorCtlrEnable ()
 Destructor.
 
virtual void sync ()
 Synchronized this with GPIO hardware state.
 
bool enable ()
 Enable power to motor controllers. More...
 
bool disable ()
 Disable power to motor controllers. More...
 
bool isEnabled ()
 Test if power to motor controllers is enabled. More...
 
- Public Member Functions inherited from laelaps::LaeGpio
 LaeGpio (const std::string &strTag, const int gpio, const LaeGpio::Direction dir)
 Default intialization constructor. More...
 
virtual ~LaeGpio ()
 Destructor.
 
virtual int writeValue (const LaeGpio::TriState value)
 Write value to gpio. More...
 
virtual int writeValue (const int value)
 Write value to gpio. More...
 
virtual int readValue (int &value)
 Read current value of gpio. More...
 
int hasValue () const
 Get the current shadowed gpio value. More...
 
bool isConfigured () const
 Is the exported GPIO number configured to match this ojbect? More...
 

Static Public Attributes

static const int TPowerUp = 500000
 power-up time (usec)
 

Additional Inherited Members

- Public Types inherited from laelaps::LaeGpio
enum  TriState {
  UNKNOWN = -1,
  LOW = 0,
  HIGH = 1
}
 GPIO tri-state value. More...
 
enum  Direction {
  INPUT = GPIO_DIR_IN,
  OUTPUT = GPIO_DIR_OUT
}
 GPIO direction. More...
 
- Protected Member Functions inherited from laelaps::LaeGpio
bool checkConfig ()
 Check if the exported GPIO exists in /sys/class and that it has been configured to match this objects configuration. More...
 
- Protected Attributes inherited from laelaps::LaeGpio
std::string m_gpioTag
 identifying tag
 
int m_gpioNum
 exported GPIO number
 
LaeGpio::Direction m_gpioDir
 GPIO direction.
 
int m_gpioVal
 shadowed value
 
bool m_gpioCfg
 GPIO is [not] configured (correctly)
 

Detailed Description

Laelaps motor controller power enable class.

Definition at line 200 of file laeGpio.h.

Member Function Documentation

bool LaeMotorCtlrEnable::disable ( )

Disable power to motor controllers.

Returns
Returns true if power is enabled, false otherwise.

Definition at line 214 of file laeGpio.cxx.

References laelaps::LaeGpio::isConfigured(), laelaps::LaeGpio::m_gpioNum, laelaps::LaeGpio::m_gpioTag, laelaps::LaeGpio::m_gpioVal, laelaps::LaeGpio::sync(), laelaps::LaeGpio::UNKNOWN, and laelaps::LaeGpio::writeValue().

215 {
216  bool bEnabled;
217 
218  // lazy one-time synchronization
219  if( m_gpioVal == LaeGpio::UNKNOWN )
220  {
221  sync();
222  }
223 
224  // versions 2.1+ have power enable to motor controllers
225  if( isConfigured() )
226  {
227  writeValue(0);
228  }
229 
230  bEnabled = isEnabled();
231 
232  if( !bEnabled )
233  {
234  LOGDIAG2("%s (GPIO %d) disabled.", m_gpioTag.c_str(), m_gpioNum);
235  }
236 
237  return bEnabled;
238 }
bool isEnabled()
Test if power to motor controllers is enabled.
Definition: laeGpio.cxx:240
int m_gpioNum
exported GPIO number
Definition: laeGpio.h:178
bool isConfigured() const
Is the exported GPIO number configured to match this ojbect?
Definition: laeGpio.h:171
unknown state value
Definition: laeGpio.h:83
virtual int writeValue(const LaeGpio::TriState value)
Write value to gpio.
Definition: laeGpio.h:129
int m_gpioVal
shadowed value
Definition: laeGpio.h:180
std::string m_gpioTag
identifying tag
Definition: laeGpio.h:177
virtual void sync()
Synchronized this with GPIO hardware state.
Definition: laeGpio.cxx:168
bool LaeMotorCtlrEnable::enable ( )

Enable power to motor controllers.

Returns
Returns true if power is enabled, false otherwise.

Definition at line 179 of file laeGpio.cxx.

References laelaps::LaeGpio::isConfigured(), laelaps::LaeGpio::m_gpioNum, laelaps::LaeGpio::m_gpioTag, laelaps::LaeGpio::m_gpioVal, laelaps::LaeGpio::sync(), laelaps::LaeGpio::UNKNOWN, and laelaps::LaeGpio::writeValue().

180 {
181  bool wasEnabled;
182  bool bEnabled;
183 
184  // lazy one-time synchronization
185  if( m_gpioVal == LaeGpio::UNKNOWN )
186  {
187  sync();
188  }
189 
190  // versions 2.1+ have power enable to motor controllers
191  if( isConfigured() )
192  {
193  wasEnabled = isEnabled();
194 
195  writeValue(1);
196 
197  // give the motor controllers time to power up
198  if( !wasEnabled && isEnabled() )
199  {
200  usleep(TPowerUp);
201  }
202  }
203 
204  bEnabled = isEnabled();
205 
206  if( bEnabled )
207  {
208  LOGDIAG2("%s (GPIO %d) enabled.", m_gpioTag.c_str(), m_gpioNum);
209  }
210 
211  return bEnabled;
212 }
bool isEnabled()
Test if power to motor controllers is enabled.
Definition: laeGpio.cxx:240
int m_gpioNum
exported GPIO number
Definition: laeGpio.h:178
static const int TPowerUp
power-up time (usec)
Definition: laeGpio.h:203
bool isConfigured() const
Is the exported GPIO number configured to match this ojbect?
Definition: laeGpio.h:171
unknown state value
Definition: laeGpio.h:83
virtual int writeValue(const LaeGpio::TriState value)
Write value to gpio.
Definition: laeGpio.h:129
int m_gpioVal
shadowed value
Definition: laeGpio.h:180
std::string m_gpioTag
identifying tag
Definition: laeGpio.h:177
virtual void sync()
Synchronized this with GPIO hardware state.
Definition: laeGpio.cxx:168
bool LaeMotorCtlrEnable::isEnabled ( )

Test if power to motor controllers is enabled.

Returns
Returns true if power is enabled, false otherwise.

Definition at line 240 of file laeGpio.cxx.

References laelaps::LaeGpio::hasValue(), laelaps::LaeGpio::HIGH, laelaps::LaeGpio::m_gpioVal, laelaps::LaeGpio::sync(), and laelaps::LaeGpio::UNKNOWN.

241 {
242  // lazy one-time synchronization
243  if( m_gpioVal == LaeGpio::UNKNOWN )
244  {
245  sync();
246  }
247 
248  return hasValue() == LaeGpio::HIGH;
249 }
int hasValue() const
Get the current shadowed gpio value.
Definition: laeGpio.h:157
unknown state value
Definition: laeGpio.h:83
high value
Definition: laeGpio.h:85
int m_gpioVal
shadowed value
Definition: laeGpio.h:180
virtual void sync()
Synchronized this with GPIO hardware state.
Definition: laeGpio.cxx:168

The documentation for this class was generated from the following files: