绘图。
This commit is contained in:
@@ -114,18 +114,30 @@ public:
|
||||
}
|
||||
else {
|
||||
Serial1.begin(SensorReader::c_uiBaud[WIT_BAUD_9600]);
|
||||
// Serial.println("9600 Baud rate modified successfully");
|
||||
if (DEBUG) {
|
||||
Serial.println("9600 Baud rate modified successfully");
|
||||
}
|
||||
}
|
||||
|
||||
if (WitSetContent(RSW_ANGLE | RSW_ACC || RSW_GYRO) != WIT_HAL_OK) {
|
||||
if (WitSetContent(RSW_ANGLE | RSW_ACC | RSW_GYRO) != WIT_HAL_OK) {
|
||||
Serial.println("Set send content: angle, acc, and GYRO Error");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if (DEBUG) {
|
||||
Serial.println("Set send content: angle, acc, and GYRO");
|
||||
}
|
||||
}
|
||||
|
||||
if (WitSetOutputRate(RRATE_5HZ) != WIT_HAL_OK) {
|
||||
Serial.print("Set report rate failed");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if (DEBUG) {
|
||||
Serial.println("Set report rate success");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -749,13 +761,13 @@ void setup() {
|
||||
TIMSK5 |= (1 << OCIE5A);
|
||||
sei();
|
||||
|
||||
attachInterrupt(digitalPinToInterrupt(JOYSTICK_SWITCH),
|
||||
on_joystick_button, FALLING);
|
||||
attachInterrupt(digitalPinToInterrupt(JOYSTICK_SWITCH), on_joystick_button,
|
||||
FALLING);
|
||||
|
||||
// Wait for z_ref to have value;
|
||||
while (SensorReader::angle.z == 0.0 && SensorReader::angle.y == 0.0 &&
|
||||
while (SensorReader::angle.z == 0.0 || SensorReader::angle.y == 0.0 ||
|
||||
SensorReader::angle.x == 0.0) {
|
||||
Serial.print("");
|
||||
Serial.println("Wait");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -975,6 +987,9 @@ void calculate_and_draw() {
|
||||
abs(SensorReader::acceleration.y) +
|
||||
abs(SensorReader::acceleration.z) >
|
||||
120.0) {
|
||||
if (DEBUG) {
|
||||
Serial.print("g");
|
||||
}
|
||||
x_offset = 0;
|
||||
y_offset = 0;
|
||||
z_offset = 0;
|
||||
@@ -987,6 +1002,14 @@ void calculate_and_draw() {
|
||||
if (abs(SensorReader::gyro.x) + abs(SensorReader::gyro.y) +
|
||||
abs(SensorReader::gyro.z) >
|
||||
240) {
|
||||
if (DEBUG) {
|
||||
Serial.println("h");
|
||||
Serial.print(SensorReader::gyro.x);
|
||||
Serial.print(" ");
|
||||
Serial.print(SensorReader::gyro.y);
|
||||
Serial.print(" ");
|
||||
Serial.println(SensorReader::gyro.z);
|
||||
}
|
||||
x_offset = 0;
|
||||
y_offset = 0;
|
||||
z_offset = 0;
|
||||
@@ -998,11 +1021,14 @@ void calculate_and_draw() {
|
||||
}
|
||||
else {
|
||||
if (DEBUG) {
|
||||
Serial.print(abs(SensorReader::angle.x - x_ref) < 20.0 ? "true" : "false");
|
||||
Serial.print(abs(SensorReader::angle.x - x_ref) < 20.0 ? "true"
|
||||
: "false");
|
||||
Serial.print(" ");
|
||||
Serial.print(abs(SensorReader::angle.y - y_ref) < 20.0 ? "true" : "false");
|
||||
Serial.print(abs(SensorReader::angle.y - y_ref) < 20.0 ? "true"
|
||||
: "false");
|
||||
Serial.print(" ");
|
||||
Serial.print(abs(SensorReader::angle.z - z_ref) < 20.0 ? "true" : "false");
|
||||
Serial.print(abs(SensorReader::angle.z - z_ref) < 20.0 ? "true"
|
||||
: "false");
|
||||
Serial.print(" ");
|
||||
Serial.println(analogRead(JOYSTICK_VRX));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user