How would I make a motor to go to a spot and stay there?

Hi, I have a part on my robot where it folds up and around my robot and would rotate down to the ground to pick up a mobile goal to score rings on. One thing I have been struggling with is getting it to go to one spot and actively trying to stay there. Some things I’ve tried to do is just have it rotate a select number of degrees, but that didn’t work as if it got stuck it would lock it all up. Next I tried a function that would rotate to the value every time I press a button but that didn’t do anything either. At this point I’m running out of ideas as I’m not that into coding. Right now I need a push into the right direction because I’m not even sure what to look up or begin to type.


I have tried that with some success problem is I have trouble eye balling it to the point where I need to go.

use break type hold along with spinning to a location like a set number of degrees.


You can ignore the top one saying setposition, but would the second one work if I just had that because I tested it this morning and it locked up the GoalGrabber and I had to quit the program to resume control. I’m pretty sure it wasn’t caught up on anything.

First if you want to copy and past code you can use ``` around you code.

code in here

What I am guessing this means is that when you press the button it doesn’t move any more.

What you are doing here is spinning the motor to degrees then stoping the motor the next loop(maybe? I hope this is the the while loop). Now this dose make sense because pushing the button will simply move the motor to the location of degrees but you are already at degrees so it would just not move.

to fix this you could create another if statement when you press another button it would spin to a new pos that is different from degs

1 Like

Thanks, I’ll try it first thing tomorrow morning.

It worked for a second but then it would start rolling down slowly even though I have the motor brake type set to hold, it doesn’t do this on other code so I’m not sure what’s going wrong. I think it’s very close though.

GoalGrabber.setVelocity(100, percent);
GoalGrabber.spinToPosition(900, degrees); //put the right angle number here //THIS MIGHT NOT BE IT (SOUNDS LIKE A PART OF A WHOLE)

     else if(Controller1.ButtonLeft.pressing()){
    GoalGrabber.setVelocity(100, percent);
		  GoalGrabber.spinToPosition(20, degrees); //Put the right angle number here