Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNS - Changes for IMUs to work #152

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion src/debugging/can_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ bool CanListener::hasId(uint32_t id, bool extended)
log_.debug("received extended CAN message; skipping");
return false;
}

return ids_.find(id) != ids_.end();
}

Expand Down
7 changes: 4 additions & 3 deletions src/sensors/imu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static constexpr uint8_t kPwrMgmt1 = 0x06; // userbank 0
static constexpr uint8_t kPwrMgmt2 = 0x07; // userbank 0

// Configuration
static constexpr uint8_t kReadFlag = 0x80; // unable to find in datasheet
static constexpr uint8_t kReadFlag = 0x80; // msb is 1 which signifies a read operation for SPI

// Configuration bits Imu
// constexpr uint8_t kBitsFs250Dps = 0x00;
Expand Down Expand Up @@ -286,12 +286,13 @@ data::ImuData Imu::getData()
}
} else {
log_.debug("Getting Imu data");
uint8_t response[8];
uint8_t response[6];
int16_t bit_data;
float value;
std::array<float, 3> acceleration_data;

readBytes(kAccelXoutH, response, 8);
// Reading six bytes - first two give x-acceleration, next two give y-acceleration, last two give z-acceleration (high and low byte pairs)
readBytes(kAccelXoutH, response, 6);
mifrandir marked this conversation as resolved.
Show resolved Hide resolved
for (size_t i = 0; i < 3; ++i) {
bit_data = ((int16_t)response[i * 2] << 8) | response[i * 2 + 1];
value = static_cast<float>(bit_data);
Expand Down
9 changes: 6 additions & 3 deletions src/utils/io/spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Spi &Spi::getInstance()

Spi::Spi(Logger &log) : spi_fd_(-1), hw_(0), ch_(0), log_(log)
{
const char device[] = "/dev/spidev1.0"; // spidev1.0 for SPI0
const char device[] = "/dev/spidev0.0"; // spidev0.0 for SPI0
mifrandir marked this conversation as resolved.
Show resolved Hide resolved
spi_fd_ = open(device, O_RDWR, 0);

if (spi_fd_ < 0) {
Expand All @@ -105,7 +105,7 @@ Spi::Spi(Logger &log) : spi_fd_(-1), hw_(0), ch_(0), log_(log)
}

// set clock frequency
setClock(Clock::k1MHz);
setClock(Clock::k500KHz);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required? Did we test it? Has it to do with the new IMUs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, yes and yes. Although this just needs to be tested with the sensors PCB but with an individual IMU, this worked.


uint8_t bits = SPI_BITS; // need to change this value
if (ioctl(spi_fd_, SPI_IOC_WR_BITS_PER_WORD, &bits) < 0) {
Expand Down Expand Up @@ -149,14 +149,17 @@ bool Spi::initialise()
ch_ = &hw_->ch0;

log_.info("Mapping successfully created %d", sizeof(SPI_HW));
log_.info("revision 0x%x", hw_->revision);
//log_.info("revision 0x%x", hw_->revision);
mifrandir marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

void Spi::setClock(Clock clk)
{
uint32_t data;
switch (clk) {
case Clock::k500KHz:
data = 500000;
break;
case Clock::k1MHz:
data = 1000000;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/io/spi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Spi {
public:
static Spi &getInstance();

enum class Clock { k1MHz, k4MHz, k16MHz, k20MHz };
enum class Clock { k500KHz, k1MHz, k4MHz, k16MHz, k20MHz };

void setClock(Clock clk);

Expand Down