Raspberry PI based ROV

Anything to do with the Raspberry Pi
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

I think it appears (to me any way ) that you can access them as independent chips. I've managed to get stuff from the pressure sensor now and the compass ... I think from all of them now..
Question is what do I do next ? I can get the data I want displayed on the screen in the terminal. Do I now try and cobble all the bit together so one bit of code gets all the data? Then do I store them in a data base or feed them directly to a socket.io thingy ? The RTMULib thing can be used with the temp sensor as well by the look of it...
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

Typically after spending hours on it and finally getting near the goal I stumble on this clever fellows blog.

https://plus.google.com/+AndrewBirkett/posts

It's got everything I need and he's written a nice imu library that contains all the stuff for each sensor on the GY 80 board.
Why I didn't find this first and save myself a lot of brain burn I don't know.

I haven't a clue what I'm talking about but I'm thinking socket.io should be able to tie in python data to node.js ....should it ?? I don't know how as yet ...
User avatar
Moki
Posts: 119
Joined: Oct 21st, 2014, 2:19 am
Location: The Netherlands

Re: Raspberry PI based ROV

Post by Moki »

Good find.... if you are into Python ;)

Socket.io is a messagebus, between javascript programs. So the server part runs on the RPI and the client part, runs on the browser.
Thats handy, if you dont want to push buttons or reload a page every time you want to update the data from the RPI.

I don't think there is was direct way for Python to interface with the socket.io part. But you could run the Python part on the RPI (using shelljs), parse the output and than send the data to the client, using socket.io. The client can than, display it on a Canvas, using HTML5.

I wouldn't store the data into a database. As a ROV is a moving vehicle, the data is already outdated the moment you have it processed. Database storage would be handy, if you are into (lets say) earthquake research and want to analyse the data over a period of time.
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

I wouldn't really say I was into python (and my next question will prove it) but over the last few days I've been bombarded with it and now I have nice little libraries allowing me to interrogate the sensors so I've made a start in the right direction...
I'm going to ask a probably stupid question now but if the IMU library looks like this

Code: Select all

import time

from adxl345 import ADXL345
from l3g4200d import L3G4200D
from hmc5883l import HMC5883L

class IMU(object):

    K = 0.98
    K1 = 1 - K

    def __init__(self, bus, gyro_address, accel_address, compass_address, name, gyro_scale=L3G4200D.FS_2000, accel_scale=ADXL345.AFS_16g):
        self.bus = bus
        self.gyro_address = gyro_address
        self.accel_address = accel_address
        self.name = name
        self.gyro_scale = gyro_scale
        self.accel_scale = accel_scale
        self.accelerometer = ADXL345(bus, accel_address, name + "-accelerometer", accel_scale)
        self.gyroscope = L3G4200D(bus, gyro_address, name + "-gyroscope", gyro_scale)
        self.compass = HMC5883L(bus, compass_address, name + "-compass")

        self.last_time = time.time()
        self.time_diff = 0

        self.pitch = 0
        self.roll = 0
        # take a reading from the device to allow it to settle after config changes
        self.read_all()
        # now take another to act a starting value
        self.read_all()
        self.pitch = self.rotation_x
        self.roll = self.rotation_y

    def read_all(self):
        '''Return pitch and roll in radians and the scaled x, y & z values from the gyroscope and accelerometer'''
        self.gyroscope.read_raw_data()
        self.accelerometer.read_raw_data()

        self.gyro_scaled_x = self.gyroscope.read_scaled_gyro_x()
        self.gyro_scaled_y = self.gyroscope.read_scaled_gyro_y()
        self.gyro_scaled_z = self.gyroscope.read_scaled_gyro_z()

        self.accel_scaled_x = self.accelerometer.read_scaled_accel_x()
        self.accel_scaled_y = self.accelerometer.read_scaled_accel_y()
        self.accel_scaled_z = self.accelerometer.read_scaled_accel_z()

        self.rotation_x = self.accelerometer.read_x_rotation(self.accel_scaled_x, self.accel_scaled_y, self.accel_scaled_z)
        self.rotation_y = self.accelerometer.read_y_rotation(self.accel_scaled_x, self.accel_scaled_y, self.accel_scaled_z)

        now = time.time()
        self.time_diff = now - self.last_time
        self.last_time = now
        (self.pitch, self.roll) = self.comp_filter(self.rotation_x, self.rotation_y)
        return (self.pitch, self.roll, self.gyro_scaled_x, self.gyro_scaled_y, self.gyro_scaled_z, self.accel_scaled_x, self.accel_scaled_y, self.accel_scal$

    


    def read_pitch_roll_yaw(self):
        '''
        Return pitch, roll and yaw in radians
        '''
        (raw_pitch, raw_roll, self.gyro_scaled_x, self.gyro_scaled_y, \
            self.gyro_scaled_z, self.accel_scaled_x, self.accel_scaled_y, \
            self.accel_scaled_z) = self.read_all()

        now = time.time()
        self.time_diff = now - self.last_time
        self.last_time = now

        (self.pitch, self.roll) = self.comp_filter(raw_pitch, raw_roll)
        self.yaw = self.compass.read_compensated_bearing(self.pitch, self.roll)

        return (self.pitch, self.roll, self.yaw)

    def set_compass_offsets(self,x_offset, y_offset, z_offset):
        self.compass.set_offsets(x_offset, y_offset, z_offset)


 
I haven't included all the code, but If I was going to use the read_all function and then print out the results to the terminal... How would I do that ? I'll have to find shell Js and give it a reading
User avatar
Moki
Posts: 119
Joined: Oct 21st, 2014, 2:19 am
Location: The Netherlands

Re: Raspberry PI based ROV

Post by Moki »

I don't babble in Python... so most of what i type about Python... is just what i think (not know) or found using google

My guess, is that you need some way to "print" your data. =>

Code: Select all

print "{0:.4f} {1:.2f} {2:.2f} {3:.2f} {4:.2f} {5:.2f} {6:.2f}".format( time.time() - now, (last_x), gyro_total_x, (last_x), (last_y), gyro_total_y, (last_y))
So, using shelljs... you run your python program... and parse the output in javascript.
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

I babble about everything :)

