Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions NUSense/Core/Inc/imu.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ namespace nusense {
/* Common Defines */
const uint8_t IMU_READ = 0x80;
const uint8_t IMU_WRITE = 0x00;
const uint8_t IMU_DEVICE_ID = 0x98;
enum class Address : uint8_t {
/* Command Defines */ /* ADR Register Function */
// Self Test
Expand Down Expand Up @@ -662,6 +663,14 @@ namespace nusense {
*/
void init();

/*
* @brief performs post-startup tests (POSTs)
* @note reads WHOAMI 1-byte register, asserts equal to 0x98
* @param none
* @return true if everything ok, false if not
*/
bool post();

/*
* @brief writes a byte to a register.
* @note uses polling, should only be used for beginning.
Expand Down
17 changes: 17 additions & 0 deletions NUSense/Core/Src/imu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ namespace nusense {
*/
}

/*
* @brief performs post-startup tests (POSTs)
* @note reads WHOAMI 1-byte register, asserts equal to 0x98
* @param none
* @return true if everything ok, false if not
*/
bool IMU::post() {
uint8_t who_am_i = 0;
read_reg(Address::WHO_AM_I, &who_am_i);

if (who_am_i != IMU_DEVICE_ID) {
return false;
}

return true;
}

/*
* @brief writes a byte to a register.
* @note uses polling, should only be used for beginning.
Expand Down
5 changes: 5 additions & 0 deletions NUSense/Core/Src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ int main(void) {
#ifdef RUN_MAIN
nusense::NUSenseIO nusenseIO;

bool posted_successfully = nusenseIO.post();
if (!posted_successfully) {
return -1;
}

// Wait for the initial handshake message from NUC
while (!nusenseIO.handshake_received()) {
}
Expand Down
3 changes: 3 additions & 0 deletions NUSense/Core/Src/nusense/NUSenseIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ namespace nusense {
dynamixel::Chain(ports[5], 5)})
, imu() {}

/// @brief Does basic sanity checks to ensure subsystems exist and communication is working
bool post();

/// @brief Begins the ports and sets the servos up with indirect addresses, etc.
/// @note Is loosely inspired by startup() in NUbots/NUbots OpenCR HardwareIO.
void startup();
Expand Down
8 changes: 8 additions & 0 deletions NUSense/Core/Src/nusense/NUSenseIO/startup.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#include "../NUSenseIO.hpp"
namespace nusense {

bool NUSenseIO::post() {
if (!this->imu.post()) {
return false;
}

return true;
}

void NUSenseIO::startup() {

/*
Expand Down