2323*/
2424#include < ESP32Servo.h>
2525#include < WiiChuck.h>
26+ #include < Wire.h>
27+ #include < Adafruit_Sensor.h>
28+ #include < Adafruit_BNO055.h>
29+ #include < utility/imumaths.h>
2630
2731Servo left;
2832Servo right;
2933Accessory nunchuck;
34+ Adafruit_BNO055 bno = Adafruit_BNO055(55 , 0x28 , &Wire);
3035
36+ bool bnoStarted = false ;
3137 float fmap (float x, float in_min, float in_max, float out_min, float out_max) {
3238 const float run = in_max - in_min;
3339 if (run == 0 ){
@@ -46,10 +52,33 @@ void setup() {
4652 right.write (90 );
4753 Serial.begin (115200 );
4854 nunchuck.begin ();
55+ bnoStarted=bno.begin ();
56+ delay (100 );
4957}
5058
5159// the loop function runs over and over again forever
5260void loop () {
61+ if (bnoStarted){
62+ sensors_event_t orientationData;
63+ bno.getEvent (&orientationData, Adafruit_BNO055::VECTOR_EULER);
64+ Serial.print (" Orient:" );
65+ double x = orientationData.orientation .x ;
66+ double y = orientationData.orientation .y ;
67+ double z = orientationData.orientation .z ;
68+ if (abs (x)<0.001 && abs (y) < 0.001 && abs (z)<0.0001 ){
69+ Serial.println (" IMU Died, reset" );
70+ bnoStarted=false ;
71+ }else {
72+ Serial.print (" \t x= " );
73+ Serial.print (x);
74+ Serial.print (" |\t y= " );
75+ Serial.print (y);
76+ Serial.print (" |\t z= " );
77+ Serial.println (z);
78+ }
79+ }else {
80+ bnoStarted=bno.begin ();
81+ }
5382 nunchuck.readData (); // Read inputs and update maps
5483
5584 float x= -fmap (nunchuck.values [1 ],0 ,255 ,-1.0 ,1.0 );
@@ -59,4 +88,6 @@ void loop() {
5988
6089 left.write (lval);
6190 right.write (rval);
91+ delay (100 );
92+
6293}
0 commit comments