-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4858a8d
commit f372757
Showing
8 changed files
with
456 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
#pragma once | ||
|
||
#include "tap/board/board.hpp" | ||
|
||
namespace Board | ||
{ | ||
using I2cSda = DigitalInPinPF0; | ||
using I2cScl = DigitalInPinPF1; | ||
using I2cMaster = I2cMaster2; | ||
|
||
inline void initialize_i2c() | ||
{ | ||
I2cMaster::connect<I2cSda::Sda, I2cScl::Scl>(I2cMaster::PullUps::Internal); | ||
I2cMaster::initialize<SystemClock>(); | ||
} | ||
} // namespace Board | ||
#pragma once | ||
|
||
#include "tap/board/board.hpp" | ||
|
||
namespace Board | ||
{ | ||
using I2cSda = DigitalInPinPF0; | ||
using I2cScl = DigitalInPinPF1; | ||
using I2cMaster = I2cMaster2; | ||
|
||
inline void initialize_i2c() | ||
{ | ||
I2cMaster::connect<I2cSda::Sda, I2cScl::Scl>(I2cMaster::PullUps::Internal); | ||
I2cMaster::initialize<SystemClock>(); | ||
} | ||
} // namespace Board |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
#pragma once | ||
|
||
#include "tap/drivers.hpp" | ||
|
||
#include "communication/cv_board.hpp" | ||
#include "communication/rtt.hpp" | ||
|
||
namespace src | ||
{ | ||
class Drivers : public tap::Drivers | ||
{ | ||
public: | ||
Drivers() : tap::Drivers(), cvBoard(this), rtt() {} | ||
communication::CVBoard cvBoard; | ||
communication::RttStream rtt; | ||
|
||
bool isKillSwitched() { return !remote.isConnected(); } | ||
}; // class Drivers | ||
|
||
} // namespace src | ||
#pragma once | ||
|
||
#include "tap/drivers.hpp" | ||
|
||
#include "communication/cv_board.hpp" | ||
#include "communication/rtt.hpp" | ||
|
||
namespace src | ||
{ | ||
class Drivers : public tap::Drivers | ||
{ | ||
public: | ||
Drivers() : tap::Drivers(), cvBoard(this), rtt() {} | ||
communication::CVBoard cvBoard; | ||
communication::RttStream rtt; | ||
|
||
bool isKillSwitched() { return !remote.isConnected(); } | ||
}; // class Drivers | ||
|
||
} // namespace src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
#pragma once | ||
|
||
#include "modm/architecture/interface/i2c_device.hpp" | ||
#include "modm/processing/protothread/protothread.hpp" | ||
|
||
#include "board.hpp" | ||
#include "encoder.hpp" | ||
|
||
namespace driver | ||
{ | ||
using Board::I2cMaster; | ||
class As5600 : public Encoder, public modm::I2cDevice<I2cMaster, 1>, public modm::pt::Protothread | ||
{ | ||
public: | ||
As5600() : modm::I2cDevice<I2cMaster, 1>(ADDRESS) {}; | ||
|
||
void update() { run(); } | ||
|
||
bool run() | ||
{ | ||
PT_BEGIN(); | ||
|
||
while (true) | ||
{ | ||
buffer[0] = uint8_t(Register::RAWANGLE); | ||
PT_WAIT_UNTIL(this->startWriteRead(buffer, 1, buffer, 2)); | ||
PT_WAIT_WHILE(this->isTransactionRunning()); | ||
|
||
if (this->wasTransactionSuccessful()) | ||
{ | ||
angle = (buffer[0] << 8) | buffer[1]; | ||
online = true; | ||
} | ||
} | ||
|
||
PT_END(); | ||
} | ||
|
||
float getAngle() override { return angle / 4096.0f; } | ||
|
||
bool isOnline() override { return online; } | ||
|
||
protected: | ||
enum class Register : uint8_t | ||
{ | ||
ZPOS = 0x01, | ||
MPOS = 0x03, | ||
CONF = 0x07, | ||
|
||
RAWANGLE = 0x0C, | ||
ANGLE = 0x0E, | ||
|
||
STATUS = 0x0B, | ||
AGC = 0x1A, | ||
MAG = 0x1B, | ||
}; | ||
|
||
private: | ||
static const uint8_t ADDRESS = 0x36; | ||
uint16_t angle = 0; | ||
uint8_t buffer[2]; | ||
bool online = false; | ||
}; | ||
|
||
#pragma once | ||
|
||
#include "modm/architecture/interface/i2c_device.hpp" | ||
#include "modm/processing/protothread/protothread.hpp" | ||
|
||
#include "board.hpp" | ||
#include "encoder.hpp" | ||
|
||
namespace driver | ||
{ | ||
using Board::I2cMaster; | ||
class As5600 : public Encoder, public modm::I2cDevice<I2cMaster, 1>, public modm::pt::Protothread | ||
{ | ||
public: | ||
As5600() : modm::I2cDevice<I2cMaster, 1>(ADDRESS) {}; | ||
|
||
void update() { run(); } | ||
|
||
bool run() | ||
{ | ||
PT_BEGIN(); | ||
|
||
while (true) | ||
{ | ||
buffer[0] = uint8_t(Register::RAWANGLE); | ||
PT_WAIT_UNTIL(this->startWriteRead(buffer, 1, buffer, 2)); | ||
PT_WAIT_WHILE(this->isTransactionRunning()); | ||
|
||
if (this->wasTransactionSuccessful()) | ||
{ | ||
angle = (buffer[0] << 8) | buffer[1]; | ||
online = true; | ||
} | ||
} | ||
|
||
PT_END(); | ||
} | ||
|
||
float getAngle() override { return angle / 4096.0f; } | ||
|
||
bool isOnline() override { return online; } | ||
|
||
protected: | ||
enum class Register : uint8_t | ||
{ | ||
ZPOS = 0x01, | ||
MPOS = 0x03, | ||
CONF = 0x07, | ||
|
||
RAWANGLE = 0x0C, | ||
ANGLE = 0x0E, | ||
|
||
STATUS = 0x0B, | ||
AGC = 0x1A, | ||
MAG = 0x1B, | ||
}; | ||
|
||
private: | ||
static const uint8_t ADDRESS = 0x36; | ||
uint16_t angle = 0; | ||
uint8_t buffer[2]; | ||
bool online = false; | ||
}; | ||
|
||
}; // namespace driver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
#pragma once | ||
|
||
namespace driver | ||
{ | ||
class Encoder | ||
{ | ||
public: | ||
virtual ~Encoder() {} | ||
|
||
/// @brief Get current measured angle of the encoder | ||
/// @return Angle (revs) | ||
virtual float getAngle() = 0; | ||
|
||
virtual bool isOnline() = 0; | ||
}; | ||
#pragma once | ||
|
||
namespace driver | ||
{ | ||
class Encoder | ||
{ | ||
public: | ||
virtual ~Encoder() {} | ||
|
||
/// @brief Get current measured angle of the encoder | ||
/// @return Angle (revs) | ||
virtual float getAngle() = 0; | ||
|
||
virtual bool isOnline() = 0; | ||
}; | ||
} // namespace driver |
Oops, something went wrong.