Last active
January 11, 2018 20:56
-
-
Save ItsHarper/7ec07c19f3d4ac3572545a9b0c1642d3 to your computer and use it in GitHub Desktop.
How to set PID parameters on an MR motor controller (untested)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.firstinspires.ftc.teamcode; | |
import com.qualcomm.hardware.modernrobotics.ModernRoboticsUsbDcMotorController; | |
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; | |
import com.qualcomm.robotcore.hardware.DcMotor; | |
import com.qualcomm.robotcore.util.DifferentialControlLoopCoefficients; | |
@Autonomous(name = "MR PID Test") | |
public class MrPIDTest extends LinearOpMode { | |
@Override | |
public void runOpMode() throws InterruptedException { | |
// This code has not been tested, you'll need to experiment with it yourself. | |
// I believe this will only set the PID values temporarily. They will probably reset when | |
// you restart the hardware. | |
// Valid values for the PID parameters are 0-255. | |
// Here are the default PID values (assuming they aren't overwritten by a particular motor type) | |
// P = 128.0, I = 64.0, D = 184.0 | |
// You can find the default PID values for the different motors by looking at their | |
// interface definitions in the Hardware module, inside package com.qualcomm.hardware.motors. | |
// Link: https://github.com/OpenFTC/OpenFTC-app/tree/master/Hardware/src/main/java/com/qualcomm/hardware/motors | |
// For example, the default PID values for a NeveRest 40 motor are P = 160, I = 32, D = 112 | |
//Defining our variables | |
ModernRoboticsUsbDcMotorController mrMotorController; | |
DcMotor motor1; | |
DifferentialControlLoopCoefficients newPIDValues; | |
// Giving them values from the hardwareMap | |
mrMotorController = (ModernRoboticsUsbDcMotorController) hardwareMap.dcMotorController.get("controllerName"); | |
motor1 = hardwareMap.dcMotor.get("motor1"); | |
// The default PID values, this is what you tweak | |
newPIDValues = new DifferentialControlLoopCoefficients(0.0, 64.0, 184.0); | |
//Assigning our new PID values to the motor | |
mrMotorController.setDifferentialControlLoopCoefficients(motor1.getPortNumber(), newPIDValues); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment