84 lines
2.0 KiB
C++
84 lines
2.0 KiB
C++
|
|
/*
|
|||
|
|
* BinaryEncoderSync.hh
|
|||
|
|
*
|
|||
|
|
* Created on: 19 <EFBFBD><EFBFBD><EFBFBD>. 2022 <EFBFBD>.
|
|||
|
|
* Author: titov
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#ifndef UMLIBRARY_DRIVER_BINARYENCODERSYNC_HH_
|
|||
|
|
#define UMLIBRARY_DRIVER_BINARYENCODERSYNC_HH_
|
|||
|
|
|
|||
|
|
#include <atomic>
|
|||
|
|
#include <cmath>
|
|||
|
|
#include <stdint.h>
|
|||
|
|
|
|||
|
|
#include "IEncoder.hh"
|
|||
|
|
|
|||
|
|
#include "../systemic/IProcess.hh"
|
|||
|
|
#include "../common/DoubleBuffer.hpp"
|
|||
|
|
#include "../communication/IBinaryDataSubscriber.hh"
|
|||
|
|
#include "../communication/format/BinaryHelpers.hh"
|
|||
|
|
#include "../peripheral/NanoTimer.hh"
|
|||
|
|
|
|||
|
|
namespace driver { namespace detail {
|
|||
|
|
|
|||
|
|
class BinaryEncoderSync : public IEncoder, public systemic::IProcess, public communication::IBinaryDataSubscriber {
|
|||
|
|
public:
|
|||
|
|
typedef communication::format::bits::bitsize bitsize;
|
|||
|
|
|
|||
|
|
BinaryEncoderSync( bitsize angle_offset, bitsize angle_size,
|
|||
|
|
bitsize turn_offset, bitsize turn_size );
|
|||
|
|
|
|||
|
|
void read( const void * data, std::size_t size );
|
|||
|
|
void process();
|
|||
|
|
void setSampleTime( float ts_in_second );
|
|||
|
|
|
|||
|
|
//!<21><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
|
Turn getTurn() const;
|
|||
|
|
//!<21><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 0 <20><> 2*pi <20><><EFBFBD> NaN.
|
|||
|
|
Angle getAngle() const;
|
|||
|
|
|
|||
|
|
//!<21><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD>).
|
|||
|
|
std::pair<Turn, Angle> getPosition() const;
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
typedef uint32_t frame;
|
|||
|
|
|
|||
|
|
//todo: extract to communication
|
|||
|
|
struct Bitfield {
|
|||
|
|
frame mask;
|
|||
|
|
bitsize offset;
|
|||
|
|
|
|||
|
|
frame get( frame );
|
|||
|
|
|
|||
|
|
Bitfield( bitsize offset, bitsize size );
|
|||
|
|
} angle, turn;
|
|||
|
|
float angle_cost;
|
|||
|
|
|
|||
|
|
peripheral::nanotimer::time_ns cycle_time;
|
|||
|
|
|
|||
|
|
struct Points {
|
|||
|
|
struct Point {
|
|||
|
|
Turn turn;
|
|||
|
|
Angle angle;
|
|||
|
|
peripheral::nanotimer::stamp timestamp;
|
|||
|
|
} first, second;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
std::atomic< Points > points;
|
|||
|
|
std::atomic_flag handled;
|
|||
|
|
|
|||
|
|
DoubleBuffer< std::pair<Turn, Angle> > sample;
|
|||
|
|
|
|||
|
|
std::pair<Turn, Angle> per_sample( peripheral::nanotimer::stamp timestamp );
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
}}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
#endif /* UMLIBRARY_DRIVER_BINARYENCODERSYNC_HH_ */
|