Hi Francis,
I2C is a darn slow protocol and going through several abstraction layers trying to directly do it from the application layer will always be very inefficient and potentially block the flight code from executing while the I2C transfers run, if not done right.
If you do an user level driver ‚right‘ to not block during the transfer, you would implement this as a work queue entry running in parallel, but it would be still inefficient as you keep switching context for single bytes - operating systems want chunks and not flick between taks just for microseconds.
You are potentially better off writing a ‚real‘ driver for your device for each platform you are interested in. This allows you leverage all the efficiency and special features each platform offers and to adapt the I2C-facing code to the hardware layer you are using.
This would mean to write a driver based on e.g. this:
https://github.com/PX4/Firmware/blob/master/src/drivers/hmc5883/hmc5883.cpp
For PX4 and then do a Linux driver, adapted to Linux, once you need it.
As a side effect this would get you proper multithreading pub sub support for your driver data on PX4.
Cheers,
Lorenz
------------------------------------------------------
Lorenz Meier
Computer Vision and Geometry Group
Institute for Visual Computing
ETH Zurich
http://www.inf.ethz.ch/personal/lomeier/
Am 18.02.2014 um 05:34 schrieb Francis Vierboom:
Hi all
Currently working on trying to get a Wii IR Camera to talk to the Pixhawk via the i2c connection (sensor which outputs the X,Y and intesity of four infra-red light sources in its FOV). Had it working on an Arduino board, and tried adding it as a new sensor with similar i2c code to the AP_Compass_HMC5843 i2c code. Spent two days but could get no sign of life - or even any errors - from calling the hal.i2c->readRegisters etc commands. Just zeros.
After getting down to the wires with an oscilloscope, we finally realised that the Pixhawk does not have I2C implemented in the libraries/AP_HAL_PX4 code and the only hal.i2c methods compiled in the px4 build are the AP_HAL_Empty stub classes (at https://github.com/diydrones/ardupilot/blob/master/libraries/AP_HAL_Empty/I2CDriver.cpp). Which explained a lot!
The PX4 compass is using AP_Compass_PX4 (derrr) which is using ioctl calls through to /dev/mag using a dedicated driver within the PX4Firmware stack that only then uses the NuttX i2c implementation.
Tridge, I can see you've been working on the Linux implementation from the notes at http://uav.tridgell.net/LCA2014/AP_Linux.pdf - but you skipped the I2C slide explanation in the video :). The presentation notes that there are some latency issues with the default I2C driver, although these are unlikely to affect this sensor which we only need at 20Hz or so.
Is the PX4/Nuttx implementation likely to be very similar to the Linux interface? Is it worth trying to implement an I2CDriver in AP_HAL_PX4 - would cutting over most of the code from AP_HAL_Linux/I2CDriver work?? I have briefly attempted this but the __s32 type and I2C_SMBUS constants used in that one seem to be in the linux-only i2c-dev.h, so I thought I would ask the community for any tips before really heading down the rabbit hole.
Have I even understood this correctly? Is there a different approach I should be taking? Was mildly surprised to find the PX4 I2C driver is unimplemented in the HAL_PX4. It's all a bit new to me, so please feel free to set me straight on anything here!
Thanks - Francis
--
You received this message because you are subscribed to the Google Groups "drones-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drones-discus...@googlegroups.com<mailto:drones-discuss+unsubscribe@googlegroups.com>.
To unsubscribe from this group and stop receiving emails from it, send an email to drones-discus...@googlegroups.com<mailto:drones-discus...@googlegroups.com>.
Sounds like we need to update our fork!
--
You received this message because you are subscribed to the Google Groups "drones-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drones-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Francis,
I2C is a darn slow protocol and going through several abstraction layers trying to directly do it from the application layer will always be very inefficient and potentially block the flight code from executing while the I2C transfers run, if not done right.
If you do an user level driver ‚right‘ to not block during the transfer, you would implement this as a work queue entry running in parallel, but it would be still inefficient as you keep switching context for single bytes - operating systems want chunks and not flick between taks just for microseconds.
You are potentially better off writing a ‚real‘ driver for your device for each platform you are interested in. This allows you leverage all the efficiency and special features each platform offers and to adapt the I2C-facing code to the hardware layer you are using.
This would mean to write a driver based on e.g. this:
https://github.com/PX4/Firmware/blob/master/src/drivers/hmc5883/hmc5883.cpp
For PX4 and then do a Linux driver, adapted to Linux, once you need it.
As a side effect this would get you proper multithreading pub sub support for your driver data on PX4.
Cheers,
Lorenz
------------------------------------------------------
Lorenz Meier
Computer Vision and Geometry Group
Institute for Visual Computing
ETH Zurich
http://www.inf.ethz.ch/personal/lomeier/
Am 18.02.2014 um 05:34 schrieb Francis Vierboom <fra...@flirtey.com<mailto:fran...@flirtey.com>>:
Hi all
Currently working on trying to get a Wii IR Camera to talk to the Pixhawk via the i2c connection (sensor which outputs the X,Y and intesity of four infra-red light sources in its FOV). Had it working on an Arduino board, and tried adding it as a new sensor with similar i2c code to the AP_Compass_HMC5843 i2c code. Spent two days but could get no sign of life - or even any errors - from calling the hal.i2c->readRegisters etc commands. Just zeros.
After getting down to the wires with an oscilloscope, we finally realised that the Pixhawk does not have I2C implemented in the libraries/AP_HAL_PX4 code and the only hal.i2c methods compiled in the px4 build are the AP_HAL_Empty stub classes (at https://github.com/diydrones/ardupilot/blob/master/libraries/AP_HAL_Empty/I2CDriver.cpp). Which explained a lot!
The PX4 compass is using AP_Compass_PX4 (derrr) which is using ioctl calls through to /dev/mag using a dedicated driver within the PX4Firmware stack that only then uses the NuttX i2c implementation.
Tridge, I can see you've been working on the Linux implementation from the notes at http://uav.tridgell.net/LCA2014/AP_Linux.pdf - but you skipped the I2C slide explanation in the video :). The presentation notes that there are some latency issues with the default I2C driver, although these are unlikely to affect this sensor which we only need at 20Hz or so.
Is the PX4/Nuttx implementation likely to be very similar to the Linux interface? Is it worth trying to implement an I2CDriver in AP_HAL_PX4 - would cutting over most of the code from AP_HAL_Linux/I2CDriver work?? I have briefly attempted this but the __s32 type and I2C_SMBUS constants used in that one seem to be in the linux-only i2c-dev.h, so I thought I would ask the community for any tips before really heading down the rabbit hole.
Have I even understood this correctly? Is there a different approach I should be taking? Was mildly surprised to find the PX4 I2C driver is unimplemented in the HAL_PX4. It's all a bit new to me, so please feel free to set me straight on anything here!
Thanks - Francis
--
You received this message because you are subscribed to the Google Groups "drones-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drones-discus...@googlegroups.com<mailto:drones-discuss+unsubscribe@googlegroups.com>.
Yes, we’ve always implemented this kind of thing as Lorenz describes.
1. A PX4Firmware layer driver that pulls data from the sensor at regular intervals. Here’s one I did for the smart battery: https://github.com/diydrones/PX4Firmware/blob/master/src/drivers/batt_smbus/batt_smbus.cpp
2. The above driver makes the data available by publishing to the Orb, an IOCTL call or via a read function (sometimes we use multiple of these methods)
3. Write an ardupilot driver to pull the data from the above PX4 driver. Here’s the one for the smart battery:
4. Call the ardupilot driver from the main ardupilot vehicle code
By the way, what you’re doing sounds a lot like the IRLock work. Maybe you’re planning to make the vehicle hold position or land based on the output of the sensor? https://www.youtube.com/watch?v=2z14S_a6bNk
The IRLock stuff is not yet integrated into master (although the IRLock driver is in the PX4Firmware layer) because of the AC3.3 delays but it’ll go in some time in the next month or so.
-Randy
Am 18.02.2014 um 05:34 schrieb Francis Vierboom <fra...@flirtey.com<mailto:fra...@flirtey.com>>:
Hi all
Currently working on trying to get a Wii IR Camera to talk to the Pixhawk via the i2c connection (sensor which outputs the X,Y and intesity of four infra-red light sources in its FOV). Had it working on an Arduino board, and tried adding it as a new sensor with similar i2c code to the AP_Compass_HMC5843 i2c code. Spent two days but could get no sign of life - or even any errors - from calling the hal.i2c->readRegisters etc commands. Just zeros.
After getting down to the wires with an oscilloscope, we finally realised that the Pixhawk does not have I2C implemented in the libraries/AP_HAL_PX4 code and the only hal.i2c methods compiled in the px4 build are the AP_HAL_Empty stub classes (at https://github.com/diydrones/ardupilot/blob/master/libraries/AP_HAL_Empty/I2CDriver.cpp). Which explained a lot!
The PX4 compass is using AP_Compass_PX4 (derrr) which is using ioctl calls through to /dev/mag using a dedicated driver within the PX4Firmware stack that only then uses the NuttX i2c implementation.
Tridge, I can see you've been working on the Linux implementation from the notes at http://uav.tridgell.net/LCA2014/AP_Linux.pdf - but you skipped the I2C slide explanation in the video :). The presentation notes that there are some latency issues with the default I2C driver, although these are unlikely to affect this sensor which we only need at 20Hz or so.
Is the PX4/Nuttx implementation likely to be very similar to the Linux interface? Is it worth trying to implement an I2CDriver in AP_HAL_PX4 - would cutting over most of the code from AP_HAL_Linux/I2CDriver work?? I have briefly attempted this but the __s32 type and I2C_SMBUS constants used in that one seem to be in the linux-only i2c-dev.h, so I thought I would ask the community for any tips before really heading down the rabbit hole.
Have I even understood this correctly? Is there a different approach I should be taking? Was mildly surprised to find the PX4 I2C driver is unimplemented in the HAL_PX4. It's all a bit new to me, so please feel free to set me straight on anything here!
Thanks - Francis
--
You received this message because you are subscribed to the Google Groups "drones-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drones-discus...@googlegroups.com<mailto:drones-discus...@googlegroups.com>.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "drones-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drones-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.