Servers by jDrones

LSM9DS1 IMU Driver I2C Functionality?


I’m porting Ardupilot to custom hardware built around a Raspberry Pi Zero W. In order to keep my hardware plug-and-play, I need to resort to an I2C connection for my LSM9DS1 IMU. Because I’m building for a sailboat, I don’t think the additional loop time will compromise control stability. It looks like the current LSM9DS1 drivers don’t have compatibility with I2C, unlike the Invensense drives. I’m a new developer working through the APM onboarding documentation, and I think LSM9DS1 I2C support could be a good first feature for me to implement. Based on the device datasheet and other drivers, this addition looks straightforward but I’m concerned there might be more nuance which prevented I2C support from being added in the first place. I want to ask other developers before I start:

  1. Is I2C too slow for most APM vehicles, or is there another reason that the LSM9DS1 does not have I2C support?
  2. Would LSM9DS1 I2C support be a welcome addition to the codebase?
  3. Should I do another project first that is a more suitable first exposure to APM’s HAL, macro usage, and threading support?

Thank you very much!

I did it! To anyone wanting to do the same, here’s what I had to do. I will not be submitting a pull request because I interpret the lack of responses to mean that there is insufficient community interest in this feature.

You can review the relevant git commit here.

  • I changed all references to AP_HAL::SPIDevice to the more generic AP_HAL::Device. Same with semaphore calls.
  • I changed the read_flag item to 0x00 from 0x80 to accommodate my device hardware. You may or may not have to do this.
  • I lowered the device’s internal update speed from 952 Hz to 119Hz so that collected samples were more indicative of the actual Rover sampling rate.
  • I did not change the frequency of the periodic_callback call which registers the device to be routinely queried. When I initially attempted to change it, it caused a bug where the INS would fail to update if the device FIFO had not been queried by the time the INS is updated.

Happy Hacking!

1 Like
Servers by jDrones