How to limit power

I’m trying to make a PID controller for a robot arm. I want to know if there is a way to limit the maximum and minimum speed or power for the motor.

#pragma config(Sensor, dgtl11, ArmEncoder, sensorQuadEncoder)
#pragma config(Motor, port5, arm1, tmotorVex393_MC29, PIDControl, encoderPort, dgtl11)
#pragma config(Motor, port7, arm2, tmotorVex393_MC29)
#pragma config(MotorPidSetting, port5, 50, 25, 640, 10, 0, 80, 5, 0)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//

#pragma platform(VEX2) //This is to tell the compiler that you are using the cortex
#pragma competitionControl(Competition) //This tells the compiler that your robot will have to listen to the field for when it can go
#include “Vex_Competition_Includes.c” //This is telling it how the field will talk to it

//This is a function used to set up tasks before the match
void pre_auton(){}

//This is a function used for an autonomous mode, OCCRA does not have autonomous modes so ignore this function
task autonomous(){}

task usercontrol(){
slaveMotor(arm2, arm1);
setMotorTarget(arm1, 40, 127, true);



This text will be hidden

Just add another statement to check if your loop is about to set your motor to a power you don’t want it to like I did below

If (new motor power < minimum){
Set new motor power to the minimum.

Create “if” statements to check and reset motor output. If it’s lower than the min value, set it to the min value. If its greater than the max value, set it to the max value.

how do you get the motor power?

You mentioned you are trying to set boundaries on your PID, all you are doing is checking if the value your PID outputs is within the range you want before you set it to the motor. I didn’t mean the literal power of the motor.