yarp-devices
EncoderRead.hpp
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 #ifndef __ENCODER_READ_HPP__
4 #define __ENCODER_READ_HPP__
5 
6 #include <cstdint>
7 
8 #include <mutex>
9 
10 #include <yarp/os/Stamp.h>
11 
12 namespace roboticslab
13 {
14 
21 {
22 public:
24  EncoderRead(double samplingPeriod);
25 
27  void update(std::int32_t newPos);
28 
30  void reset(std::int32_t pos = 0);
31 
33  std::int32_t queryPosition() const;
34 
36  double querySpeed() const;
37 
39  double queryAcceleration() const;
40 
42  double queryTime() const;
43 
44 private:
45  const double samplingFreq; // samples per second
46  std::int32_t lastPosition;
47  double lastSpeed;
48  double lastAcceleration;
49  yarp::os::Stamp lastStamp;
50  mutable std::mutex encoderMutex;
51 };
52 
53 } // namespace roboticslab
54 
55 #endif // __ENCODER_READ_HPP__
Stores last encoder reads, obtains mean speeds and accelerations via differentiation.
Definition: EncoderRead.hpp:21
double queryTime() const
Retrieve last timestamp (seconds).
Definition: EncoderRead.cpp:72
void reset(std::int32_t pos=0)
Reset internals to zero, pick provided position (encoder counts).
Definition: EncoderRead.cpp:38
std::int32_t queryPosition() const
Retrieve current position (encoder counts).
Definition: EncoderRead.cpp:48
EncoderRead(double samplingPeriod)
Constructor.
Definition: EncoderRead.cpp:9
double queryAcceleration() const
Retrieve instantaneous acceleration (encoder counts/sample^2).
Definition: EncoderRead.cpp:64
double querySpeed() const
Retrieve instantaneous speed (encoder counts/sample).
Definition: EncoderRead.cpp:56
void update(std::int32_t newPos)
Set new position (counts), update speeds (counts/sample) and accelerations (counts/sample^2).
Definition: EncoderRead.cpp:20
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6