Skip to content

Commit

Permalink
Modified double yaw for conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
vinle0 committed May 15, 2024
1 parent 7fa740f commit b5d6d1b
Show file tree
Hide file tree
Showing 12 changed files with 567 additions and 549 deletions.
32 changes: 16 additions & 16 deletions ut-robomaster/src/board.hpp
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
62 changes: 31 additions & 31 deletions ut-robomaster/src/drivers.hpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
#ifndef DRIVERS_HPP_
#define DRIVERS_HPP_

#include "tap/drivers.hpp"

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

#include "board.hpp"

namespace src
{
class Drivers : public tap::Drivers
{
friend class DriversSingleton;

#ifdef ENV_UNIT_TESTS
public:
#endif
Drivers() : tap::Drivers(), cvBoard(this), terminal(this) {}

public:
communication::CVBoard cvBoard;
comms::RobotComms terminal;
bool isKillSwitched() { return !remote.isConnected(); }
}; // class Drivers

} // namespace src

#endif // DRIVERS_HPP_
#ifndef DRIVERS_HPP_
#define DRIVERS_HPP_

#include "tap/drivers.hpp"

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

#include "board.hpp"

namespace src
{
class Drivers : public tap::Drivers
{
friend class DriversSingleton;

#ifdef ENV_UNIT_TESTS
public:
#endif
Drivers() : tap::Drivers(), cvBoard(this), terminal(this) {}

public:
communication::CVBoard cvBoard;
comms::RobotComms terminal;
bool isKillSwitched() { return !remote.isConnected(); }
}; // class Drivers

} // namespace src

#endif // DRIVERS_HPP_
118 changes: 59 additions & 59 deletions ut-robomaster/src/drivers/as5600.hpp
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
#pragma once

#include "modm/architecture/interface/i2c_device.hpp"
#include "modm/processing/protothread/protothread.hpp"

#include "encoder.hpp"

namespace driver
{
template <class 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];
}
}

PT_END();
}

float getAngle() override { return angle / 4096.0f; }

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];
};

#pragma once

#include "modm/architecture/interface/i2c_device.hpp"
#include "modm/processing/protothread/protothread.hpp"

#include "encoder.hpp"

namespace driver
{
template <class 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];
}
}

PT_END();
}

float getAngle() override { return angle / 4096.0f; }

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];
};

}; // namespace driver
26 changes: 13 additions & 13 deletions ut-robomaster/src/drivers/encoder.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once

namespace driver
{
class Encoder
{
public:
virtual ~Encoder() {}

/// @brief Get current measured angle of the encoder
/// @return Angle (revs)
virtual float getAngle() = 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;
};
} // namespace driver
Loading

0 comments on commit b5d6d1b

Please sign in to comment.