So I have seen many teams that have a tray that goes forward slowly to place the cubes and returns to its original position much faster. I am confused as to how these teams are achieving two different speeds when moving the tray. Help will be much appreciated!!
I think itâs some squared function or something, dont quote me.
So squared function forward, no squared function backward
Here,
if(Controller1.ButtonR1.pressing())
{
Tray.setVelocity(100,percent);
Tray.spin(foward);
}
Then just change the percent
ok I will try that
(20 char)
Like @RNA said, set the velocity of the motor to your desired slow speed for when you move it up, and then when you go down change it back so its fast.
I would also advise using some type of setpoints to make your placement more consistent. I believe to use the built in function is motor.rotateTo()
in VexCode. That will make it so instead of your driver needing to let go every time, they can just hold the button down. It also can be used to compress two buttons down to one (on button press the tray goes to its placement position, else the tray goes back to its starting position).
How would the code look like for that?
I would write a code so that if the motor reaches a certain degree then it changes the velocity
It might just go down faster because of gravity. Though you could code it to go one speed up and another speed down, thatâs what my team does.
I donât use VexCode very often so this example might be off, but I think its mostly correct. For reference I am using this VCS documentation site. I think VCS and VC-Text have the same functions, but I could be wrong.
This example assumes your tray motor needs to turn 45 degrees to reach its tray up position, that you want it to go up at 50 percent speed, your tray motor is called tray_m, and you want A to be the tray tilt button.
//If A is pressed, move the tray to its upright position. If A is not pressed, put the tray back down.
if(Controller1.ButtonA.pressing())
tray_m.rotateTo(45, rotationUnits::deg, 50, velocityUnits::pct, false);
}
else{
tray_m.rotateTo(0, rotationUnits::deg, 100, velocityUnits::pct, false);
}
Also try not to confuse rotateTo with rotateFor. While similar, they do slightly different things (rotateFor is relative whereas rotateTo is absolute).
For extra fun, you could have the button check to see if the tray is in position. And if the tray is up, it will call a function so the robot automatically reverses the rollers and backs up.
That helps a lot!! Thank you! I will be able to implement this tomorrow.
So I was working on my aton, and I was wondering how to achieve my tray moving at two different speeds when I wanted it to in autonomous.
Instead of defining the speed at the beginning of autonomous just use this in the brackets to control its speed for that command
100, velocityUnits::pct
So I would put that code before my tray line to set the percentage to 100?
(Iâm totally ripping this off from the post above butâŚ)
Use it like how itâs used here for it to work
tray_m.rotateTo(0, rotationUnits::deg, 100, velocityUnits::pct, false);
Oh, ok I get it now! Thank you!
If you know what a p loop is, thatâs what I use for my traytilt function.
What is a âP loopâ? How do I use it?
A proportional loop is a control method that uses the idea of âerrorâ. You take your setpoint (your target position), and subtract it by the motorâs current position. As you move away from your target, your error will grow larger. And as you get closer, your error gets smaller. If you set the motorâs speed to the value of your error, you would see your motor speed up and slow down depending on its positon.
The problem is that this error doesnât work very well with the voltages/speeds the motor takes. So we multiply the error by a constant called kP (proportional). The value kP contains depends on how you want the motor to behave. If kP is too large, your motor will overshoot its target. When correcting for the overshoot, it will overshoot again. This repeated overshooting creates an oscillating pattern. If kP is too small, the motor might move slowly or it might not ever reach its target (as it wonât have enough power to push the motor). So we want kP to be tuned to a nice goldilox zone.
An easy way to tune kP is to set kP to 1. If it doesnt overshoot, increase kP. If it overshoots, you lower the value of kP. Rinse and repeat till you find a good value.
Better than just a P loop is a PID loop. It is a proportional loop, but it also has integral and derivative values. The integral helps move the motor to its position as it gets closer to the target. And the derivative helps lower the effects when you change the target. PID is what the motor.rotateTo() function uses to reach its target. The hold brake mode also uses PID to keep its position.