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.
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.)
Can you post a snippet of your code?
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.
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?
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?
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.
That sounds reasonable. Are you sure that you are connected to Analog Channel 2 (the 3rd analog channel, they start at 0).
Yes the else-if is in a while loop.
Yes the PWM is in analog Channel 2.
The change in resistance is from between ground and signal. Is this right?
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?
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.
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.
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.
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.