View Full Version : Potentiometer values not changing
Herbie_3633
07-02-2015, 20:17
We are currently trying to program our potentiometer for our linear actuator. I have verified that the pot is working through tests described in this video.https://www.youtube.com/watch?v=Eh2cQCLie5A
I'm using the ->Get() function to print the values but they stay at or around 30.2711. The PWM cable is plugged in to the analog in slot 2. The pot is the brand Bourns, and the part number is 3590S-2-201L.
Thank you for the help , team 3633.
RufflesRidge
07-02-2015, 20:22
That video doesn't tell us anything about how you have wired the potentiometer or how you are using it in code. Please describe the wiring and provide more details about the code you are using (Potentiometer class or AnalogInput? If Potentiometer, what does your constructor look like? etc.)
Ty Tremblay
07-02-2015, 20:22
Can you post a snippet of your code?
Herbie_3633
07-02-2015, 20:31
Potentiometer* DartPot;
public:
Robot() {
DartPot = new AnalogPotentiometer(2,360,30);
}
double pot = DartPot->Get();
else if (stick->GetRawButton(11) == 1){
std::cout<<("Pot Value: ");
std::cout<<(pot)<<std::endl;
}
The else if is connected to an if statement in the rest of the code.
RufflesRidge
07-02-2015, 20:35
That snippet doesn't help locate these items within the rest of the code. The methods there look fine, but I can't tell if the Get() call is in a location that will actually update the value.
Assuming it is, how is the pot wired?
Ty Tremblay
07-02-2015, 20:35
What's shown here will only get your potentiometer value once. You need to get your potentiometer value in a loop. Is there a loop somewhere outside your snippet?
Herbie_3633
07-02-2015, 20:37
The pot has 3 connections labeled 1-3. Connection 1 and 3 are connected by a wavy line. Ground is going to terminal 1, red is terminal 3, and signal is terminal 2.
RufflesRidge
07-02-2015, 20:40
That sounds reasonable. Are you sure that you are connected to Analog Channel 2 (the 3rd analog channel, they start at 0).
Herbie_3633
07-02-2015, 20:41
Yes the else-if is in a while loop.
Herbie_3633
07-02-2015, 20:42
Yes the PWM is in analog Channel 2.
Herbie_3633
07-02-2015, 20:56
The change in resistance is from between ground and signal. Is this right?
Alan Anderson
07-02-2015, 22:45
Yes the else-if is in a while loop.
That part of the code prints the value of pot. Is there anything in the loop that sets the value? Specifically, do you ever do another DartPot->Get() after you define the variable?
Herbie_3633
07-02-2015, 22:56
While(IsOperatorControl()&& IsEnabled()){
double pot = DartPot->Get();
if(){
}
else if(stick->GetRawButton(1) == 1){
std::cout<<(pot)<<std::endl;
}
}
The above if statement is not relevant to the pot.
Alan Anderson
08-02-2015, 00:21
If I'm reading the C++ standard correctly, the variable pot will be initialized once when the loop begins. It doesn't get reinitialized every iteration of the loop. You can test this by disabling the robot and seeing if the value printed changes when you reenable the robot.
If that happens as I think it will, you should add a line pot = DartPot->Get(); to the loop somewhere before you use the value of pot.
Herbie_3633
08-02-2015, 16:00
I tried putting pot = DartPot->get(); in my while loop and tried using cout to print DartPot->Get() directly (not using a variable) but neither worked.
Alan Anderson
08-02-2015, 16:24
Let's step back from the code for a moment and verify that you have the wiring correct. Tell us what each pin on the pot is connected to. Be extremely specific, so there is no room for doubt about what you are telling us.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.