Is it possible to have certain motors not go past a certain degree

i was wondering if it is possible to write a program that tells a motor to not go past a certain degree i have a code that idk will work but i want it to allow us to use the other functions of the robot

LeftMotor.rotateTo(-90,rotationUnits::deg);
RightMotor.rotateTo(-90,rotationUnits::deg);
vex::task::yield();

Is this for your tray angle

no its for a dr4b lift but the bottom of it hits the wheels and messes up the driving

I think the easiest and most effective way to solve this would be to make a hard stop for the lift so it never hits the wheels. We have a standoff mounted above each wheel on pillow bearings that blocks it.

5 Likes

like a physical stopping mech. no programming

Exactly. With programming the lift might brush up against them by accident. If it can’t physically touch it won’t

Add something over the wheels like alphagoats said.

You could set it to brakeType::hold after it goes to the specific degree you want, or you could use a potentiometer and use PID to hold it in place.

4 Likes

i dont have any room for the potentiometer on the robot and idk what a PID is

PID - Proportional Integral Derivative control
Think of it like a thermostat - yours may be at say 80 degrees, and you want it a little colder. You select the option 75 degrees. Your home’s heating system will now attempt to change the temperature to that, but in a way that won’t destroy itself. Then, if someone say opened a window and let in a lot of hot air, the system will try to re-adjust the internal temperature back to 75 degrees.
There’s plenty of threads on this forum that explain how it works/how to do it.
Mechanical stops are still easier, but if you insist on solving it with code I’m sure there’s a way to keep track of encoder counts on motors that will allow you to stop the motor from turning after it reaches a certain amount of counts, but this would require you to start your code with a robot fully reset every time

5 Likes

If you scroll slightly down from the vexforum website, you can find a tutorial I have built explaining pid, how to code it, and how to tune it.

1 Like

thank you for the explanation i figured there was something like that but didnt know what it was called