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