how to creat a home button

can some on help explain how to use a potentiometer connected to turret to create a button that once press returns the turret to a set home position on and stops. or any other way that would work

Use a button on your controller to start a Routine in the Periodic Task vi. The Periodic Task routine would use a loop to check the current potentiometer value and drive the motor in the direction/speed the turret needs to move until the desired pot value is reached. This would require a PID loop, but if your turret is single-speed and you don’t care about a small offset, using the potentiometer feedback just as a directional indicator would do “good enough”.

To translate the above, let me describe how I would implement in code:

  • In Teleop VI, use a feedback register such that when the desired button is pressed, if this is greater than the register, include within a Case Structure a global variable boolean (“TurretHomeEnabled”, for example) set to True. What I described is a “WhenPressed” case.

  • In Periodic Task, include an endless loop that constantly checks for your global variable. If True, check the current pot value and drive the motor accordingly. If the pot value matches your specified “Home” value with a tolerance, stop driving the motor and then set the global boolean to False.

If what I’m describing still sounds confusing, let me know and I can probably find you some example screenshots.

Thanks I will try it tomorrow. If you could post some screen shots that would be great

I am having trouble getting the potentiometer to work. when I run the code the window motor hooked up to the turret runs continuously in on direction. can some on take a look at my code attached below?

I am looking to control the turrets turn radius and create a home button.

You may be running away from your setpoint if the motor and the pot are reversed and returning the opposite of what the code is expecting. Your max and min may be reversed.

You can use a probe running in debug to see if the actual pot value is getting further from the setpoint as you run.

A simple test is to reverse or negate (-x) the output of the PID icon for the motor set.

I’m trying to interpret exactly what are are looking to do with Button 4 and Button 5.
It appears that when nothing is pressed, the PID target is always 1.17 (pot min)
When Button 4 is pressed, the PID target becomes 3.9 (pot max)
When Button 5 is pressed, the PID target becomes -(3.9 - 1.17) + 1.17 = -1.56 (out of range)

For this “Home” button are you trying to drive to a mid-value?
If so, when a button is pressed, you should be setting the setpoint to (3.9-1.17)/2]. You can just put this into a Case structure where the selected Button determines the Case, and if True, run the PID loop. If false, use your other turret logic to specify your motor power.

If this is not what you are trying to do, please describe explicitly your desired function (what you want each button to do, etc).

What i want to do is when button 5 is pressed the turret to turn from a range 0 (0 being my home position ) to 90 degrees to the right and button 4 to do the same in the opposite direction

For the home button i want to be able to push a button and no matter were the turret is it returns to home position automatically when button is pressed.

Pickett –

See attached .vi I created which should do what you’re looking for. Note that there are a lot of different ways to perform the same task in code, and the way I wrote this is just one example (the way I would write it).

First off, I am converting the voltage from your pot to an actual angle (by scaling against the min/max values). The output is a value of 0 to your turret limit. I like working with positive numbers rather than using “0” as a home position. Instead, 0 represents one limit, and the Range represents the other limit.

Then I check to see which buttons are being held down – If button 4, set the setpoint to 0 deg. If button 5, set the setpoint to 180 deg. If button 6 (“home button”), set the setpoint to 90 deg. You would have to change these values based on your actual desired setpoints.

If no buttons are being pressed, the setpoint is your current position. That would tell the PID loop to stop moving the motor.

Remember to put all this within a loop, such as in Periodic Task (or Teleop)

Let me know if this helps… (18.5 KB) (18.5 KB)