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

update to imu docs #42

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
57 changes: 38 additions & 19 deletions docs/parts/imu.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,36 @@ MPU9250 offers additional integrated magnetometer.

* Typically uses the I2C interface and can be chained off the default PWM PCA9685 board. This configuration will also provide power.
* MPU6050: Outputs acceleration X, Y, Z, Gyroscope X, Y, Z, and temperature.
* MPU6250: Outputs acceleration X, Y, Z, Gyroscope X, Y, Z, Magnetometer X, Y, Z and temperature.
* MPU9250: Outputs acceleration X, Y, Z, Gyroscope X, Y, Z, Magnetometer X, Y, Z and temperature.
* Chip built-in 16bit AD converter, 16bit data output
* Gyroscopes range: +/- 250 500 1000 2000 degree/sec
* Acceleration range: ±2 ±4 ±8 ±16g

### Software Setup

Install smbus
Install smbus2

* either from package:
* either using pip:

``` bash
sudo apt install python3-smbus
pip install smbus2
```
* or conda:

* or from source:

```bash
sudo apt-get install i2c-tools libi2c-dev python-dev python3-dev
git clone https://github.com/pimoroni/py-smbus.git
cd py-smbus/library
python setup.py build
sudo python setup.py install
``` bash
conda install -c conda-forge smbus2
```
For MPU6050:


**If you are using MPU6050:**

Install pip lib for `mpu6050`:

```bash
pip install mpu6050-raspberrypi
```

For MPU9250:
**If you are using MPU9250:**

Install pip lib for `mpu9250-jmdev`:

Expand All @@ -51,18 +48,18 @@ pip install mpu9250-jmdev
```

### Configuration
Enable the following configurations to your `myconfig.py`:
1. Make the following configuration changes in your `/home/pi/mycar/myconfig.py`:

``` python
#IMU
HAVE_IMU = True
IMU_SENSOR = 'mpu9250' # (mpu6050|mpu9250)
IMU_DLP_CONFIG = 3
IMU_DLP_CONFIG = 0x05 # Digital Lowpass Filter setting (0x00:250Hz, 0x01:184Hz, 0x02:92Hz, 0x03:41Hz, 0x04:20Hz, 0x05:10Hz, 0x06:5Hz)
```
`IMU_SENSOR` can be either `mpu6050` or `mpu9250` based on the sensor you are using.

`IMU_DLP_CONFIG` allows to change the digital lowpass filter settings for your IMU. Lower frequency settings (see below) can filter high frequency noise at the expense of increased latency in IMU sensor data.
Valid settings are from 0 to 6:
Valid settings are from 0 (`0x00`) to 6 (`0x06`):

- `0` 250Hz
- `1` 184Hz
Expand All @@ -72,6 +69,28 @@ Valid settings are from 0 to 6:
- `5` 10Hz
- `6` 5Hz

<br>

2. In `/home/pi/projects/donkeycar/donkeycar/parts/` find `imu.py`
Copy link
Contributor

Choose a reason for hiding this comment

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

I've actually landed a pull requests that exposes a configuration so there is not need to edit this manually; just change the configuration value; See autorope/donkeycar#1064. The configuraton changes here https://github.com/autorope/donkeycar/pull/1064/files#diff-dd7806493c6284e60142951760a6712d8b3f90a8e007e710d4033691f74753edR447. So it would be excellent if you could incorporate instructions for changing that configuration here.

Copy link
Author

Choose a reason for hiding this comment

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

Tried to understand what's happening at the provided recent merge.
==> configurable imu addressing (?); derives from imu part file w/ new (?) IMU_ADDRESS config (?)

Thus, and please do correct me, @Ezward

  1. the imu docs should instead reflect setting addr=0x68 to addr=IMU_ADDRESS on line 29
    ... in addition to commenting out the calibrateMPU6500() script
    ... & setting address_mpu_slave = 0x0c
    ... not sure where IMU_ADDRESS would be initially defined here

Or

  1. are you suggested the imu docs should additionally be extended to contain info on how to modify:
    IMU_ADDRESS = 0x68 # if AD0 pin is pulled high them address is 0x69, otherwise it is 0x68
    ...which can be found at: donkeycar/templates/cfg_path_follow.py (?)

Copy link
Author

Choose a reason for hiding this comment

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

I think option 2 seems more likely.
So, I should include instructions how to configure IMU_ADDRESS in:

  1. donkeycar/templates/cfg_path_follow.py::414

&

  1. donkeycar/templates/cfg_complete.py::447

Appreciate the feedback

Copy link
Contributor

@Ezward Ezward Dec 6, 2022

Choose a reason for hiding this comment

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

I am suggesting 2. We no longer need to edit any source code to change the address; so that should be removed. The user just needs to set the value of "IMU_ADDRESS" in their myconfig.py file; so that should added.

Copy link
Author

Choose a reason for hiding this comment

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

Hey, I studied the IMU_ADDRESS commit further to try and understand why source code changes to imu.py are no longer necessary and I did not reach the same conclusion; I left the source code edits in case configurations differ among setups

Copy link
Contributor

Choose a reason for hiding this comment

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

See https://github.com/autorope/donkeycar/blob/f8dc720596d04c3cb14ff0a34d771ef39baf1897/donkeycar/templates/complete.py#L263 https://github.com/autorope/donkeycar/blob/f8dc720596d04c3cb14ff0a34d771ef39baf1897/donkeycar/templates/complete.py#L805 The imu part has be updated to take in the necessary parameters and complete.py has been updated to use them.

I also see that the instruction include setting the address_mpu_slave=0x0c; can you explain? My understanding what that the slave setting is if you have two IMU's and one is slaved to the other.

I also see that the instructions include commenting out the sensor calibration; can you explain? The calibrateMPU6500 is still appropriate even if using an MPU9250; the MPU9250 is basically just an MPU6500 plus an magnetometer; we we still want to calibrate the giro/accelerometers so we know which way is down.


On lines `29`,`45` and `54` of `imu.py`, implement the following adjustments.

* On line `29` change `addr=0x68` to `addr=0x69` (`...def __init__(self, addr=0x69, poll_delay=0.0166, ...`)

* On line `45` change `address_mpu_slave=None` to `address_mpu_slave=0x0c`

* On line `54` change `self.sensor.calibrateMPU6500()` to `#self.sensor.calibrateMPU6500()` (add `#` at the start of the line)

<br>

### Notes on MPU9250
At startup the MPU9250 driver performs calibration to zero accel and gyro bias. Usually the process takes less than 10 seconds, and in that time avoid moving or touching the car.
Please place the car on the ground before starting Donkey.
If you are using Robohat MM1, the MPU9250 come presoldered and the following is applicable to you.
The self-calibration routine currently does not function.
This is why we comment out the corresponding line `54` in the second configuration step above.
Factory calibration is thus considered as minimum sufficient.

In case the calibration routine gets fixed in the future, the following applies:
At startup the MPU9250 driver performs calibration to zero accel and gyro bias.
Usually this process takes less than 10 seconds.
Avoid moving or touching the car during this time.
It is best to place the car on flat ground when first launching a driving script that relies on the imu.