Revision 8cc46552

View differences:

examples/bunny/bunny.pde
1
#include <Wire.h>
2
#include <Adafruit_Sensor.h>
3
#include <Adafruit_BNO055.h>
4
#include <utility/imumaths.h>
5

  
6
/* This driver uses the Adafruit unified sensor library (Adafruit_Sensor),
7
   which provides a common 'type' for sensor data and some helper functions.
8
   
9
   To use this driver you will also need to download the Adafruit_Sensor
10
   library and include it in your libraries folder.
11

  
12
   You should also assign a unique ID to this sensor for use with
13
   the Adafruit Sensor API so that you can identify this particular
14
   sensor in any data logs, etc.  To assign a unique ID, simply
15
   provide an appropriate value in the constructor below (12345
16
   is used by default in this example).
17
   
18
   Connections
19
   ===========
20
   Connect SCL to analog 5
21
   Connect SDA to analog 4
22
   Connect VDD to 3.3V DC
23
   Connect GROUND to common ground
24
    
25
   History
26
   =======
27
   2015/MAR/03  - First release (KTOWN)
28
*/
29

  
30
/* Set the delay between fresh samples */
31
#define BNO055_SAMPLERATE_DELAY_MS (50)
32

  
33
Adafruit_BNO055 bno = Adafruit_BNO055(55);
34

  
35
/**************************************************************************/
36
/*
37
    Displays some basic information on this sensor from the unified
38
    sensor API sensor_t type (see Adafruit_Sensor for more information)
39
*/
40
/**************************************************************************/
41
void displaySensorDetails(void)
42
{
43
  sensor_t sensor;
44
  bno.getSensor(&sensor);
45
  Serial.println("------------------------------------");
46
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
47
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
48
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
49
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" xxx");
50
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" xxx");
51
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" xxx");  
52
  Serial.println("------------------------------------");
53
  Serial.println("");
54
  delay(500);
55
}
56

  
57
/**************************************************************************/
58
/*
59
    Arduino setup function (automatically called at startup)
60
*/
61
/**************************************************************************/
62
void setup(void) 
63
{
64
  Serial.begin(115200);
65
  Serial.println("Orientation Sensor Test"); Serial.println("");
66
  
67
  /* Initialise the sensor */
68
  if(!bno.begin())
69
  {
70
    /* There was a problem detecting the BNO055 ... check your connections */
71
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
72
    while(1);
73
  }
74
  
75
  delay(1000);
76
    
77
  /* Display some basic information on this sensor */
78
  displaySensorDetails();
79
}
80

  
81
/**************************************************************************/
82
/*
83
    Arduino loop function, called once 'setup' is complete (your own code
84
    should go here)
85
*/
86
/**************************************************************************/
87
void loop(void) 
88
{
89
  /* Get a new sensor event */ 
90
  sensors_event_t event; 
91
  bno.getEvent(&event);
92
  
93
  /* Board layout:
94
         +----------+
95
         |         *| RST   PITCH  ROLL  HEADING
96
     ACR |*        *| SCL
97
     INT |*        *| SDA     ^            <-\
98
     PS1 |*        *| GND     |              |   
99
     PS0 |*        *| 3VO     Y    Z-->   X -/
100
         |         *| VIN 
101
         +----------+
102
  */
103

  
104
  /* The processing sketch expects data as roll, pitch, heading */
105
  Serial.print(F("Orientation: "));
106
  Serial.print((float)event.orientation.x);
107
  Serial.print(F(" "));
108
  Serial.print((float)event.orientation.y);
109
  Serial.print(F(" "));
110
  Serial.print((float)event.orientation.z);
111
  Serial.println(F(""));
112

  
113
  delay(BNO055_SAMPLERATE_DELAY_MS);
114
}
examples/bunny/processing/cuberotate/cuberotate.pde
1
import processing.serial.*;
2
import java.awt.datatransfer.*;
3
import java.awt.Toolkit;
4
import processing.opengl.*;
5
import saito.objloader.*;
6
import g4p_controls.*;
7

  
8
float roll  = 0.0F;
9
float pitch = 0.0F;
10
float yaw   = 0.0F;
11
float temp  = 0.0F;
12
float alt   = 0.0F;
13

  
14
OBJModel model;
15

  
16
// Serial port state.
17
Serial       port;
18
String       buffer = "";
19
final String serialConfigFile = "serialconfig.txt";
20
boolean      printSerial = false;
21

  
22
// UI controls.
23
GPanel    configPanel;
24
GDropList serialList;
25
GLabel    serialLabel;
26
GCheckbox printSerialCheckbox;
27

  
28
void setup()
29
{
30
  size(400, 550, OPENGL);
31
  frameRate(30);
32
  model = new OBJModel(this);
33
  model.load("bunny.obj");
34
  model.scale(20);
35
  
36
  // Serial port setup.
37
  // Grab list of serial ports and choose one that was persisted earlier or default to the first port.
38
  int selectedPort = 0;
39
  String[] availablePorts = Serial.list();
40
  if (availablePorts == null) {
41
    println("ERROR: No serial ports available!");
42
    exit();
43
  }
44
  String[] serialConfig = loadStrings(serialConfigFile);
45
  if (serialConfig != null && serialConfig.length > 0) {
46
    String savedPort = serialConfig[0];
47
    // Check if saved port is in available ports.
48
    for (int i = 0; i < availablePorts.length; ++i) {
49
      if (availablePorts[i].equals(savedPort)) {
50
        selectedPort = i;
51
      } 
52
    }
53
  }
54
  // Build serial config UI.
55
  configPanel = new GPanel(this, 10, 10, width-20, 90, "Configuration (click to hide/show)");
56
  serialLabel = new GLabel(this,  0, 20, 80, 25, "Serial port:");
57
  configPanel.addControl(serialLabel);
58
  serialList = new GDropList(this, 90, 20, 200, 200, 6);
59
  serialList.setItems(availablePorts, selectedPort);
60
  configPanel.addControl(serialList);
61
  printSerialCheckbox = new GCheckbox(this, 5, 50, 200, 20, "Print serial data");
62
  printSerialCheckbox.setSelected(printSerial);
63
  configPanel.addControl(printSerialCheckbox);
64
  // Set serial port.
65
  setSerialPort(serialList.getSelectedText());
66
}
67
 