Thanks for that Moki. I'll go and have a play with stuff. It appears from a little bit of research you can use socketio with python and indeed you can actually replace node Js with a sort of python equivalent. And still use it with sockets... any way a lot more reading to do on my behalf..
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

I've had a bit of time to start trying to learn this node and socket stuff.. Hmmm I'm not getting anywhere quick I'm afraid though I can do simple socket connections and say hello world.. so making progress... I still need to do some more java script learning.

What is express actually doing in your software Moki ? I installed it and it seemed to make folders and files like a code grenade had gone off and none of them actually seemed to do anything to my simple html web page.. It seems like it may be handy for an applications company that may continually change bits of the code but not sure how it fits in to our project. I'd like not to use it unless I have to...

Also I can see that cam 1 and 2 buttons are in the index.html file but where are you defining the lines and stuff ?
Thanks...
I've found node modules for my sensors so I hope that will make integration a bit easier...
User avatar
Moki
Posts: 119
Joined: Oct 21st, 2014, 2:19 am
Location: The Netherlands

Re: Raspberry PI based ROV

Post by Moki »

perfo wrote:I've had a bit of time to start trying to learn this node and socket stuff.. Hmmm I'm not getting anywhere quick I'm afraid though I can do simple socket connections and say hello world.. so making progress... I still need to do some more java script learning.
Keep at it, its not hard... just a lot of learning.

perfo wrote:What is express actually doing in your software Moki ? I installed it and it seemed to make folders and files like a code grenade had gone off and none of them actually seemed to do anything to my simple html web page.. It seems like it may be handy for an applications company that may continually change bits of the code but not sure how it fits in to our project. I'd like not to use it unless I have to...
Express is a module to make it easy to create a server. You don't have to use it, ofcourse. Its just easier.
perfo wrote:Also I can see that cam 1 and 2 buttons are in the index.html file but where are you defining the lines and stuff ?...
Lines and stuff? Do you mean the graphics? thats all just canvas drawing. Its all in the index.html part.

perfo wrote:Thanks...
I've found node modules for my sensors so I hope that will make integration a bit easier...
Yer welcome and i am sure it will be.
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

Thanks for the encouragement.
I'll have to dissect the index.html a bit better then as I missed the line bit. I tried commenting out all the code blocks to see If I could decipher the rest but may have over commented...
I'll have to read more about express as I can't see the assistance at the moment for a single simple (well simple for someone that knows what they are doing i guess) page like this but then ha I haven't managed to build a simple page yet so maybe that's why :)


I think what I need is some simple examples...
Do you know of any examples on the net where you have someone pressing a key on a key board and an led goes on (or off) on the RPI. (or something similar) If this was done using html node and sockets but literally just had those few elements it may get the penny to drop.. most examples I find on the net are either run locally for LED control or are part of a bigger project where the details get a bit lost in the code..
small simple examples seem to be short and far between on the net....
User avatar
Moki
Posts: 119
Joined: Oct 21st, 2014, 2:19 am
Location: The Netherlands

Re: Raspberry PI based ROV

Post by Moki »

All "lines" should have a "rov_context." in the index.html
As the line is draw on the context, which is a way to view the canvas in HTML5.

And if that fails "TRY HARDER! :D "

Or say "Please 8-) " and ill see if i can hack an example for you.
Post Reply