Servo on joystick

Hey Guys hope every one had a blast at competition, but now that is over is time to start thinking on next years possibilities. So my team is starting to develop a swerve drive, but they want to activate something (secret sorry) using a servo, so I was wondering how can you program a servo to work on a button for a joystick, I know it was posted some were but i cant find it, can some one help me.

Thanks :smiley:

We’ve had success using the “One-shot Rising” VI in Labview for rotating a servo at the press of a button. There are most definitely much better ways to do this.

If you are using Labview, or any environment for that matter, it is quite simple. Check the state of a given input, in this case a button on the joystick. When the input is false, give one value to the servo. When that input is true, give a different value to the servo.

See the pictures below for an example.

In c it might be something like:

if digin1 == 1
{
  servo1 = 118;
}
else
{
  servo1 = 75;
} 
```<br><br>![False servo.JPG|690x176](upload://rFRMUm51BBOiNYU5DslgLOr9mTM.jpeg.jpeg)<br>![True Servo.JPG|690x191](upload://mWJaHXNAmoylJ67X7ee5DD0SjKg.jpeg.jpeg)<br><br><br>![False servo.JPG|690x176](upload://rFRMUm51BBOiNYU5DslgLOr9mTM.jpeg.jpeg)<br>![True Servo.JPG|690x191](upload://mWJaHXNAmoylJ67X7ee5DD0SjKg.jpeg.jpeg)<br>

There’s actually an easier way then that. Go into (I think it’s Comparison) palette and look for a Switch. I forgot it’s exact name, but basically it looks like a triangle with a T and F inputs on the top and bottom and a case on the middle. It just passes the data through depending on the value of the input.

I don’t really use lab view, but that sounds like a logic gate

in c++ you could do some thing similar with a boolean variable:

int main()
{
   bool virtualdigin1;
   if digin1==1
     {
        virtualdigin1=0;
      }
   else
     {
        virtualdigin1=1;
      }
}

It is. The solution proposed by Bill is a case structure, I proposed a switch.

Here is a picture of what Apalrd suggested. He is right, it is even easier than what I suggested.





Not that it won’t work, but controlling a button with a servo seems like it’s adding additional potential points of failure unnecessarily.Servo controlled features do have their place, but i’m not sure this is it.

If the servo and button are on 2 separate systems, then I suggest a relay instead of a button that must be physically connected with the servo and then made to work together.

on the other hand, if the system controlling the servo also receives the input from the button, the issue could probably be fixed in programming.

However, if you still feel these solutions won’t work and you need some sort of electromechanical actuator, a solenoid might be better (assuming this isn’t ON the robot, if it is, the input from the button and servo output are both handled by one system so you should fix it in the code)

of course, since this is a black project there could be some major detail I don’t know about that makes this your only option, in which case, disregard this.

Controlling a button with a servo? I think you have it backwards. I hope you have it backwards. I’m pretty sure the question was how to control a servo with a joystick button.

I hope you are right Alan, I was going an the same assumption.

Although, when you read the OP’s original question, you can see why there is room for confusion.
It’s amazing how our language can open to so many different interpretations.

…

http://www.chiefdelphi.com/media/photos/27192

Sorry guys that’s what I ment, the button on the joystick to move the servo in different positions and come back to those positions. What we are trying is use a dewalt motor and we need to change gears and for that we need the servo to move the shifter on the dewalt. :confused:

ooooohhh… you’re using a 3-speed DeWalt transmission… we’ve used those before.

This year we had two robots and only used gears 1 and 2 (only one shifter, it was for our arm).

In LabVIEW I created a 2x2 matrix for the shift states. The column was the numeric equivalent to the boolean robot variable (false for competition, true for practice). The row was the numeric equivalent to the boolean shift state variable. This worked just fine for only going from 1 to 2. I set the shift point when deploying so there was not much load on the arm at the time it shifted and it never missed a shift.

In the past, we have used all three gears (for drivetrains), and had the servo overshoot and come back when shifting into second, to make more certain the shift was successful (the shift from 2 to 3 at speed is kinda hard anyway).

The simple way to do this would be to use a state-machine and have a value for “Low”, “Mid”, and “High”. This will make the robot stay in gear when you remove your hands from the buttons. To do this, create an Enum control, right-click, and hit “Edit Items”. Then, type in your three states, preferably with Low as 0 and High as 2. Then, create an array and place a Numeric type inside, making a numeric array. This will store your shift points. There are three rows in the numeric array that we care about: the first three. The first one corresponds to Low (assuming Low is the 0 in the list), and so on. Servo values are between 0 and 170 in degrees. When you have set them (you can do this while the code is running), stop the code, right-click on the array, and go to Data Operations -> Make Current Value Default. Then, go to the place where you set the servo, get the array and enum, and Index the array (using Arrau->Index Array) where the index is the enum. This will give you the correct angle for the state that the Enum is set to, which you can set to your servo. Then, to set the enum, you can have a button for Low, Mid, and High. Just have a Switch for each button, and feed the current state of the enum into the False of the first one (then string the output of the first to the False of the second and so on). Then, set the True to the value of the button, either Low Mid or High. The output of the last one gets set to the enum. You could save buttons by having a Shiftup and Shiftdn button, but that would require an indicator of the current gear (Dashboard or LED) and a rising-edge trigger, both of which are more complex then you probably want. I would make pictures to go along with this but my LabVIEW laptop is broken.

Also, don’t forget to remove the detent from the shifter (a little black tab that holds it in gear, it makes it harder for the servo to shift)