How do I get a motor to hold the weight in autonomous?

Our robot can’t hold the weight of stars with no power to the motors. So, in driver control we have the else run the motors at 15. I need this in autonomous, but I don’t know how to keep the motors running at 15 value through our the whole autonmous, while running other functions?

I think I might be able to run a global function that runs throughout the whole competition template.

I don’t know if this will work, but did you try and make a while true loop and set the motors to 15?

Once you set motors to a power, they will continue running at that power until you set the power again. For example, if you were to have this at the beginning of your autonomous:

motor[lift1] = 15;
motor[lift2] = 15;

Both motors would be set to a power of 15, and stay running at a power of 15 for the entire autonomous period, unless you set them to a different power before autonomous ends.

In my autonmous I make the motors run at different amounts but after the function ends I need the motors to hold

I need something to constantly keep the motors at 15.

So you want a way for your motors to run after autonomous ends? Unless you have some sweet bands then you’re out of luck. Everything cuts off at the end of auton and driver. The only thing that could possibly move is a ratcheted gear.

No the motors will turn off at the end. On my robot I scoop up stars and lift over the fence. The motors that are used on the hinge must be run at 15 when nothing else is being touched. This isn’t happening after stars are scooped or after we lift up or drive

Just set a constant variable and say when the buttons that control the “scoop” aren’t being pressed, then the motors should equal 15.

Just in your autonomous code whenever you stop moving your lift just set the motor value to 15 instead of 0. That way they will stay like that until the program reaches a point where you request a different speed

I tried just telling the motors to run at 15, but it doesn’t hold the motors when I do this. It runs them for a sec then they power off. Anushka post a screenshot of the code you are talking about.

Anushka is completely wrong
Placing that at the start of the autonomous code will not make it run for the whole time

Also the autonomous task is the only task that can control motors during the autonomous period

If you wanted to do what you are wanting to achieve you must do something like this

task autonomous(){

		// Initially set hold power
		motor[liftMotor] = 15;
		// Drive to star
		motor[driveMotors] = 127;
		wait1Msec(2000);
		// Stop drive motors
		motor[driveMotors] = 0;
		// Raise lift
		motor[liftMotor] = 127;
		wait1Msec(700);

		// Stop arm moving but keep holding power again after changing power before
		motor[liftMotor] = 15;

	// Continue using this format after.	
		
}

Basically what is happening is you are telling a motor to be set to a power of 15, then changing that power later on. If you never tell it to go back to 15 it will stay at what was set later on (127).
Motor powers will stay where they are set until changed in the program flow.

That’s why you must reset the power to 15 every time you want to stop, because then it will hold again. Because you are changing the power later on.

To get more advanced, a PID with an increased integral (I) contribution (say up to 30% of motor power) helps in the hold factor.

The integral, when dialed in will hold your arm in place and as it tries to fall down, the I compensates and holds you up. Sometimes you get a droop and the motor finally kicks in to raise your arm back up. That means the I contribution is a wee bit too low.

This can be a bit tricky as different hold points have different effects from gravity, weight of objects, and different contributions from the rubber bands based upon stretch distance. Try and calibrate it to the most popular hold point you might have - like the spot where you would drive around getting ready to dump/catapult the objects.

Maybe you have to have different functions based upon the weight being held this year. Mode A and B for cubes and stars.