Skip to content

Commit

Permalink
Move and rename driver stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
calebchalmers committed Apr 14, 2024
1 parent 8c757c3 commit 4e8ff82
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
File renamed without changes.
7 changes: 4 additions & 3 deletions ut-robomaster/src/drivers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include "tap/drivers.hpp"

#include "communication/cv_board.hpp"
#include "drivers/board.hpp"
#include "drivers/encoder.hpp"
#include "drivers/as5600.hpp"
#include "utils/robot_comms.hpp"

#include "board.hpp"

namespace src
{
class Drivers : public tap::Drivers
Expand All @@ -22,7 +23,7 @@ class Drivers : public tap::Drivers
public:
communication::CVBoard cvBoard;
comms::RobotComms terminal;
encoder::Encoder<Board::I2cMaster> encoder;
driver::As5600<Board::I2cMaster> encoder;
bool isKillSwitched() { return !remote.isConnected(); }
}; // class Drivers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
#include "modm/architecture/interface/i2c_device.hpp"
#include "modm/processing/protothread/protothread.hpp"

namespace encoder
namespace driver
{
template <class I2cMaster>
class Encoder : public modm::I2cDevice<I2cMaster, 10, modm::I2cWriteReadTransaction>,
public modm::pt::Protothread
class As5600 : public modm::I2cDevice<I2cMaster, 1>, public modm::pt::Protothread
{
public:
Encoder(uint8_t address = slave_address)
: modm::I2cDevice<I2cMaster, 10, modm::I2cWriteReadTransaction>(address){};
As5600() : modm::I2cDevice<I2cMaster, 1>(ADDRESS){};

void update() { run(); }

Expand All @@ -21,25 +19,24 @@ class Encoder : public modm::I2cDevice<I2cMaster, 10, modm::I2cWriteReadTransact

while (true)
{
PT_WAIT_UNTIL(this->startWriteRead(writeBuf, 1, buffer, 2));
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];
}

PT_YIELD();
}

PT_END();
}

/// @brief Get current measured angle of the encoder
/// @return Angle (revs)
float getAngle() { return angle / 4096.0f; }

protected:
static const uint8_t slave_address = 0x36; // address of the AS5600

enum class Register : uint8_t
{
ZPOS = 0x01,
Expand All @@ -55,9 +52,9 @@ class Encoder : public modm::I2cDevice<I2cMaster, 10, modm::I2cWriteReadTransact
};

private:
uint16_t angle;
static const uint8_t ADDRESS = 0x36;
uint16_t angle = 0;
uint8_t buffer[2];
const uint8_t writeBuf[1] = {0x0E};
};

}; // namespace encoder
}; // namespace driver
3 changes: 2 additions & 1 deletion ut-robomaster/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#include "tap/motor/motorsim/sim_handler.hpp"
#endif

#include "drivers/board.hpp"
#include "modm/architecture/interface/delay.hpp"
#include "modm/platform.hpp"

#include "board.hpp"

/* arch includes ------------------------------------------------------------*/
#include "tap/architecture/periodic_timer.hpp"
#include "tap/architecture/profiler.hpp"
Expand Down

0 comments on commit 4e8ff82

Please sign in to comment.