meow
parent
5c7ed130b3
commit
002118e969
|
@ -1,5 +1,6 @@
|
|||
#include "Adafruit_VL53L0X.h"
|
||||
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
|
||||
float distanceReading = 0;
|
||||
|
||||
void initDistance(){
|
||||
|
||||
|
@ -13,7 +14,9 @@ void initDistance(){
|
|||
|
||||
void updateDistance(){
|
||||
if (lox.isRangeComplete()) {
|
||||
Serial.print("Distance in mm: ");
|
||||
Serial.println(lox.readRange());
|
||||
distanceReading = (float)lox.readRange();
|
||||
// if(distanceReading>2000){
|
||||
// distanceReading = (float)NAN;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,13 +11,13 @@ double turnKp=1, turnKi=5.0, turnKd=0.17;
|
|||
|
||||
|
||||
double angleInput, angleOutput, angleSetpoint;
|
||||
PID anglePID(&angleInput, &angleOutput, &angleSetpoint, angKp, angKi, angKd, AUTOMATIC);
|
||||
PID anglePID(&angleInput, &angleOutput, &angleSetpoint, angKp, angKi, angKd, P_ON_M, REVERSE);
|
||||
|
||||
double posInput, posOutput, posSetpoint;
|
||||
PID posPID(&posInput, &posOutput, &posSetpoint, posKp, posKi, posKd, AUTOMATIC);
|
||||
PID posPID(&posInput, &posOutput, &posSetpoint, posKp, posKi, posKd, P_ON_E, DIRECT);
|
||||
|
||||
double turnInput, turnOutput, turnSetpoint;
|
||||
PID turnPID(&turnInput, &turnOutput, &turnSetpoint, turnKp, turnKi, turnKd, AUTOMATIC);
|
||||
PID turnPID(&turnInput, &turnOutput, &turnSetpoint, turnKp, turnKi, turnKd, P_ON_E, REVERSE);
|
||||
|
||||
PID* pids[] = {&anglePID, &posPID, &turnPID};
|
||||
|
||||
|
|
|
@ -78,7 +78,8 @@ void initServer(){
|
|||
char buff[1024];
|
||||
int ret = snprintf(buff, sizeof(buff),
|
||||
R"({
|
||||
"motorTargetAngle": %d,
|
||||
"motorTargetAngle": %f,
|
||||
"distanceReading": %f,
|
||||
"position": %f,
|
||||
"anglePID": {"setpoint": %lf, "input": %lf, "output": %lf},
|
||||
"posPID": {"setpoint": %lf, "input": %lf, "output": %lf},
|
||||
|
@ -92,7 +93,8 @@ void initServer(){
|
|||
"aaReal": {"x": %hd, "y": %hd, "z": %hd},
|
||||
"aaWorld": {"x": %hd, "y": %hd, "z": %hd}
|
||||
})",
|
||||
dbgState.motorTargetAngle,
|
||||
(float)dbgState.motorTargetAngle,
|
||||
(float)distanceReading,
|
||||
encoder.position(),
|
||||
angleSetpoint, angleInput, angleOutput,
|
||||
posSetpoint, posInput, posOutput,
|
||||
|
|
Loading…
Reference in New Issue