I have just learned how to do a simple code for a V5 robot (press button, do thing) but I want to go a bit more advanced. My team is using a traybot and I was thinking about using a P loop for the tray so 1 button press will make the tray go into the right position. However, I have no idea how to implement this into the code, so I was wondering if anyone here could help me out. Thanks!
1 Like
I like to use a library (well, more of a couple files, really) called MiniPID. It does the calculations of proportion, integral, and derivative for you. You still have to tune it though.
3 Likes
this is just pseudocode
int tray_deploy()
{
movetray((target-encoder)*kp);
}
Are you sure writing your own P loop is necessary in this case? The built-in motor commands should work fine. Assuming that the tray has a one motor lift, then the C++ code would look something like this:
if(con.ButtonDown.pressing())
trayMotor.startRotateTo(0,deg,40,vex::velocityUnits::pct); // 0 is down position
if(con.ButtonUp.pressing())
trayMotor.startRotateTo(100,deg,40,vex::velocityUnits::pct); // 100 is up
you need to slow it down as it goes or it will push the cubes over