1

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.

1
  • How exactly are you transmitting data between PC and Arduino? As I understood, you use ethernet. But how are you sending and receiving the data itself? Simple packets? Web sockets? That can account for the biggest lag in the system – chrisl Sep 9 '20 at 23:47
0

I don't know about commercial drones, however your 'protocol' seems to be quite efficient, as it uses 4 bytes to send 2 values (e.g. U3F5) for Up with speed 3 and Forward with speed 5.

Let's assume values from 0-7. Then you can send them both in 8 bits/one byte:

H H H H V V V V

Where H is the horizontal speed (from -8 (000) to +7 (111), in total 16 possible values. For the vertical speed you can do the same.

So within one byte you send both speeds (meaning also there is no lag). In case you need more accuracy, than send two bytes: one byte with horizontal and one byte with vertical speed. Depending on the sending/receiving speed I doubt there is any lag.

Even with your protocol I doubt there is a lag, but the above is more efficient.

I'm sure even more efficient algorithms can be created, probably by using the difference with the previous value (like sending delta values).

Another algorithm that can be created, assuming there is a big chance that only one of the two directions is changed (either horizontal or vertical is) and having a high accuracy

D V V V V V V V

Where D is the direction (0 = horizontal, 1 = vertical) and V is the value/speed (-64 to +63, 7 remaining bits).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.