We have a potentiometer on the lift.
//Lift
//Variables
const int ArmBottom = 2463;
const int ArmBump = 2274;
const int ArmBar= 1687;
const int ArmStash= 960;
///////////////////////////////////////////////////////////////////////////////////
void lift(int speed)
{
motor[LL] = speed;
motor[LR] = speed;
}
//Arm PID Variables; change kp ki and kd to whatever is best for your robot.
float kp = 1;
float ki = 0;
float kd = 0;
int previousError = 0;
float errorSum = 0;
int motPower = 0;
//Actual PID
void LiftPID(int target)
{
int error = target - SensorValue[PL];
int derivative = error-previousError;
motPower = (error*kp+errorSum*ki+derivative*kd);
lift(motPower); //this is our function for just setting lift motors to this power.
previousError = error;
errorSum += error/1024.0;
}
#pragma config(UART_Usage, UART2, uartVEXLCD, baudRate250000, IOPins, None, None)
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, in1, PL, sensorPotentiometer)
#pragma config(Sensor, in2, PR, sensorPotentiometer)
#pragma config(Sensor, in3, GY, sensorGyro)
#pragma config(Sensor, dgtl1, , sensorDigitalOut)
#pragma config(Sensor, dgtl2, , sensorQuadEncoder)
#pragma config(Sensor, I2C_1, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Sensor, I2C_2, , sensorQuadEncoderOnI2CPort, , AutoAssign)
#pragma config(Motor, port1, IR, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port2, LF, tmotorVex393HighSpeed, openLoop)
#pragma config(Motor, port3, RF, tmotorVex393HighSpeed, openLoop)
#pragma config(Motor, port4, LM, tmotorVex393HighSpeed, openLoop)
#pragma config(Motora, port5, LL, tmotorVex393, openLoop, reversed)
#pragma config(Motor, port6, LR, tmotorVex393, openLoop)
#pragma config(Motor, port7, RM, tmotorVex393HighSpeed, openLoop, reversed)
#pragma config(Motor, port8, LB, tmotorVex393HighSpeed, openLoop, encoder, encoderPort, I2C_2, 1000)
#pragma config(Motor, port9, RB, tmotorVex393HighSpeed, openLoop, reversed, encoder, encoderPort, I2C_1, 1000)
#pragma config(Motor, port10, IL, tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#pragma platform(VEX)
//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)
#include "Vex_Competition_Includes.c" //Main competition background code...do not modify!
#include "Drive.c" //Drive Functions
#include "Lift.c" //Lift Functions
#include "Intake.c" //Intake Functions
/////////////////////////////////////////////////////////////////////////////////////////
//
// Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////
void pre_auton()
{
// Set bStopTasksBetweenModes to false if you want to keep user created tasks running between
// Autonomous and Tele-Op modes. You will need to manage all user created tasks if set to false.
bStopTasksBetweenModes = true;
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...
}
/////////////////////////////////////////////////////////////////////////////////////////
//
// Autonomous Task
//
// This task is used to control your robot during the autonomous phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////
task autonomous()
{
Turn(180, 64);
}
/////////////////////////////////////////////////////////////////////////////////////////
//
// User Control Task
//
// This task is used to control your robot during the user control phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//**//
/////////////////////////////////////////////////////////////////////////////////////////
task usercontrol()
{
// User control code here, inside the loop
while (true)
{
motor[LF] = vexRT[Ch3]; //Left joystick drives left side
motor[LM] = vexRT[Ch3]; //Left joystick drives left side
motor[LB] = vexRT[Ch3];
motor[RF] = vexRT[Ch2]; //Left joystick drives left side
motor[RM] = vexRT[Ch2]; //Left joystick drives left side
motor[RB] = vexRT[Ch2];
motor[port5] = vexRT[Ch3Xmtr2];
motor[port6] = vexRT[Ch3Xmtr2];
motor[IL] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
motor[IR] = (vexRT[Btn8DXmtr2] - vexRT[Btn8UXmtr2])*127;
//motor[LL] = (vexRT[Btn5U] - vexRT[Btn5D])*127;
//motor[LR] = (vexRT[Btn5U] - vexRT[Btn5D])*127;
//motor[IL] = (vexRT[Btn6U] - vexRT[Btn6D])*127;
//motor[IR] = (vexRT[Btn6U] - vexRT[Btn6D])*127;
}
}
There is our lowly code
Let me know if you see any problems.
@Tabor.
So you can still say āGo to position Nā and it will go there. You have a little power going to it all the time right?