Tag Archives: tutorial

Tutorial: How to read data from IMU

In the previous post I described how to setup raspberry pi for connection with the IMU.

Now it is time to see how to read some data from the sensor.

First yuo need sw that manage the i2c interface.there are many examples.You can find one called adafruit_i2c.py on github.

Then it is necessary to have the code specific for the sensor,in my case a MPU6050.

I tryied for some days to build my own code, but I encountered problems related to unconsistent results: even if I did not move the sensor, the returned results were always different. I suspect it was a problem on how I formatted the values.

Finally, Thanks to the great job done by Hove in  his blog, I used his code and I’m now able to collect correct data from the sensor.

I did some minor modification and prepare this IMU_test files.

So I started some preliminary tests to verify which is the sensor behaviour.

I fixed the sensor on a bar ,horizontally, than turned the bar by a known angle ( 13 degrees,measured with my smartphone level) then move back to horizontal.

IMU_test1

I recorded on a file the sensor data : acceleration along axis (from ACCelerometer) and rotational speed (from GYRO scope). On excel sheet  I calculated the angle around x  respect the ACC and respect the GYRO:

  • rx ACC=DEGREES(ATAN2(accZ+9.8;accY))
  • rx(i) GYRO=wx(i) *dt+wx(i-1)

Below you can see the graph.

IMU

I underline in the picture the 2 tipical problems on the IMU :

  • the Gyro drift (you can see an angle of 1  degree while it reality it was 0)
  • the Accelerometer sensibility to noise.

So next  development step is to filter/reduce this 2 problems by combining the 2 sensors results.

Tutorial:How to control a brushless motor with raspberry pi

UPDATED 2014.06.15 Important Note: I discovered that the usage of the function pwm.setservo() it is not adeguate to control the motor in a loop. Everytime it is called, it sets the pwm to zero than it sets the new value. the result is a loss of speed (and so power ) of the motor. I just start to use the pwm.add_channel_pulse() instead and it solve the problem.See motor.py for the last version of  code.

 

Last Saturday it was the great day: first brushless moved! And moved with rpi!!!

Right now I prefer not to mix up too much things, so the rpi is powered via usb and the connection is done by ethernet cable.

wiring_2

Those the details for the necessary steps.

  1. Mount the motor firmly. IMPORTANT: Remember it will move,so fix it well!
  2. Connect the motor wires to the esc.my motor has got 3 cables:red,black and yellow.I decided always to connect the black on the middle, and i can invert yellow and red to change rotation side.
  3. Do NOT connect yet the esc power cable to the battery
  4. Connect esc 0v signal (black) to th rpi ground (for example pin 25)
  5. Connent PWM signal(white) on a rpi output.In my example i connect on pin 11 called GPIO17. This value(17) is used in the program.
  6. Connect Ethernet cable
  7. Connect USB to power on rpimotor_test_setup

Let’s see now the software. It is necessary to install on rpi the RPIO library.You an find how to do it in the SW installation post.

  1. Donwload the motor_test folder tha includes motor_test.py and motor.py and copy in  home/python/motor_test on your pc.
  2. On the pc terminal copy the folder on rpi: (it is requred the rpi password):
    scp -r python/motor_test  pi@10.42.0.63:./python
    password : raspberry
  3. On the pc terminal run the command to connect to rpi.now the terminal is the rpi terminal.
    ssh pi@10.42.0.63
    password : raspberry
  4. Finally run the motor_test program.Important: the startu sequence of an ESC can vary by the model.See the ESC  page for details.
    cd python/motor_test 
    sudo python motor_test.py
  5. Follow the program instruction.

motor_test

After the first ENTER , the PWM signal is set to the maximun value (a pulse width= 2000us every 20ms).Now you can connect the ESC power cables.If everything goes right (correct voltage, cell number correct) ESC is ready to pilot the motor.PWM signal goes to 1000us,the minimum value.So it is possible to play with the motor speed.My motor starts to move over 5%,it means 1050us.This value depends from motor inertia from friction and from battery charge level.