Doing this project with voice recognition only

Doing this project strictly with voice recognition I ran into a problem I want the forward button to keep the rover moving forward until I tell it to stop. Since I have no use of my arms I want to start automating it. I'm thinking it has to do with how many cycles per click

piborg's picture

Without knowing how your voice recognition works it is a little tricky to help with this one.
Hopefully I can point you in the right direction :)

In our diddyWeb.py script we have two variations on how the controls work.
Using 192.168.0.198 as an example IP address for the robot:

  1. http://192.168.0.198 - Provides buttons which have to be pressed to change speed.
    This means clicking Forward will keep going along until Stop is clicked.
  2. http://192.168.0.198/hold - Provides buttons which have to be held to keep going.
    This does not work on all devices and may behave strangely with voice controls.

In this case the difference between the two in code is:

  1. Sends a single command when the button is pressed to perform the movement
  2. Sends one command when the button is pressed down to perform the movement, a second is sent when the button is released to stop the movement

The code in diddyWeb.py should only change speeds when:

  • A command is sent from the device to make a change
  • No communication has happened for over a second

The script communicates regularly to grab the camera image, so "no communication" should only happen when the device is not trying to control the robot any more.

I am using windows speech recognition. So when I open up the web UI in my browser I just say " forward" or any other button and the browser button gets clicked. I've tried changing the onmouseup from off() to on() that didn't work since I'm not using a mouse. I've also tried onmouseover on() so maybe if I hover over it, it would stay on, still the forward button stops after a few revolutions or seconds. I want it so when I say the command like "forward" it would go forward until I say " left" " right" or any other button command, I probably need a while loop . How can I change the time the motors go on per click?

piborg's picture

Which version of the controls are you using:

  1. The standard controls: http://192.168.0.198
  2. The alternative controls: http://192.168.0.198/hold

I've tried both. Also tried to look at the pico reverse python file, but I'm stuck.

piborg's picture

I think we should stick with the http://192.168.0.198 version, this only sends single command when each button is pressed.

I suspect your problem is the watchdog timer in the script deciding your browser has disconnected.
If you comment out the following lines in diddyWeb.py it should stop the watchdog running:

print 'Setup the watchdog'
watchdog = Watchdog()

and

watchdog.terminated = True

To comment a line out add a # symbol to the start of the line.

I tried commenting out what you told me but I got the following error(uploaded below):
Watchdog not defined! So I tried leaving watchdog= watchdog() alone and comment out the others you told me. Still not working.

What is watchdog and where is it defined? I've also been looking at the other examples like Diddy sequence.py code and there's a part there I took a snippet of the section I uploaded down there. It's under #movement settings, "timeForward1m=5.7" #number of seconds to move. Is there a way to incorporate this code to webui.

Another idea I got was to experiment with under the "httptext+= Drive(1,1)", what is drive and where is it defined?

Images: 
piborg's picture

My mistake, there are a couple more lines which need to be commented out.

The full list is:

        watchdog.event.set()
print 'Setup the watchdog'
watchdog = Watchdog()
watchdog.terminated = True
watchdog.join()

All the watchdog does is check if the browser is still talking to the script.
If it has not seen any messages from the browser for more than 1 second it stops the DiddyBorg moving.
This is why I suspect it may be the cause of your problem.

Thank you so much. Works like a charm. Next I think I wanna make it to avoid obstacles semiautomatic, maybe work with opencv with an extra camera for stereo vision or ultrasonic sensors.

How would I a dd buttons that would control the speed, just by calling out the speed like 100% or 75%. Since I'm only doing this by voice the speed bar at the bottom is kind of complicated to operate by voice.

piborg's picture

What you will need to do is add a button which changes the position of the slider.

For example this is the HTML code for a button which sets the slider to 50% speed:

<button onclick="speed.value=50" style="width:200px;height:100px;"><b>50%</b></button>

