I am building an underwater robot, which can move Up/Down, Forward/Reverse, controlled by a Joystick.
The situation is like this :
USB Joystick is connected to a PC, PC is connected to an Arduino via tether cable (Ethernet), and motors of the robot are connected to the arduino.
The joystick I am using is having 2 sticks, and I have decided to use 1 stick to control the UP-DOWN movement (Actually, I'm using only 1 axis of that stick for this.) and the 2nd stick to control the LEFT-RIGHT movement.
My question is, Whenever the user manipulates both the sticks simultaneously (To achieve diagonal motion, for example), The joystick will send 2 signals, one after the other, one for each stick. Keeping in mind the limited receiver buffer size of the arduino, how do I program the arduino, such that it can understand the difference between linear motion signal and diagonal motion signal?
I am highly motivated to program this on my own. I just need an Intuition for this.
A thought came to my mind is, to use the following strategy:
For my Up-down stick value, I add a character such as 'U'
, followed by the integer joystick value. For E.g. I send "U4"
to go up at speed 4
. With some twitching, I can even send down signal with the same preceding character U
.
Similarly, for Forward/Backward, I send "F3"
to go fwd/bkwd at speed 3
. And for diagonal, I send something like "T5"
to go diagonally at speed 5.
My concern with this is, I will transmit 2 characters from the PC to Arduino. Will the arduino be able to read such 2 characters, interpret them and act accordingly, without the noticeable lag? Or is there any other better way?
This also makes me wonder, how commercial robots (such as Commercial Drones) handle such situations?
The movements the robot will make needs to be quick. There should not be "visible" lag, That is, the user should not feel that the Robot is responding after a couple of seconds.