Dutch Rov.

What are you working on .... Show off your Rov's Projects here.
User avatar
KR2_Diving
Posts: 391
Joined: Aug 30th, 2012, 11:43 am
Location: Currently: NW Suburbs of Chicago. Originally: NE Wisconsin

Re: Dutch Rov.

Post by KR2_Diving »

This read just like one of those headlines: "We can't make this stuff up!"

Great project!
fryslan76
Posts: 290
Joined: Dec 18th, 2012, 4:52 pm
Location: Netherlands

Re: Dutch Rov.

Post by fryslan76 »

Today I was rebuilding my ROV again and managed to fry my powerline unit my mixing the + and - pole :( Well next step is to find me an other powerline unit to complete the set again. And resoldering some cables to prevent it from happing again.
fryslan76
Posts: 290
Joined: Dec 18th, 2012, 4:52 pm
Location: Netherlands

Re: Dutch Rov.

Post by fryslan76 »

Got my self some presents a new Raspberry B+ and a Pi Camera. I realy sould have bougth that sooner. Had the camera working in a few hours and streaming to a webpage on my old Pi (model A) with a decent performance. Today I purchased a new Micro SD and switched all stuff to my new B+ model.

I used the post of Moki in de Raspberry Pi section to get met started with node.js and http://www.linux-projects.org/modules/s ... e&artid=14 to get a /dev/video0 device which I can use with different programs. It even includes a web server option so I do not have to do anything anymore on that :)
fryslan76
Posts: 290
Joined: Dec 18th, 2012, 4:52 pm
Location: Netherlands

Re: Dutch Rov.

Post by fryslan76 »

Finally found some time again to work on the ROV and take a few pictures. the hull design is almost completed in my head (always easy) and now I managed to piece together the internals on a board that fits in my hull. The basics are still to reuse material that I have around the house so far so good.
The whole board would fit (1m) but I am trying to make it as small as possible so less then 50 cm. The underside is for the batteries and for the power/network adapter if I manage to repair the fired one :roll:
More detailed overview.
More detailed overview.
20150526_224203_klein.jpg (688.05 KiB) Viewed 12677 times
overview of control board.
overview of control board.
20150526_224127_klein.jpg (599.73 KiB) Viewed 12677 times
I created some alu brackets to add an extra level so I could place the cables and USB hub below the Raspberry and the Arduino. Everything is zip-ty and screws because this is supposed to be version one :D
fryslan76
Posts: 290
Joined: Dec 18th, 2012, 4:52 pm
Location: Netherlands

Re: Dutch Rov.

Post by fryslan76 »

Had to read my own build thread to figure out what my original plans where, after three year of no ROV building. So far no success, so I will scrap everything and start again.

First order of the day, design some building blocks:

Topside - laptop & keyboard nothing fancy
Tether - UTP cable or 2 powerline connecters for a two wire setup. Still my preferred connection, easy to waterproof.
ROV - PI version 2 model B, with PI Camera. Arduino for sensors and motor control.
Lights – led dive light I have for diving.
Camera – For recording I will attach my diving camera to the ROV, the pi camera is for steering.
fryslan76
Posts: 290
Joined: Dec 18th, 2012, 4:52 pm
Location: Netherlands

Re: Dutch Rov.

Post by fryslan76 »

Oke have been playing with Python and motor control from my Pi through the Arduino.
I forward my UI of my ROV PI through the network to my laptop.
Communication between the PI and the Arduino is based on the Firmata protocol.
Since all sliders are blocked during stand-up I can send a 90 to all servo ports to initialise my ESC. When that is done I unblock the sliders and I have control over the motors.

Code: Select all

from Tkinter import *
import pyfirmata

# Activate Arduino
board = pyfirmata.Arduino('/dev/ttyACM0')
Left_pin = board.get_pin('d:5:s')
Right_pin = board.get_pin('d:6:s')
Up_pin = board.get_pin('d:9:s')
        
def switchSliderState():
    # Initial all slider are block so ESC receive a neutral value
    if (scale5['state'] == NORMAL):
        scale5['state'] = DISABLED
        scale6['state'] = DISABLED
        scale9['state'] = DISABLED
        esc5.set(90)
        esc6.set(90)
        esc9.set(90)
        ChangeLeft(esc5.get())
        ChangeRight(esc6.get())
        ChangeUp(esc9.get())        
    else:
        scale5['state'] = NORMAL
        scale6['state'] = NORMAL
        scale9['state'] = NORMAL

def ChangeLeft(left):
    valueLeft = "Left = "+str(left)
    leftDrive.config(text=valueLeft)
    Left_pin.write(left)

def ChangeRight(right):
    valueRight = "Right = "+str(right)
    rightDrive.config(text=valueRight)
    Right_pin.write(right)

def ChangeUp(up):
    valueUp = "Up = "+str(up)
    upDrive.config(text=valueUp)
    Up_pin.write(up)

def sel():
   selection = "Value = " + str(esc5.get())
   label.config(text = selection)

root = Tk()
esc5 = IntVar()
esc6 = IntVar()
esc9 = IntVar()
scale5 = Scale( root, command = ChangeLeft, label = "left", state= DISABLED, variable = esc5, tickinterval=30, length = 180, orient=VERTICAL, from_ = 0, to_ = 180 )
scale6 = Scale( root, command = ChangeRight, label = "right", state= DISABLED, variable = esc6, tickinterval=30, length = 180, orient=VERTICAL, from_ = 0, to_ = 180 )
scale9 = Scale( root, command = ChangeUp, label = "up", state= DISABLED, variable = esc9, tickinterval=30, length = 180, orient=HORIZONTAL, from_ = 0, to_ = 180 )

# ESC with reverse need to arm at center point 
esc5.set(90)
scale5.pack(side=LEFT)
esc6.set(90)
scale6.pack(side=RIGHT)
esc9.set(90)
scale9.pack(side=BOTTOM)

button = Button(root, text="(de)activa sliders", command=switchSliderState)
button.pack(side=BOTTOM)

leftDrive = Label(root)
leftDrive.pack(side = TOP)
upDrive = Label(root)
upDrive.pack(side = TOP)
rightDrive = Label(root)
rightDrive.pack(side = TOP)

# Display initial values
ChangeLeft(esc5.get())
ChangeRight(esc6.get())
ChangeUp(esc9.get())

# write pin values neutral
Left_pin.write(90)
Right_pin.write(90)
Up_pin.write(90)

root.mainloop()
fryslan76
Posts: 290
Joined: Dec 18th, 2012, 4:52 pm
Location: Netherlands

Re: Dutch Rov.

Post by fryslan76 »

On some occasions I still tinker with my ROV, mostly reading here what other people are building. My build project are mostly centred around my house and barns.
Anyway I dropped frimata as method of communication. The implementation was not reliable enough on lots of occasions the ESC would not start. I switched the code to use pigpio directly on the PI using the set_servo_pulsewith seems to be a reliable method of working with my motors.
Adding now the HMC5883L chip for navigation, got data from it now I need to interpreted this correctly. The communication for this seems to load the PI so I might offload that to the arduino.
fryslan76
Posts: 290
Joined: Dec 18th, 2012, 4:52 pm
Location: Netherlands

Re: Dutch Rov.

Post by fryslan76 »

Code: Select all

from tkinter import *
import pigpio
import time
import struct

# foutmelding root /dev/gpiomem
# chgrp gpio /dev/gpiomem
# chmod g+rw /dev/giomem

def switchSliderState():
    # Initial all slider are block so ESC receive a neutral value
    if (scaleLeft['state'] == NORMAL):
        scaleLeft['state'] = DISABLED
        scaleRight['state'] = DISABLED
        scaleUp['state'] = DISABLED
        escLeft.set(0)
        escRight.set(0)
        escUp.set(0)
        ChangeLeft(escLeft.get())
        ChangeRight(escRight.get())
        ChangeUp(escUp.get())        
    else:
        scaleLeft['state'] = NORMAL
        scaleRight['state'] = NORMAL
        scaleUp['state'] = NORMAL

def ChangeLeft(left):
    valueLeft = "Left = "+str(left)
    leftDrive.config(text=valueLeft)
    pi.set_servo_pulsewidth(17,1500+10*escLeft.get())
    
def ChangeRight(right):
    valueRight = "Right = "+str(right)
    rightDrive.config(text=valueRight)
    pi.set_servo_pulsewidth(18,1500+10*escRight.get())
 
def ChangeUp(up):
    valueUp = "Up = "+str(up)
    upDrive.config(text=valueUp)
    pi.set_servo_pulsewidth(27,1500+10*escUp.get())

def ReadAccelerometer():
    read = 0
    start_time = time.time()

    while (time.time()-start_time) < RUNTIME:

        # 0x3 = X MSB, 0x4 = X LSB
        # 0x5 = Y MSB, 0x6 = Y LSB
        # 0x7 = Z MSB, 0x8 = Z LSB

        # > = big endian

        (s, b) = pi.i2c_read_i2c_block_data(h, 0x03, 6)

        if s >= 0:
            (x, y, z) = struct.unpack('>3h', buffer(b))
            print("{} {} {}".format(x, y, z))
            read += 1    
            valueAcc= "Accel = "+"{} {} {}".format(x, y, z)
            labelAccel.config(text=valueAcc)
                
        root.after(1000, ReadAccelerometer)

# inital program
#
# GPIO 17 pin 11 Left
# GPIO 18 pin 12 Right
# GPIO 27 pin 13 Up/ Down

#accelerometer
buffer = memoryview
BUS=1
HMC5883L_I2C_ADDR=0x1E
RUNTIME=60.0

# handle exceptions in the program
pigpio.exceptions = True

pi = pigpio.pi()
if not pi.connected:
    print("No connection to PiGPIO")
    exit()

# Pins set to output default frequency
pi.set_mode(17, pigpio.OUTPUT)
pi.set_mode(18, pigpio.OUTPUT)
pi.set_mode(27, pigpio.OUTPUT)
        
# write pin values neutral
pi.set_servo_pulsewidth(17,1500)
pi.set_servo_pulsewidth(18,1500)
pi.set_servo_pulsewidth(27,1500)

h = pi.i2c_open(BUS, HMC5883L_I2C_ADDR)

if h < 0: # Not Connected OK?
    print("No accelerometer found")
    exit()

# Initialise HMC5883L.
pi.i2c_write_byte_data(h, 0x00, 0xF8)  # CRA 75Hz.
pi.i2c_write_byte_data(h, 0x02, 0x00)  # Mode continuous reads.

root = Tk()
        
while True:         
    escLeft = IntVar()
    escRight = IntVar()
    escUp = IntVar()

    scaleLeft = Scale( root, command = ChangeLeft, label = "left", state= DISABLED, variable = escLeft, tickinterval=10, length = 500, orient=VERTICAL, from_ = 50, to_ = -50 )
    scaleRight = Scale( root, command = ChangeRight, label = "right", state= DISABLED, variable = escRight, tickinterval=10, length = 500, orient=VERTICAL, from_ = 50, to_ = -50 )
    scaleUp = Scale( root, command = ChangeUp, label = "up", state= DISABLED, variable = escUp, tickinterval=10, length = 500, orient=HORIZONTAL, from_ = 50, to_ = -50 )

    # ESC with reverse need to arm at center point 
    escLeft.set(0)
    scaleLeft.pack(side=LEFT)
    escRight.set(0)
    scaleRight.pack(side=RIGHT)
    escUp.set(0)
    scaleUp.pack(side=BOTTOM)

    button = Button(root, text="(de)activa sliders", command=switchSliderState)
    button.pack(side=BOTTOM)

    leftDrive = Label(root)
    leftDrive.pack(side = TOP)
    upDrive = Label(root)
    upDrive.pack(side = TOP)
    rightDrive = Label(root)
    rightDrive.pack(side = TOP)
    labelAccel = Label(root)
    labelAccel.text=("Accel=")
    labelAccel.pack(side = TOP)

    # Display initial values
    ChangeLeft(escLeft.get())
    ChangeRight(escRight.get())
    ChangeUp(escUp.get())

    # Accelerometer
    #ReadAccelerometer()

    root.mainloop()

# clean-up stuff
print("Goodbye clean-up now")
pi.set_servo_pulsewidth(17,0)
pi.set_servo_pulsewidth(18,0)
pi.set_servo_pulsewidth(27,0)
#pi.set_PWM_dutycycle(17,0)
#pi.set_PWM_dutycycle(18,0)
#pi.set_PWM_dutycycle(27,0)

pi.i2c_close(h)
pi.stop()
exit()
My Pi2 freezes when I run everything together so disabled the Accelerometer.
Post Reply