Tetrix Gamepads. Controlling the motors with two separate GamePad Sticks Pro Preview

In this tutorial, we are controlling the FTC Tetrix robot with the two sticks of the same GamePad. The left stick is for forward and backwards, while the right stick is for left and right.

  • #517
  • 21 Apr 2017
  • 6:33

Different power for the left and right motor

The calculation should be done based on the position of the stick. We take the account for the "x" and "y" position of both sticks. 50% of the power should come from the left and 50% from the right stick.

leftPower = - gamepad1.left_stick_y/2 + gamepad1.right_stick_x/2

leftPower = - gamepad1.left_stick_y/2 - gamepad1.right_stick_x/2

Part of the power comes from the Y axis of the first stick and part of the X axis from the second stick. You can modify the formula, but the principle for controlling with both sticks is the same.



We are moving into a little more advanced task where we'll control with the same gamepad but with the two sticks we'll control the robot and the way we're going to do this is with the left stick we control the robot forward and backward while with the right stick we control the turns. And if I now just move the right stick slowly, you can see the robot turning. If I move forward and then backward and we can even group these two actions. So, forward and left

and backward and right.

This is the program that we want to develop in this video.

In the Android studio what I'll do is to change the way we calculate the power for the left and for the right motor. For this, in our function I'll declare a new variable called leftPower and initially it is equal to 0. Another variable that's called rightPower and again it is equal to 0. So, these are the two variables that will control the power that we set to the motors. And right here we want to set rightPower and then is leftPower.

What we need to do is to find a formula, a calculation that would give us the correct left power taking into account both gamepad1 and its left stick and gamepad1 again its right stick. You can develop different formulas and you can modify them based on your preferences for controlling the robot with the gamepad. But the simple formula would be just taking gamepad1 and its left stick

so we take the 'y' access of the gamepad with minus sign. We divide this by 2 and we sum with gamepad1 the right stick and its 'x' access. The idea is the following: When you move forward you can move forward to up to 50% with this motor but then when you press with the right stick you press left, you set the power to the other 50% that the whole robot could take - the whole motor. The same is for the right power - we have -gamepad1.left_stick but here it is with -gamepad1.right_stick_x/2. So, with the left stick we take about 50% of the whole value that we set to the motors because we divide the value that we get from the left_stick/2. So, we can get to up to 50% and the other 50% come from the right stick. If we've moved to the left or to the right and we get our correct value. So, this is the formula that we used for controlling the robot with both sticks. And here you can come up with more advanced formulas. So, you should take into account the 'y' access of 1 the 'x' access of the other stick and you can combine them in different ways. For example, you can combine them here. It might not be 2, it might be another value that gives you a better control of your robot so all the robots are different. So, this formula is something that you should develop specifically for your robot and for the way you want to control this robot. But the basic principle is the same. You get part of the result from the 'y' access of one of the sticks and part of the result from the 'x' access from the other stick. Download and run. I'll use just the right stick and I push to the left.

And now to the right. And you can see that the robot is rotating around an axle that's somewhere here between the two wheels. So, we have the axle on which the wheels are and it is rotating around the center of this axle.

And we also can move it forward and backward. What will happen if we set a maximum power forward and left?

What's happening is that we are giving a maximum power to the right motor and the left wheel stays on place. Now I'll just set it right and backward

and you see that because we are not rotating this wheel it stays on place and we can do the same for the other wheel - for our right wheel. So, move forward and right.

And this is at least a very interesting way in which you can control your robot. Again, the program will probably be different for your specific robot but the principle is the same and you can control the motors with both sticks.