So I have been working on a P-loop recently and I run into a bug. I can’t seem to figure out why the rotation is an error.
I want the motor to slow down over time as I hold the L1 button.
'''// ----------------------------------------------------------------------------
//
// Project:
// Author:
// Created:
// Configuration:
//
// ----------------------------------------------------------------------------
// Include the V5 Library
#include "vex.h"
// Allows for easier use of the VEX Library
using namespace vex;
//Drivetrain Group
motor_group driveL(LeftFMotor, LeftBMotor);
motor_group driveR(RightFMotor, RightBMotor);
// Begin project code
void preAutonomous(void) {
// actions to do when the program starts
Brain.Screen.clearScreen();
Brain.Screen.print("pre auton code");
wait(1, seconds);
}
void autonomous(void) {
Brain.Screen.clearScreen();
Brain.Screen.print("autonomous code");
// place automonous code here
}
void userControl(void) {
Brain.Screen.clearScreen();
// place driver control in this while loop
while (true) {
double kP = 0.014;
int error = 0;
int targetValue = 900;
while(1==1){
error = Tilter.rotation(degrees) - targetValue;
if(Controller1.ButtonL1.pressing()) {
Tilter.spin( directionType::fwd, error * kP, voltageUnits::volt );
}
else{
Tilter.stop(vex::brakeType::hold);
}
}
wait(20, msec);
}
}
int main() {
// create competition instance
competition Competition;
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(userControl);
// Run the pre-autonomous function.
preAutonomous();
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}
edit: code tags added by mods, please remember to use them.