Update:
Major Goal Achieved!!!
Good news for a change. . . .
I have successfully implemented a “controller configuration file” into the New Remote Camera Robot, which allows me to define the axes and buttons that map to the various control functions of the robot.
Viz.:
File: gamepad_config.json
(These are the values for the Saitek X52 HOTAS joystick)
{
"Drive_LR": 0,
"Drive_FB": 1,
"Head_LR": 2,
"Head_UD": 3,
"Drive_Enable": 0,
"Turbo_Enable": 14,
"Head_Enable": 5
}
These items represent controller axis/button ID’s as defined by:
(taken from the JavaScript file - these numbers are the associations for the “standard” gamepad.)
// The file should look somthing like this: (order may not be important)
// {
// "Drive_LR": 0, (number of the axis you want to be L/R (x) axis on the controller)
// "Drive_FB": 1, (number of the axis you want to be F/B (y) axis on the controller)
// "Head_LR": 2, (number of the axis you want to be the head's LR (x) axis on the controller)
// "Head_UD": 3, (number of the axis you want to be the head's U/D (y) axis on the controller)
// "Drive_Enable": 6, (number of the button you want to be the "motion enable" button on the controller)
// "Turbo_Enable": 4, (number of the button you want to be the "turbo-mode enable" button on the controller)
// "Head_Enable": 5 (number of the button you want to be the "head-motion enable" button on the controller)
// }
The modifications to the base JavaScript browser side code look like this:
This is the part that actually loads and parses the config file into a JavaScript object structure. (Think Python dictionary)
// Global variables
var server_address = window.location.protocol + "//" + window.location.host + "/robot";
var get_request_address = window.location.protocol + "//" + window.location.host;
var joystick_data = [];
var js = [];
// Load the configuration file from the server and create a formal tree structure
// The file should look somthing like this: (order may not be important)
// {
// "Drive_LR": 0, (number of the axis you want to be L/R (x) axis on the controller)
// "Drive_FB": 1, (number of the axis you want to be F/B (y) axis on the controller)
// "Head_LR": 2, (number of the axis you want to be the head's LR (x) axis on the controller)
// "Head_UD": 3, (number of the axis you want to be the head's U/D (y) axis on the controller)
// "Drive_Enable": 6, (number of the button you want to be the "motion enable" button on the controller)
// "Turbo_Enable": 4, (number of the button you want to be the "turbo-mode enable" button on the controller)
// "Head_Enable": 5 (number of the button you want to be the "head-motion enable" button on the controller)
// }
// Ref: https://stackoverflow.com/questions/21450227/how-would-you-import-a-json-file-into-javascript
var gamepad_config;
var oReq = new XMLHttpRequest();
oReq.onload = reqListener;
oReq.open("get", get_request_address + "/static/gamepad_config.json", true);
oReq.send();
function reqListener(e) {
gamepad_config = JSON.parse(this.responseText);
}
And this is the modified code that actually reads the joystick values. Note the substitution of “gamepad_config” variable names for the original hard-coded axis/button ID’s.
// Collate data collects all the data, normalizes it, packages it,
// and prepares it for transmission to the 'bot'
function collate_data(jsdata) {
gopigo3_joystick.time_stamp = Number((jsdata.timestamp).toFixed(0));
gopigo3_joystick.x_axis = Number.parseFloat((jsdata.axes[gamepad_config.Drive_LR]).toFixed(2));
gopigo3_joystick.y_axis = Number.parseFloat((jsdata.axes[gamepad_config.Drive_FB]).toFixed(2));
gopigo3_joystick.force = Math.abs(gopigo3_joystick.y_axis);
gopigo3_joystick.trigger_1 = Number((jsdata.buttons[gamepad_config.Drive_Enable].value).toFixed(0));
gopigo3_joystick.trigger_2 = Number((jsdata.buttons[gamepad_config.Turbo_Enable].value).toFixed(0));
gopigo3_joystick.head_enable = Number((jsdata.buttons[gamepad_config.Head_Enable].value).toFixed(0));
Saying that I am jumping up and down is a masterpiece of understatement!
I have tried this with both the Saitek X52 joystick and the Logitech gamepad controller, and it works a treat!
Yippee! Yippee! Yippee!
(Jumping all around like a crazy man. . .)
Next Steps, communicate robot status to the browser.