Major progress to report - I’ve cracked this thing wide open!
The first major step is now 99% done. I can drive the robot around using the mouse and the nipple.js libraries and move the pan-and-tilt using the arrow keys on the keyboard.
What went wrong:
It turns out that I was, indeed, “barking up the wrong tree” by trying to analyze and re-factor the nipple.js code. It’s complicated, it’s convoluted, and it has more classes and methods than an Ivy-League University!
More important, I had lost sight of the fact, (actually, didn’t realize it at first), that nipple.js is a library that is there for my convenience just like the GoPiGo3 and EasyGoPiGo3 libraries - though I will admit that the nipple.js library makes the GoPiGo libraries look like 1975 Standard Basic, right out of Dartmouth College, (where it was invented).
N.B. For those who don’t know this, “Basic” is NOT an acronym, like FORTRAN or COBOL - it’s the actual name of the language, like Python is the name of the language most of us use on the Pi.
Once I realized that re-factoring the nipple.js code was a nightmare waiting to happen, I took a step back and looked at the over-all project again, this time zeroing in on the index.html file. I also made a major step when I decided to fork the remote-robot code and create a stripped-down copy to experiment with HTML messages and head movement.
THIS was the nut to crack - understanding how messages were passed back-and-forth between the browser and the server instance on the 'bot itself. The stripped down code - my “head servo test” code - allowed me to concentrate on the server and client side messaging routines.
The first step was to figure out how to “capture” the communication that was already happening via the HTML and nipple.js files and re-direct it to controlling the servos.
Once that was done, I spent a while concentrating on how keyboard events are handled. Unfortunately, every example and article I found assumes that you want to capture the event within the context of the web page itself, not as a message to be sent back to the server. Figuring that out was like unfolding a gas-station map, (remember those?), and figuring out how to get it folded back up again!
Finally, today, I have working code that will capture the key-events I want and ignore the events I don’t want. I also took the opportunity to re-factor the servo motion code to more effectively modularize it.
The last step was to merge these changes back into the basic Remote Camera Robot code. Just in case you didn’t know, merging “test” code into the main code fork is not a task for the faint hearted. Once that was done - and all the dangling participles were weeded out - the code is now just about 99% working.
There are a few regressions in there, (controlling the robot’s movements is now not working properly), but that’s likely to be some test-code that I left in the base HTML by mistake.
Once I get it working, I’ll make a video and upload it.