ArPiRobot-CoreLib C++
C++ library for ArPiRobot robots
Public Member Functions | Protected Member Functions | List of all members
arpirobot::SingleEncoder Class Reference

#include <arpirobot/arduino/sensor/SingleEncoder.hpp>

Inheritance diagram for arpirobot::SingleEncoder:
arpirobot::ArduinoDevice

Public Member Functions

 SingleEncoder (int pin, bool useInternalPullup, bool createDevice=true, int deviceId=-1)
 
 SingleEncoder (std::string pin, bool useInternalPullup, bool createDevice=true, int deviceId=-1)
 
int32_t getPosition ()
 
void setPosition (int32_t currentPosition)
 
float getVelocity ()
 
- Public Member Functions inherited from arpirobot::ArduinoDevice
 ArduinoDevice (bool createDevice, int deviceId)
 
virtual std::string getDeviceName ()
 

Protected Member Functions

void applyDefaultState () override
 
std::vector< uint8_t > getCreateData () override
 
void handleData (const std::vector< uint8_t > &data) override
 
- Protected Member Functions inherited from arpirobot::ArduinoDevice
void setArduino (BaseArduinoInterface *arduino)
 
void setDeviceId (int deviceId)
 
bool sendData (const std::vector< uint8_t > &data)
 
bool sendData (const std::string &data)
 

Additional Inherited Members

- Static Protected Member Functions inherited from arpirobot::ArduinoDevice
static std::vector< uint8_t > stringToData (const std::string &str)
 
- Protected Attributes inherited from arpirobot::ArduinoDevice
bool createDevice
 
int deviceId
 
std::string deviceName
 
BaseArduinoInterfacearduino = nullptr
 

Detailed Description

Single-channel encoder

Constructor & Destructor Documentation

◆ SingleEncoder() [1/2]

arpirobot::SingleEncoder::SingleEncoder ( int  pin,
bool  useInternalPullup,
bool  createDevice = true,
int  deviceId = -1 
)
Parameters
pinThe digital pin number this encoder is connected to
useInternalPullupSet to true to use the arduino's internal pullup resistor on this pin (if supported)
createDeviceLeave this true unless the device is hard-coded in arduino firmware
deviceIdSet this to the hard-coded deviceId if createDevice is false

◆ SingleEncoder() [2/2]

arpirobot::SingleEncoder::SingleEncoder ( std::string  pin,
bool  useInternalPullup,
bool  createDevice = true,
int  deviceId = -1 
)
Parameters
pinThe pin number this encoder is connected to (prefix with letter A for analog pin)
useInternalPullupSet to true to use the arduino's internal pullup resistor on this pin (if supported)
createDeviceLeave this true unless the device is hard-coded in arduino firmware
deviceIdSet this to the hard-coded deviceId if createDevice is false

Member Function Documentation

◆ getPosition()

int32_t arpirobot::SingleEncoder::getPosition ( )

Get the position (tick count) for this encoder

Returns
The position in ticks

◆ getVelocity()

float arpirobot::SingleEncoder::getVelocity ( )

Get the current velocity from the encoder

Returns
The speed in ticks / sec

◆ setPosition()

void arpirobot::SingleEncoder::setPosition ( int32_t  currentPosition)

Set the current tick count to the given value

Parameters
currentPositionThe new tick value to set

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