Added Processing viewer for new fusion_usb sketches
This commit is contained in:
parent
a8b22f70a0
commit
b7b4969eee
3 changed files with 104695 additions and 0 deletions
|
|
@ -0,0 +1,165 @@
|
||||||
|
import processing.serial.*;
|
||||||
|
import java.awt.datatransfer.*;
|
||||||
|
import java.awt.Toolkit;
|
||||||
|
import processing.opengl.*;
|
||||||
|
import saito.objloader.*;
|
||||||
|
import g4p_controls.*;
|
||||||
|
|
||||||
|
float roll = 0.0F;
|
||||||
|
float pitch = 0.0F;
|
||||||
|
float yaw = 0.0F;
|
||||||
|
float temp = 0.0F;
|
||||||
|
float alt = 0.0F;
|
||||||
|
|
||||||
|
OBJModel model;
|
||||||
|
|
||||||
|
// Serial port state.
|
||||||
|
Serial port;
|
||||||
|
String buffer = "";
|
||||||
|
final String serialConfigFile = "serialconfig.txt";
|
||||||
|
boolean printSerial = false;
|
||||||
|
|
||||||
|
// UI controls.
|
||||||
|
GPanel configPanel;
|
||||||
|
GDropList serialList;
|
||||||
|
GLabel serialLabel;
|
||||||
|
GCheckbox printSerialCheckbox;
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
size(400, 500, OPENGL);
|
||||||
|
frameRate(30);
|
||||||
|
model = new OBJModel(this);
|
||||||
|
model.load("bunny.obj");
|
||||||
|
model.scale(20);
|
||||||
|
|
||||||
|
// Serial port setup.
|
||||||
|
// Grab list of serial ports and choose one that was persisted earlier or default to the first port.
|
||||||
|
int selectedPort = 0;
|
||||||
|
String[] availablePorts = Serial.list();
|
||||||
|
if (availablePorts == null) {
|
||||||
|
println("ERROR: No serial ports available!");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
String[] serialConfig = loadStrings(serialConfigFile);
|
||||||
|
if (serialConfig != null && serialConfig.length > 0) {
|
||||||
|
String savedPort = serialConfig[0];
|
||||||
|
// Check if saved port is in available ports.
|
||||||
|
for (int i = 0; i < availablePorts.length; ++i) {
|
||||||
|
if (availablePorts[i].equals(savedPort)) {
|
||||||
|
selectedPort = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Build serial config UI.
|
||||||
|
configPanel = new GPanel(this, 10, 10, width-20, 90, "Configuration (click to hide/show)");
|
||||||
|
serialLabel = new GLabel(this, 0, 20, 80, 25, "Serial port:");
|
||||||
|
configPanel.addControl(serialLabel);
|
||||||
|
serialList = new GDropList(this, 90, 20, 200, 200, 6);
|
||||||
|
serialList.setItems(availablePorts, selectedPort);
|
||||||
|
configPanel.addControl(serialList);
|
||||||
|
printSerialCheckbox = new GCheckbox(this, 5, 50, 200, 20, "Print serial data");
|
||||||
|
printSerialCheckbox.setSelected(printSerial);
|
||||||
|
configPanel.addControl(printSerialCheckbox);
|
||||||
|
// Set serial port.
|
||||||
|
setSerialPort(serialList.getSelectedText());
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw()
|
||||||
|
{
|
||||||
|
background(0,0, 0);
|
||||||
|
|
||||||
|
// Set a new co-ordinate space
|
||||||
|
pushMatrix();
|
||||||
|
|
||||||
|
// Simple 3 point lighting for dramatic effect.
|
||||||
|
// Slightly red light in upper right, slightly blue light in upper left, and white light from behind.
|
||||||
|
pointLight(255, 200, 200, 400, 400, 500);
|
||||||
|
pointLight(200, 200, 255, -400, 400, 500);
|
||||||
|
pointLight(255, 255, 255, 0, 0, -500);
|
||||||
|
|
||||||
|
// Displace objects from 0,0
|
||||||
|
translate(200, 350, 0);
|
||||||
|
|
||||||
|
// Rotate shapes around the X/Y/Z axis (values in radians, 0..Pi*2)
|
||||||
|
rotateX(radians(roll));
|
||||||
|
rotateZ(radians(pitch));
|
||||||
|
rotateY(radians(yaw));
|
||||||
|
|
||||||
|
pushMatrix();
|
||||||
|
noStroke();
|
||||||
|
model.draw();
|
||||||
|
popMatrix();
|
||||||
|
popMatrix();
|
||||||
|
//print("draw");
|
||||||
|
}
|
||||||
|
|
||||||
|
void serialEvent(Serial p)
|
||||||
|
{
|
||||||
|
String incoming = p.readString();
|
||||||
|
if (printSerial) {
|
||||||
|
println(incoming);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((incoming.length() > 8))
|
||||||
|
{
|
||||||
|
String[] list = split(incoming, " ");
|
||||||
|
if ( (list.length > 0) && (list[2].equals("Orientation:")) )
|
||||||
|
{
|
||||||
|
roll = float(list[5]);
|
||||||
|
pitch = float(list[4]);
|
||||||
|
yaw = float(list[3]);
|
||||||
|
buffer = incoming;
|
||||||
|
}
|
||||||
|
if ( (list.length > 0) && (list[2].equals("Alt:")) )
|
||||||
|
{
|
||||||
|
alt = float(list[3]);
|
||||||
|
buffer = incoming;
|
||||||
|
}
|
||||||
|
if ( (list.length > 0) && (list[2].equals("Temp:")) )
|
||||||
|
{
|
||||||
|
temp = float(list[3]);
|
||||||
|
buffer = incoming;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set serial port to desired value.
|
||||||
|
void setSerialPort(String portName) {
|
||||||
|
// Close the port if it's currently open.
|
||||||
|
if (port != null) {
|
||||||
|
port.stop();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// Open port.
|
||||||
|
port = new Serial(this, portName, 115200);
|
||||||
|
port.bufferUntil('\n');
|
||||||
|
// Persist port in configuration.
|
||||||
|
saveStrings(serialConfigFile, new String[] { portName });
|
||||||
|
}
|
||||||
|
catch (RuntimeException ex) {
|
||||||
|
// Swallow error if port can't be opened, keep port closed.
|
||||||
|
port = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UI event handlers
|
||||||
|
|
||||||
|
void handlePanelEvents(GPanel panel, GEvent event) {
|
||||||
|
// Panel events, do nothing.
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleDropListEvents(GDropList list, GEvent event) {
|
||||||
|
// Drop list events, check if new serial port is selected.
|
||||||
|
if (list == serialList) {
|
||||||
|
setSerialPort(serialList.getSelectedText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleToggleControlEvents(GToggleControl checkbox, GEvent event) {
|
||||||
|
// Checkbox toggle events, check if print events is toggled.
|
||||||
|
if (checkbox == printSerialCheckbox) {
|
||||||
|
printSerial = printSerialCheckbox.isSelected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
13
processing/bunnyrotate_ahrs_fusion_usb/data/bunny.mtl
Normal file
13
processing/bunnyrotate_ahrs_fusion_usb/data/bunny.mtl
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
# 3ds Max Wavefront OBJ Exporter v0.94b - (c)2007 guruware
|
||||||
|
# File Created: 04.07.2010 10:41:39
|
||||||
|
|
||||||
|
newmtl Body
|
||||||
|
Ns 32
|
||||||
|
d 1
|
||||||
|
Tr 1
|
||||||
|
Tf 1 1 1
|
||||||
|
illum 2
|
||||||
|
Ka 0.0000 0.0000 0.0000
|
||||||
|
Kd 0.7412 0.4784 0.4765
|
||||||
|
Ks 0.3500 0.3500 0.6500
|
||||||
|
|
||||||
104517
processing/bunnyrotate_ahrs_fusion_usb/data/bunny.obj
Normal file
104517
processing/bunnyrotate_ahrs_fusion_usb/data/bunny.obj
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue