I bought the 9DoF Razor IMU chip and connected to a 3D printed solid model and then connected it to the computer using p5 serial control, and then tried to run a code with Processing software
Hypothetically, if I rotate the model, it should show a similar rotation pattern after I run the code, but when I try to do that, there is a problem with the orientation, it is inverted.
https://media.discordapp.net/attachment … height=601
The code for this is:
var serial;
var shape;
var rot=[0,0,0];
var logString=“Waiting”;
function preload() {
shape = loadModel(‘data/BIG_TURBO.obj’);
}
function setup() {
createCanvas(400,400, WEBGL);
serial = new p5.SerialPort();
var portlist = serial.list();
serial.open(“COM10”,{ baudrate: 115200});
serial.on(‘open’, gotOpen);
serial.on(‘data’, gotData);
serial.on(‘error’, serialError);
textSize(15);
xSlide=createSlider(-3.14,3.14,0,0.03);
ySlide=createSlider(-3.14,3.14,0,0.03);
zSlide=createSlider(-3.14,3.14,0,0.03);
}
function draw() {
background(255);
ambientLight(255, 0, 255);
directionalLight(255, 255, 255, 0, 0, 1);
//noStroke();
rotateX(rot[0]+xSlide.value());
rotateY(rot[1]+ySlide.value());
rotateZ(rot[2]+zSlide.value());
scale(30);
model(shape);
}
function gotData() {
var conv=3.14159/180;
var currentString = serial.readStringUntil(“\r\n”);
print(currentString);
var itemized=currentString.split(", ");
if(itemized.length>1){
rot=[itemized[10]*conv, itemized[11]*conv, itemized[12]*conv];
//print(itemized);
}
}
function keyPressed() {
if(key=“r”){
print(“Reseting sensor rotation”);
xSlide.value((xSlide.value()-rot[0]+3.14)%6.28-3.14);
ySlide.value((ySlide.value()-rot[0]+3.14)%6.28-3.14);
zSlide.value((zSlide.value()-rot[0]+3.14)%6.28-3.14);
//xslide.value(0);
//yslide.value(0);
//zslide.value(0);
}
}
function serialError(err){
print(err);
}
function gotOpen(){
print(“OPEN”);
}
When i try to rotate it, the visual rotates in total wrong direction. Please help to fix this orientation problem thank you!