DavidEGrayson / minimu9-ahrs

Program for reading data from the Pololu MinIMU-9 over I²C. Works on the Raspberry Pi and other embedded ARM Linux boards.
Other
167 stars 68 forks source link

Changed behaviour of the file descriptor for the I2C-device #1

Closed thesummer closed 12 years ago

thesummer commented 12 years ago

I changed the class I2C-bus in a way that it does not have a single file descriptor it has to change every time a sensor requests access, but every I2C-device registers itself to the bus and gets its own fd. This way issuing the system call ioctl extensively can be avoided which may be better for real time systems like xenomai. The sensor classes have been changed accordingly. Only regression so far is that the constructor I2CBus(int fd) had to be removed (but it was not used so far). Opening a device without knowing the device name (as in this case) is apparently not as easy as I thought in the beginning, but needed to assign each sensor an own fd. It would be possible though, but IMHO not in a clean and easy way.

I reverted the changes in the register addresses I made to get the program running with minIMU9 v1, so it should still work with your version. I only tested the program in raw mode (lacking a calibration file). But as I did not change any math-relating code the other modes shouldn't be affected?

I don't know if you agree with these decisions, but I thought I let you know ;-)

DavidEGrayson commented 12 years ago

Thanks! I will look at this more when I get home. I don't have much experience with ioctl calls or real-time Linux; is ioctl generally a slow operation? If I recall correctly, the underlying I2C functions we are using do all their work with ioctl (but I might be wrong about that).

Either way, it seems like a good idea. I think we should do it like this:

I2CBus i2c("/dev/...");
I2CAddress address = i2c.address(0x44); // or call the class I2CDevice
address.readByte(command_byte);

Then the LSM303 and similar classes don't have to worry about file descriptors and don't have to have an explicit destructor.

I'd be happy to make the new class if you don't.

DavidEGrayson commented 12 years ago

Actually, all we need is some way to copy an I2CBus object.

thesummer commented 12 years ago

Sorry for not replying the last week. I just moved to Sweden and had lots of things to sort out and don't have an internet connection at home yet. I hope that I can spend some with that project in university next week.

Adding the i2caddress class seems to be a elegant idea. So the device classes are more independent of OS-specifics. I saw you already pushed some commits for this. I will look into this.

One more question: I compiled your ahrs-visualizer and used the magnetometer calibrator, but I was not sure what to do during calibration. Should the sensor be still or rotated randomly (as they do in many smartphones)?

DavidEGrayson commented 12 years ago

Congrats on moving! Hey, never mind about adding a new class. I came up with a solution that seems pretty good for now, which is to pass around the string "/dev/i2c-0" to all the constructors so each different device can have its own I2CBus object. Then we only have 3 file descriptors for the 3 addresses we are reading, and don't have to worry about copying objects or making a new class.

Also I made it auto-detect which MinIMU-9 version is being used, so it would be cool if you could try my code and make sure it works for you.

During calibration you should be rotating the board all over the place.

thesummer commented 12 years ago

Yes I saw that now after I went through the commit history. It worked out of the box with my MinIMU, so great job :-D. I could only
check the raw mode so far because I don't have my monitor here right now
to display the visualizer.

Am 01.09.2012, 20:20 Uhr, schrieb David Grayson notifications@github.com:

Hey, never mind about adding a new class. I came up with a solution
that seems pretty good for now, which is to pass around the string
"/dev/i2c-0" to all the constructors so each different device can have
its own I2CBus object. Then we only have 3 file descriptors for the
three addresses we are reading.

Also I made it auto-detect which MinIMU-9 version is being used, so it
would be cool if you could try my code and make sure it works for you.

During calibration you should be rotating the board all over the place.


Reply to this email directly or view it on GitHub: https://github.com/DavidEGrayson/minimu9-rpi-ahrs/pull/1#issuecomment-8215285