Please help complete this project!!

Hi, yet again I am reviving my ongoing ROV project. I am determined to have a working ROV before the summer.
just a recap. I am using two PicoBorg Reverse, one is controlling two bilge pumps which steer the Rov in forward/ reverse and left and right direction. The second controls two more bilge pumps which allows the ROV to ascend and dive.
Using a modified WEB ui code. and accessing http://my address:8088/ I can control all motors on the ROV . I have buttons for forward, reverse, left and right. Additionally I have UP and Down buttons. Whilst on this page all controls work as intended i.e. the motors on the ROV turn when a button is pushed on my laptop.

Im also using the /hold which has been modified to use two Picoborg reverses. Again I have buttons for Forward , Reverse, Left and Right and also Up and Down. I am using # 38=UP 40=DOWN 37=LEFT 39=RIGHT as well as 85=PAGE UP 68=PAGE DOWN for up and down. Using this page I am able to use Forward , Reverse, Left and Right but not up and down.
In my attached code I only have one motor being used for up and down as I do not know how I should label motor 2.

Can you please have a look at my code and help get this working. Your help over the past 5 yrs has bee amazing.

Attachments: 
piborg's picture

Based on a quick look I have some thoughts on what the problem might be.

First I think the key codes for page up and down are wrong. Based on a quick check I think it should be:
33 = PAGE UP
34 = PAGE DOWN
You can check the actual key codes you need here: https://www.toptal.com/developers/keycode

Second there is a line that sets the initial state of the map array:

httpText += 'var map = {38: false, 40: false, 37: false, 39: false, 90: false, 88: false};\n'

The last two entries do not match the key codes you are looking at. With the first change this should be:

httpText += 'var map = {38: false, 40: false, 37: false, 39: false, 33: false, 34: false};\n'

The order they are set in does not matter :)

Finally I would duplicate the rise value to both outputs like you have done on the up / down button version.

            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,valRise);\n'
            httpText += '  }\n'

Thanks for your input however it still isn't working !
I changed everything you suggested and have fiddled with other ideas but I still cannot get my 2nd Picoborg reverse to be recognised by the buttons. I'm thinking Drive2 has not been defined in the Key Management section. Also Drive 1 has left and right labels should Drive 2 not be labled in a similar fashion.

# key management ------------------------------------------------
# 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 += 'var valRise = 0;\n'
httpText += 'function checkKey() {\n'
httpText += 'valLeft = 0;\n'
httpText += 'valRight = 0;\n'
httpText += 'valRise = 0;\n'
Awaiting your thoughts

John

Attachments: 
piborg's picture

Did you check what the correct key codes are on the computer you are using to control your ROV?
Here is the link again: https://www.toptal.com/developers/keycode

Hi, yes my codes match the keyboard.
Whilst using the /hold page I am able to use the mouse curser and also the touch screen to
click on the onscreen buttons which register on the speed indicator. Doing this also makes the motors turn in their respective directions. This is only true for the buttons relating to board 1(forward, reverse etc)
When trying the above with board 2 buttons( , up& down) there is no response either with the speed indicator or the motors.

When using the / page all buttons and motors respond to clicking with the mouse and touch screen.
I think it's something to do with the labeling in the
httpText += 'var valRise = 0;\n' section.

Many thanks

John

piborg's picture

I didn't realise it was the buttons you were having problems with, I thought it was the key controls only :)
If you are not using the keyboard then you can probably ignore the "key management" section.

I think the actual problem is that in the standard controls you added a second speed slider which is missing from the hold controls:

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

Because it is missing the Drive2 function will fail when it tries to lookup speed2.value, which is why it is not working.

Thank you , I added the second speed slider as suggested and all buttons are now working when using the mouse or touch screen to click the buttons. Also buttons relating to board 1 ie forward reverse etc work when using the keyboard.
However the buttons for board 2 controls ie up and down do not!!
Also how would I add a second motor speeds percentage indicator that shows board 2 motor speeds.

Any thoughts.

John

piborg's picture

Making a second status should be easy, this is the status panel:

httpText += '<iframe id="setDrive" src="/off" width="100%" height="50" frameborder="0"></iframe>\n'

Make another copy and label it setDrive2:

httpText += '<iframe id="setDrive" src="/off" width="100%" height="50" frameborder="0"></iframe>\n'
httpText += '<iframe id="setDrive2" src="/off" width="100%" height="50" frameborder="0"></iframe>\n'

Now in the Drive2 function change iframe from setDrive to setDrive2.

Finally Off should be changed to update both panels:

            httpText += 'function Off() {\n'
            httpText += ' var iframe = document.getElementById("setDrive");\n'
            httpText += ' iframe.src = "/off";\n'
            httpText += ' var iframe2 = document.getElementById("setDrive2");\n'
            httpText += ' iframe2.src = "/off";\n'
            httpText += '}\n'

It looks like you have two copies of the Off function, so remove the extra one as well.

At this point I would try it again and see how the values for the motors compare between using the buttons and using the keyboard.

Subscribe to Comments for &quot;Please help complete this project!!&quot;