68
void draw()
69
{
70
  background(0,0,0);
71

  
72
  // Set a new co-ordinate space
73
  pushMatrix();
74

  
75
  // Simple 3 point lighting for dramatic effect.
76
  // Slightly red light in upper right, slightly blue light in upper left, and white light from behind.
77
  pointLight(255, 200, 200,  400, 400,  500);
78
  pointLight(200, 200, 255, -400, 400,  500);
79
  pointLight(255, 255, 255,    0,   0, -500);
80
  
81
  // Displace objects from 0,0
82
  translate(200, 300, 0);
83
  
84
  // Rotate shapes around the X/Y/Z axis (values in radians, 0..Pi*2)
85
  rotateZ(radians(roll * -1.0F));
86
  rotateX(radians(pitch));
87

  
88
  pushMatrix();
89
  noStroke();
90
  model.draw();
91
  popMatrix();
92
  popMatrix();
93
  //print("draw");
94
}
95

  
96
void serialEvent(Serial p) 
97
{
98
  String incoming = p.readString();
99
  if (printSerial) {
100
    println(incoming);
101
  }
102
  
103
  if ((incoming.length() > 8))
104
  {
105
    String[] list = split(incoming, " ");
106
    if ( (list.length > 0) && (list[0].equals("Orientation:")) ) 
107
    {
108
      roll  = float(list[3]); // Roll = Z
109
      pitch = float(list[2]); // Pitch = Y 
110
      yaw   = float(list[1]); // Yaw/Heading = X
111
      buffer = incoming;
112
    }
113
    if ( (list.length > 0) && (list[0].equals("Alt:")) ) 
114
    {
115
      alt  = float(list[1]);
116
      buffer = incoming;
117
    }
118
    if ( (list.length > 0) && (list[0].equals("Temp:")) ) 
119
    {
120
      temp  = float(list[1]);
121
      buffer = incoming;
122
    }
123
  }
124
}
125

  
126
// Set serial port to desired value.
127
void setSerialPort(String portName) {
128
  // Close the port if it's currently open.
129
  if (port != null) {
130
    port.stop();
131
  }
132
  try {
133
    // Open port.
134
    port = new Serial(this, portName, 115200);
135
    port.bufferUntil('\n');
136
    // Persist port in configuration.
137
    saveStrings(serialConfigFile, new String[] { portName });
138
  }
139
  catch (RuntimeException ex) {
140
    // Swallow error if port can't be opened, keep port closed.
141
    port = null; 
142
  }
143
}
144

  
145
// UI event handlers
146

  
147
void handlePanelEvents(GPanel panel, GEvent event) {
148
  // Panel events, do nothing.
149
}
150

  
151
void handleDropListEvents(GDropList list, GEvent event) { 
152
  // Drop list events, check if new serial port is selected.
153
  if (list == serialList) {
154
    setSerialPort(serialList.getSelectedText()); 
155
  }
156
}
157

  
158
void handleToggleControlEvents(GToggleControl checkbox, GEvent event) { 
159
  // Checkbox toggle events, check if print events is toggled.
160
  if (checkbox == printSerialCheckbox) {
161
    printSerial = printSerialCheckbox.isSelected(); 
162
  }
163
}
examples/bunny/processing/cuberotate/data/bunny.mtl
1
# 3ds Max Wavefront OBJ Exporter v0.94b - (c)2007 guruware
2
# File Created: 04.07.2010 10:41:39
3

  
4
newmtl Body
5
Ns 32
6
d 1
7
Tr 1
8
Tf 1 1 1
9
illum 2
10
Ka 0.0000 0.0000 0.0000
11
Kd 0.7412 0.4784 0.4765
12
Ks 0.3500 0.3500 0.6500
13

  
examples/bunny/processing/cuberotate/data/bunny.obj
1
####
2
#
3
# OBJ File Generated by Meshlab
4
#
5
####
6
# Object bunny.obj
7
#
8
# Vertices: 34835
9
# Faces: 69666
10
#
11
####
12
vn -1.346575 -4.896271 -1.811116
13
v 1.487000 0.373600 2.257600 0.752941 0.752941 0.752941
14
vn -2.353517 -5.669623 -0.379453
15
v 1.580300 0.345100 2.185900 0.752941 0.752941 0.752941
16
vn -3.331489 -4.818274 -1.725233
17
v 1.627500 0.311100 2.226100 0.752941 0.752941 0.752941
18
vn -1.350004 -5.092984 -2.572659
19
v 1.634300 0.078300 2.435200 0.752941 0.752941 0.752941
20
vn -0.345341 -6.207365 -0.638331
21
v 1.518000 0.064400 2.539800 0.752941 0.752941 0.752941
22
vn -0.502028 -5.478112 -2.233162
23
v 1.456800 0.072000 2.520500 0.752941 0.752941 0.752941
24
vn -0.637121 -4.539354 -3.023798
25
v 1.395300 0.079500 2.501300 0.752941 0.752941 0.752941
26
vn 0.020125 -6.238689 -0.400924
27
v 1.285000 0.076200 2.597300 0.752941 0.752941 0.752941
28
vn -0.945325 -4.954727 -2.552756
29
v 1.218100 0.073200 2.586200 0.752941 0.752941 0.752941
30
vn -0.135061 -6.270432 -0.376632
31
v 1.107900 0.069800 2.682400 0.752941 0.752941 0.752941
32
vn -0.549599 -5.461109 -2.200781
33
v 1.043500 0.072100 2.667300 0.752941 0.752941 0.752941
34
vn -0.610568 -4.638136 -3.359110
35
v 0.988000 0.090200 2.639500 0.752941 0.752941 0.752941
36
vn -0.063115 -6.185869 -0.886773
37
v 0.869300 0.071000 2.747900 0.752941 0.752941 0.752941
38
vn -0.522453 -5.461117 -2.364014
39
v 0.807900 0.078500 2.728600 0.752941 0.752941 0.752941
40
vn -0.186979 -5.610107 -2.236772
41
v 0.633400 0.077300 2.809300 0.752941 0.752941 0.752941
42
vn 0.104933 -5.129907 -2.304061
43
v 0.563300 0.069000 2.802100 0.752941 0.752941 0.752941
44
vn -0.313654 -4.721046 -2.073034
45
v 0.596200 0.376200 2.535900 0.752941 0.752941 0.752941
46
vn -0.652416 -4.604906 -3.471313
47
v 0.510400 0.092500 2.770500 0.752941 0.752941 0.752941
48
vn 0.270318 -6.253489 -0.475421
49
v 0.392500 0.073500 2.877900 0.752941 0.752941 0.752941
50
vn -0.543972 -5.416714 -1.904827
51
v 0.325900 0.071200 2.866000 0.752941 0.752941 0.752941
52
vn -0.529177 -4.712361 -3.181963
53
v 0.269900 0.089100 2.838600 0.752941 0.752941 0.752941
54
vn 0.164593 -6.255838 -0.535341
55
v 0.154200 0.073100 2.941400 0.752941 0.752941 0.752941
56
vn -0.148527 -5.472015 -2.074268
57
v 0.087700 0.070800 2.929400 0.752941 0.752941 0.752941
58
vn -0.283110 -4.842135 -2.628733
59
v 0.023800 0.073500 2.913200 0.752941 0.752941 0.752941
60
vn -0.189360 -6.273220 -0.298734
61
v -0.084000 0.072500 3.004500 0.752941 0.752941 0.752941
62
vn -0.080797 -5.736409 -1.892364
63
v -0.147900 0.075200 2.988500 0.752941 0.752941 0.752941
64
vn 0.438706 -5.376206 -1.933100
65
v -0.017600 0.367000 2.648600 0.752941 0.752941 0.752941
66
vn 0.621045 -5.126215 -1.764571
67
v 0.052000 0.375300 2.655600 0.752941 0.752941 0.752941
68
vn 0.504590 -5.578479 -1.924711
69
v -0.214200 0.072800 2.976400 0.752941 0.752941 0.752941
70
vn 0.473248 -5.571465 -1.654917
71
v -0.219100 0.357900 2.615100 0.752941 0.752941 0.752941
72
vn 0.736822 -5.747169 -1.421582
73
v -0.674600 0.066200 2.884000 0.752941 0.752941 0.752941
74
vn 0.998559 -5.223456 -1.573582
75
v -0.835800 0.052700 2.747900 0.752941 0.752941 0.752941
76
vn 1.733087 -5.108392 -1.837279
77
v -0.623500 0.335300 2.551000 0.752941 0.752941 0.752941
78
vn -0.103676 -6.252668 0.547260
79
v -0.741100 0.063800 2.871700 0.752941 0.752941 0.752941
80
vn -0.173072 -6.229100 0.687361
81
v -0.804900 0.066400 2.855900 0.752941 0.752941 0.752941
82
vn 0.790947 -5.832245 -0.990056
83
v -0.899500 0.055400 2.732300 0.752941 0.752941 0.752941
84
vn -0.319873 -6.224010 0.575417
85
v -0.966000 0.053000 2.720100 0.752941 0.752941 0.752941
86
vn 1.342007 -5.313892 -0.825394
87
v -0.994100 0.044300 2.608300 0.752941 0.752941 0.752941
88
vn -0.645228 -6.208881 0.579963
89
v -1.055300 0.052100 2.588700 0.752941 0.752941 0.752941
90
vn 1.300535 -5.354733 -1.010988
91
v -1.083300 0.043300 2.477000 0.752941 0.752941 0.752941
92
vn -0.076650 -6.255035 -0.187202
93
v -1.144300 0.051100 2.457500 0.752941 0.752941 0.752941
94
vn 2.361990 -5.623356 -0.906716
95
v -1.159200 0.067500 2.326600 0.752941 0.752941 0.752941
96
vn 3.982127 -4.435106 -0.220889
97
v -1.010400 0.227200 2.220100 0.752941 0.752941 0.752941
98
vn 1.783025 -5.619010 0.390577
99
v -0.911200 0.291200 2.185600 0.752941 0.752941 0.752941
100
vn 2.036253 -5.306568 -0.707604
101
v -0.884100 0.299700 2.298300 0.752941 0.752941 0.752941
102
vn 0.652420 -6.192426 0.546890
103
v -0.817300 0.302100 2.310500 0.752941 0.752941 0.752941
104
vn 1.387648 -5.130943 -1.629014
105
v -0.787100 0.316300 2.418600 0.752941 0.752941 0.752941
106
vn 1.440011 -5.767185 -1.441930
107
v -0.723000 0.313600 2.434700 0.752941 0.752941 0.752941
108
vn 0.989593 -6.165750 0.216503
109
v -0.648100 0.331900 2.434600 0.752941 0.752941 0.752941
110
vn 0.570066 -5.510625 -1.612911
111
v -0.610900 0.063500 2.899600 0.752941 0.752941 0.752941
112
vn 0.666255 -5.569387 -1.839717
113
v -0.554400 0.342800 2.559300 0.752941 0.752941 0.752941
114
vn 0.461678 -5.593730 -2.277379
115
v -0.469800 0.083600 2.912600 0.752941 0.752941 0.752941
116
vn 0.909842 -5.568046 -1.970208
117
v -0.539000 0.076100 2.904200 0.752941 0.752941 0.752941
118
vn 0.643698 -5.597113 -1.816634
119
v -0.487000 0.345800 2.570500 0.752941 0.752941 0.752941
120
vn 0.164720 -5.567540 -2.007680
121
v -0.408700 0.075800 2.932300 0.752941 0.752941 0.752941
122
vn 0.352289 -5.597385 -1.694317
123
v -0.353200 0.351800 2.592800 0.752941 0.752941 0.752941
124
vn -0.088681 -5.736596 2.082758
125
v -0.152100 0.360900 2.626200 0.752941 0.752941 0.752941
126
vn -0.369418 -1.580893 2.951816
127
v -0.085000 0.363900 2.637400 0.752941 0.752941 0.752941
128
vn 0.288424 -5.580446 -1.884238
129
v -0.344600 0.073100 2.948300 0.752941 0.752941 0.752941
130
vn 0.576002 -5.570906 -1.655518
131
v -0.286100 0.354900 2.604000 0.752941 0.752941 0.752941
132
vn -0.702238 -4.482433 -1.943914
133
v 0.119000 0.378400 2.666700 0.752941 0.752941 0.752941
134
vn -0.110303 -5.675516 -1.413265
135
v 0.220700 0.365900 2.583200 0.752941 0.752941 0.752941
136
vn -0.297346 -4.693354 -2.105836
137
v 0.357600 0.377300 2.601400 0.752941 0.752941 0.752941
138
vn 0.324566 -6.226826 0.750516
139
v 0.462100 0.370100 2.513600 0.752941 0.752941 0.752941
140
vn -0.163350 -5.478781 -1.541008
141
v 0.529200 0.373200 2.524800 0.752941 0.752941 0.752941
142
vn -0.024927 -6.223534 0.618915
143
v 0.700800 0.369000 2.448100 0.752941 0.752941 0.752941
144
vn -0.143086 -5.496031 -1.723713
145
v 0.765300 0.366700 2.463400 0.752941 0.752941 0.752941
146
vn -0.214108 -4.686597 -2.050035
147
v 0.834900 0.375000 2.470300 0.752941 0.752941 0.752941
148
vn 0.321137 -6.227229 0.748064
149
v 0.939600 0.367800 2.382500 0.752941 0.752941 0.752941
150
vn 0.017307 -5.489621 -1.674593
151
v 1.006600 0.370800 2.393500 0.752941 0.752941 0.752941
152
vn -0.231984 -4.668063 -2.057247
153
v 1.076500 0.379100 2.400400 0.752941 0.752941 0.752941
154
vn 0.321192 -6.226999 0.748986
155
v 1.181100 0.371900 2.312400 0.752941 0.752941 0.752941
156
vn -0.158876 -5.472498 -1.550710
157
v 1.248200 0.374900 2.323500 0.752941 0.752941 0.752941
158
vn -0.387549 -4.522632 -2.263290
159
v 1.315200 0.377900 2.334600 0.752941 0.752941 0.752941
160
vn -0.035618 -6.234802 0.394712
161
v 1.423100 0.375900 2.242400 0.752941 0.752941 0.752941
162
vn -3.433449 -3.453228 -3.060567
163
v 1.663400 0.255500 2.282900 0.752941 0.752941 0.752941
164
vn -0.813605 -4.585639 -2.885951
165
v 0.746500 0.086100 2.709200 0.752941 0.752941 0.752941
166
vn 0.579367 -5.156244 -1.824563
167
v 0.290500 0.374300 2.590200 0.752941 0.752941 0.752941
168
vn 0.328390 -5.564126 -1.754651
169
v -0.280700 0.070400 2.964500 0.752941 0.752941 0.752941
170
vn 0.467056 -5.531989 -1.495967
171
v -0.417400 0.354200 2.577500 0.752941 0.752941 0.752941
172
vn 1.465364 -4.692305 1.564907
173
v -2.045800 0.144100 0.695200 0.752941 0.752941 0.752941
174
vn 1.896208 -5.320906 0.374283
175
v -2.301500 -0.008100 0.895600 0.752941 0.752941 0.752941
176