[C++] Programming Catapult w/ Potentiometer

  1. last week

    5SRobotics

    Dec 6 Nebraska 5S

    We are using C++ programming on V5 and we want to use a potentiometer to have the catapult shoot and return the original degree. We have the potentiometer on the same axle as the actual catapult gear itself. We aren’t sure how to program the potentiometer to allow the motors to return to the original position. We have two motors on our catapult and currently don’t have an automatic reload. We would like to do this by clicking on button on the controller which lets it shoot and reload all in one motion because it is a slip gear with a ratchet. Some programming help would be greatly appreciated as for we are very confused.

    Chiming in, one of the problems with trying to use an encoder on a slip-gear catapult is that the encoder will not be aware of the slip. The potentiometer sounds like the right way to go.

    As for how to use a potentiometer in RMS to control this, it will be similar in form to how every other language accomplishes it: spin the motor when it is not at its target, or when you want to fire. Something like this:

    ...
    if ((cataPot.value(pct) < TARGET_POT_VALUE || con.ButtonR2.pressing() ) {
        cataMotor.spin(fwd, CATAMOTOR_SPEED, pct);
    } else {
        cataMotor.stop(coast);
    }
    ...

    Fill in values for TARGET_POT_VALUE, change the firing button if you like, and you might have to change the < for a > depending on which way your pot reads. This may require some additional embellishment to get it to work well and reliably, but this should accomplish basic operation. Embellishments you might look to add would be a physical catch for the catapult so the motor doesn't have to work to hold it back and motor logic to support it, or having it only draw back when you press some other button that's not the firing button.

  2. mattjiang

    Dec 6 Irvine, CA 2496Y

    I would create a PID control loop with set positions for the catapult and use a task/thread to perform the automatic functions. There's plenty of guides for PID on Google. You can start with this guide

    This post can probably help you with multitasking in vex c++.

  3. Joey The Great

    Dec 6 Suspended Maryland 24k

    PID is not necessary, just say if arm is not far enough, go dawn, else, go up, and then fine-tune it to stay in the right position

  4. Riptide

    Dec 6 Canton, Michigan 21636A

    I just use the internal motor encoder and it works fine.

  5. 5SRobotics

    Dec 6 Nebraska 5S

    How did you Program the internal Motor encoder. We tried but couldn’t get it to work on Robot Mesh Studio.

  6. Joey The Great

    Dec 6 Suspended Maryland 24k

    that might not be as accurate

  7. Riptide

    Dec 6 Canton, Michigan 21636A

    @5SRobotics How did you Program the internal Motor encoder. We tried but couldn’t get it to work on Robot Mesh Studio.

    I don't know because I use vcs.

  8. Riptide

    Dec 6 Canton, Michigan 21636A
    Edited last week by Riptide

    @Joey The Great that might not be as accurate

    it's not nearly as accurate, I just did it that way because i don't know how to use a pot with vcs and i was in a rush when i was programming.

  9. 5SRobotics

    Dec 6 Nebraska 5S

    Do you happen to have an example of programming for a potentiometer? And do you necessarily need to us a PID?

  10. Joey The Great

    Dec 6 Suspended Maryland 24k

    what if the slip gear turns too much and catches again b4 the arm soots?

  11. 5SRobotics

    Dec 6 Nebraska 5S

    I guess that makes sense to use a potentiometer instead because it’s more accurate. How would I program it without a PID?

  12. Joey The Great

    Dec 6 Suspended Maryland 24k

    i'll try to send a snapshot of my code soon

  13. 5SRobotics

    Dec 6 Nebraska 5S
    Edited last week by 5SRobotics

    Do you use robot mesh studio? If so, a snapshot would be really helpful.

  14. Joey The Great

    Dec 6 Suspended Maryland 24k

    no, robotc for cortex

  15. 5SRobotics

    Dec 6 Nebraska 5S

    How different is RobotC to C++ for Robot Mesh Studio?

  16. mattjiang

    Dec 6 Irvine, CA 2496Y

    @5SRobotics Do you happen to have an example of programming for a potentiometer? And do you necessarily need to us a PID?

    "PotentiometerName".value(rotationUnits::raw); will give you the raw value of the pot from 0-4095 ticks. You can also use rotationUnits::deg or rotationUnits::rev to get the degrees or revolutions output.

    I would definitely recommend using PID for your actions due to its accuracy, but if you would like to not use PID, you can set your motor to stop when the potentiometer hits its desired value and tell the motor to hold.

  17. Joey The Great

    Dec 6 Suspended Maryland 24k

    i wouldn't know, i've only ever used robotc, but im saying the basic code structure should be the same despite syntax

  18. meepmeepme

    Dec 6 Honolulu, Hawaii (Saint Louis ... 42700B/C
    Edited last week by meepmeepme

    @5SRobotics How different is RobotC to C++ for Robot Mesh Studio?

    almost the same. You'll be having to learn new api's and stuff, but they're very similar in the way that you construct them.

    E: api like the commands to spin motors.

    MOTOR.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct); for C++ vs
    motor[MOTOR] = 100;

  19. Joey The Great

    Dec 6 Suspended Maryland 24k

    what's api?

  20. Deleted last week by mattjiang
  21. Newer ›
 

or Sign Up to reply!