Python Notebook for controlling the ROV


#1

For those interested in python bindings to control the ROV, I have started a project that shows how to call the API from Python in the form of a ipython notebook. Feel free to fork and improve! Big call out to Jim T. for finding the python socket.io library and doing the initial initial ground work!

https://github.com/BrianAdams/openrov-python-notebook


Connecting to Arduino via c++
#2

This may make it easier for folks to browse: http://nbviewer.ipython.org/github/BrianAdams/openrov-python-notebook/blob/master/OpenROVSockIOTest.ipynb


#3

Hi,

Do you have a sample script *.py or commands which get IMU data in real-time? I would like to write a program capturing image from camera and save with IMU data.


#4

I have not put together any additional scripts explicitly for interacting with the APIs yet. Feel free to share any you come up with!


#5

I can grab image from camera and partial IMU data, but don’t have any idea how to put together (one script) with time synchronization. Maybe anybody help me? The scripts are below (Software - 30.0.2). Also I have a issue to get accel and magnetometer data. This guide: Hacking in raw IMU accelleration and mag values is out of date. In file MPU9150.cpp, gyroscope calibration code like this:

navdata::HDGD = MPU.m_fusedEulerPose[VEC3_Z] * RAD_TO_DEGREE;
navdata::PITC = MPU.m_fusedEulerPose[VEC3_X] * RAD_TO_DEGREE+3.3;
navdata::ROLL = (MPU.m_fusedEulerPose[VEC3_Y] * RAD_TO_DEGREE)+4;
navdata::YAW = MPU.m_fusedEulerPose[VEC3_Z] * RAD_TO_DEGREE;

doesn’t work. Where I should change the code to get properly visualization in the cockpit? Any *.js file?

Stream.py:

import cv2
import urllib
import numpy as np
from datetime import datetime

stream = urllib.urlopen("http://@192.168.254.1:8090/?action=stream")
directory = 'data' 

bytes=''
while True:
    bytes+=stream.read(1024)
    a = bytes.find('\xff\xd8')
    b = bytes.find('\xff\xd9')
    if a!=-1 and b!=-1:
        jpg = bytes[a:b+2]
        bytes= bytes[b+2:]
        i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.IMREAD_COLOR)
        cv2.imshow('i',i)
        utcTime = datetime.utcnow().strftime('%H_%M_%S_%f')[:-3]
        cv2.imwrite(directory + "\\" + utcTime + ".png", i)

        if cv2.waitKey(1) == 27:
            
            cv2.destroyAllWindows()
            exit(0)

OpenROV_control.py:

from socketIO_client import SocketIO, BaseNamespace
from datetime import datetime
import time
import os

def savedata(directory, filename, data):
    try:
        if not os.path.exists(directory):
            os.makedirs(directory)
            
        datafile = open(directory + "\\" + filename, 'w+')

        try:
            datafile.writelines(data)
        finally:
            datafile.close()
    except IOError as e:
        print "I/O error({0}): {1}".format(e.errno, e.strerror)

class Namespace(BaseNamespace):
 
    def on_connect(self):
        print '[Connected]'

def on_data_response(*args):
    #print 'navdata', args
    lista = str(args[0]).split("'")
   
    try:        
        #ComputerTime = time.strftime("%H:%M:%S") + ","
        utcTime = datetime.utcnow().strftime('%H_%M_%S_%f')[:-3] + ","
        hdgd = lista[lista.index('hdgd')+2] + ","
        pitch = lista[lista.index('pitch')+2] + ","
        roll = lista[lista.index('roll')+2] + ","
        yaw = lista[lista.index('yaw')+2] + ","
        depth = lista[lista.index('deapth')+2] + ","
        pres = lista[lista.index('pres')+2] + ","
        temp = lista[lista.index('temp')+2] + ","
        thrust = lista[lista.index('thrust')+2]

        dane.append(utcTime + hdgd + pitch + roll + yaw + depth + pres + temp + thrust + "\n")
        
    except ValueError as e:
        print e
        dane.append(utcTime + str(e) +"\n")

def on_status_response(*args):
    print 'status ', args
    #socketIO.emit('brightness_update',0)

############################################################################
print "start"
            
directory = 'data'
filename = 'DATA_' + datetime.utcnow().strftime('%H_%M_%S_%f')[:-3] + '.dat'
dane = []
scanTime = 10 #seconds

socketIO = SocketIO('192.168.254.1', 8080, Namespace)

#socketIO.on('status', on_status_response)

socketIO.on('navdata', on_data_response)

print "wait " + str(scanTime) + " seconds"

socketIO.wait(scanTime)
savedata(directory, filename, dane)

print "stop..."