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
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);
Comment thread
mifrandir marked this conversation as 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
2 changes: 1 addition & 1 deletion src/sensors/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ std::optional<std::vector<uint8_t>> Main::brakePressurePinsFromFile(utils::Logge
}
const auto brake_pressure_pin_array = config_object["brake_pressure_pins"].GetArray();
if (brake_pressure_pin_array.Size() != data::Sensors::kNumBrakePressure) {
log.error("Found %d brake sensor pins but %d were expected in configuration file at %s",
log.error("Found %d brake pressure pins but %d were expected in configuration file at %s",
brake_pressure_pin_array.Size(), data::Sensors::kNumBrakePressure, path.c_str());
}
std::vector<uint8_t> brake_pressure_pins;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/io/gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void Gpio::exportGPIO()
// let the kernel know we are using this pin
int fd;
uint32_t len;
fd = open("/sys/class/gpio/export", O_WRONLY);
fd = open("/sys/class/gpio/export", O_RDWR);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You've touched this line now so we need to do this properly.

const auto fd = open(/* ... */);

Similar for len.

if (fd < 0) {
log_.error("could not open export file");
return;
Expand Down
8 changes: 5 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
Comment thread
mifrandir marked this conversation as 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
Copy Markdown
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
Copy Markdown
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,16 @@ bool Spi::initialise()
ch_ = &hw_->ch0;

log_.info("Mapping successfully created %d", sizeof(SPI_HW));
log_.info("revision 0x%x", hw_->revision);
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