Greetings!
I hope this finds you safe and well.
Issue:
I am trying to develop a web app, (combination html and javascript), to control a robot with a joystick.
N.B. I don’t understand why, but there doesn’t seem to be ANY code or examples for using an actual joystick to control a server-side “thing”. It’s all “virtual joysticks” like nipple.js, etc.
Right now my code is organized like this:
(This is a very high-level overview)
- Event handler for “gamepad connected”
- Event handler for “gamepad disconnected”
- Request Animation Frame(poll the gamepad)
- Gamepad Polling Logic
This grabs data from the gamepad, does some minimal logic testing so that the data makes sense, (X and Y axis values don’t matter if the robot isn’t moving), and updates values that are - for the time being - placed on the browser screen as an overlay.
- Gamepad Polling Logic
If I understand correctly, the “Request Animation Frame” function calls my gamepad polling logic once every v_sync interval which is a LOT of activity, especially if I am going to be transmitting data over a network to a wireless robot.
What I’d really like to do is something like this:
(syntax may not be correct, this is psudo-code to demonstrate what I am trying to do.)
window.addEventListener (gamepad.event)
, such that “gamepad.event” would return whatever the event is.
For example:
window.addEventListener (gamepad.event) {
if (gamepad.event == "gamepadconnected"
{
gamepad connected logic
}
elseif (gamepad.event == "gamepaddisconnected")
{
gamepad disconnected logic
}
else
{
Poll for gamepad data changes
and send updated data to the robot
}
}
This way I ONLY send data to the robot if there is something worth sending.
I’d really rather not send data 60 times a second, (or whatever), if I don’t have to because that is wasteful of bandwidth, is totally unnecessary, and complicates things on the robot’s end.
Question:
Is this possible? Does this exist?
Corollary question:
If that does NOT exist, how do I go about throttling the data such that I only send data of interest to the robot? (i.e. Only if the data is changing - a joystick axis value change, a button press, etc.) I really don’t want to send 20,000 “trigger-pressed” messages to the robot if I don’t have to.