You will need to add this to the httpText values in the elif getPath == '/': section.
This is the finished line for a 50% speed button:

            httpText += '<button onclick="speed.value=50" style="width:200px;height:100px;"><b>50%</b></button>\n'

The speed set is the =50 part, the values are from 0 to 100.
The text on the button is the 50% part.
You should be able to add as many buttons as you like :)

The new speed will be used on the next direction button clicked.

Hi, using the above modifications to the Web gui script i.e. adding an extra speed/direction control button. How could I use this to control the speed of the motors on a second picoborg reverse connected by daisy chain.
Thanks.

piborg's picture

Are you trying to control the two boards independently, or do they operate as a pair?

Hi thanks for the reply. Once again I'm trying to get my ROV working. The two boards would operate independently of each other. board 1would move the ROV forward and back whilst board 2 would allow the ROV to ascend and descend.
I like the web gui as it would allow me access to the ROV via an CAT5 cable tether and streams video from the raspberry pi.
Yes there are other methods and product out there but I'm trying to soley use a raspberry pi and piborg products.
I've reposted this as a new post so please ignore that one.

piborg's picture

This will probably need a few changes to get the behaviour you want to work.

First you will want to duplicate the section that starts:

elif getPath.startswith('/set/'):

and give it a new name, such as set2. This should be made to set the power levels on the second board.

Second you will want another slider to select the speed for the board. Look for these lines:

httpText += '<input id="speed" type="range" min="0" max="100" value="100" style="width:600px" />\n'

and duplicate them with an id of speed2 instead.

Third you will want a second drive function. Look for these sections:

            httpText += 'function Drive(left, right) {\n'
            httpText += ' var iframe = document.getElementById("setDrive");\n'
            httpText += ' var slider = document.getElementById("speed");\n'
            httpText += ' left *= speed.value / 100.0;'
            httpText += ' right *= speed.value / 100.0;'
            httpText += ' iframe.src = "/set/" + left + "/" + right;\n'
            httpText += '}\n'

Make a copy of each with the following changes:

  1. Change Drive to Drive2
  2. Change speed to speed2
  3. Change set to set2

Finally when you add your new buttons call the new Drive2 function just like the existing ones do with Drive. For example:

httpText += '<button onclick="Drive2(-1,0)" style="width:200px;height:100px;"><b>Descend</b></button>\n'

This should allow you to control both the speed and operation of the third axis separately from the first board. You should also be able to create speed buttons in the same way as mentioned earlier in this thread but setting speed2 instead.

I've eventually got around to buying my second PicoBorg reverse. I have followed the above instructions (correctly I think)
I'm able to see new buttons in the WeGUI but they do not work as intended.
When dvice 11 is first in the chain it works but not 12. If 12 is placed first it works but not 11. Both devices are detected.

ideally I want two motors on device 11 to control Forward /reverse/left /right. device 12 only has 1 motor for up/down.
Also I need up down buttons on the key board ideally + and - could you help with this?

Hope I make sense.

BTW im only using the / path and /joystick path
P.s just noticed in my attached script (Web.txt) I have commented out i2c 12 this was only for testing and forgot to uncomment it prior to posting.
John

Attachments: 
piborg's picture

You are only setting up a single PBR object in the code, this can only control a single board. To control both at once you will need to setup two objects, say PBR1 and PBR2, and set them to the correct address for that board. You can then control each output by using the correct combination of board and motor, e.g. PBR1.SetMotor1.

In the most basic form the setup would now look like this:

# Board #1, address 11 (hex)
PBR1 = PicoBorgRev.PicoBorgRev()
PBR1.i2cAddress = 0x11
PBR1.Init()
PBR1.ResetEpo()
# Board #2, address 12 (hex)
PBR2 = PicoBorgRev.PicoBorgRev()
PBR2.i2cAddress = 0x12
PBR2.Init()
PBR2.ResetEpo()

A more complete setup based on your current setup code would look something like this:

# Setup both PicoBorg Reverses
PBR1 = PicoBorgRev.PicoBorgRev()
PBR2 = PicoBorgRev.PicoBorgRev()
PBR1.i2cAddress = 0x11
PBR2.i2cAddress = 0x12
PBR1.Init()
PBR2.Init()
if not PBR1.foundChip or not PBR2.foundChip:
    boards = PicoBorgRev.ScanForPicoBorgReverse()
    if len(boards) == 0:
        print ('No PicoBorg Reverses found, check you are attached :)')
    else:
        print ('One or more PicoBorg Reverses are missing, but we did find boards:')
        for board in boards:
            print ('    %02X (%d)' % (board, board))
        print ('If you need to change the I²C address change the setup line so it is correct, e.g.')
        print ('PBR.i2cAddress = 0x%02X' % (boards[0]))
    sys.exit()
# Uncomment the two lines below to disable EPO latch, needed if you do not have a switch / jumper
#PBR1.SetEpoIgnore(True)
#PBR2.SetEpoIgnore(True)
# Disable the communications failsafe
PBR1.SetCommsFailsafe(False)
PBR2.SetCommsFailsafe(False)
PBR1.ResetEpo()
PBR2.ResetEpo()

Thank you so much. Using the above script ie 2 picoborg reverse would you be able to help showing me how to add an extra button to the keyboard part of the webui. Again it would control the second picoborg making my RoV to ascend and descend. I use this on my attached laptop.
I'm nearly finished my Rov (submersible) and will post pics and a write up shortly
Thanks again for your help.

John

piborg's picture

All of the keyboard controls are in the "key management" section of the script.

The first thing is you will want the key codes for raising and lowering. I will use Page Up - 33 and Page Down - 34. This site can tell you what the correct code is for any key you want: https://www.toptal.com/developers/keycode

Start by changing the top section to have a third value for the rise motor

            # 38=UP 40=DOWN 37=LEFT 39=RIGHT 33=PAGE UP 34=PAGE DOWN
            httpText += 'var valLeft = 0;\n'
            httpText += 'var valRight = 0;\n'
            httpText += 'function checkKey() {\n'
            httpText += 'valLeft = 0;\n'
            httpText += 'valRight = 0;\n'
            httpText += 'valRise = 0;\n'

Next you will need to check for these keys and set the rise motor power accordingly.

            #PAGE UP
            httpText += '  if (map[33]) {\n'
            httpText += '      valRise = 1;\n'
            httpText += '  }\n'
            #PAGE DOWN
            httpText += '  if (map[34]) {\n'
            httpText += '      valRise = -1;\n'
            httpText += '  }\n'

Now you can add this value to the action section and the two new keys into the map value:

            #ACTION
            httpText += '  if (valLeft == 0 && valRight == 0 && valRise == 0) {\n'
            httpText += '      Off();\n'
            httpText += '  }\n'
            httpText += '  else {\n'
            httpText += '      Drive(valLeft,valRight);\n'
            httpText += '      Drive2(valRise,0);\n'
			httpText += '  }\n'
            httpText += '}\n'
            httpText += 'var map = {38: false, 40: false, 37: false, 39: false, 33: false, 34: false};\n'

Don't forget to turn the motors on both boards off in the /off section.

.

Hi Adam, (or anyone else that can help)
This is exactly what i am trying to do, i am fairly new to all this raspberry pi stuff but loving everything so far,
basically i work with children with additional needs in a school and i am trying to create a buggy (like the diddy borg) to run on voice commands so the children just need to speak to get it to move etc. so far due to my lack of knowlage i am stuck.
please could you tell me (i am using a diddy borg thats all built up and runs perect using the diddyjoy.py sode using a rock candy controller) so basically how do i get that setup to run on voice commands.
you may need to explain it in a very basic way for me as i am still learning lol
many thanks
Tim.

Subscribe to Comments for &quot;Doing this project with voice recognition only&quot;