GremlinWrangler
Well-known member
For anybody else playing Kerbal Space Program have confirmed that KSPIO works with Teensy 3.5 if you add packed attribute to the vessel data struct:
struct __attribute__((__packed__)) VesselData
As part of using this working on a graphical artificial horizon mapping a sphere. For those playing with beta units who have a display handy the 'renderer' for a wireframe ball looks like
Please note this is BYO display library so add your own setup code and mod the 'clear' and 'display' elements of loop and the 'line' procedure to suit.
Lots of optimization options since do not think this is actually deploying the floating point hardware, and I'm sure there is a way to apply roll without the vector conversion stuffed in the placeLine there but my trig isn't strong enough to make things happen in one go.
struct __attribute__((__packed__)) VesselData
As part of using this working on a graphical artificial horizon mapping a sphere. For those playing with beta units who have a display handy the 'renderer' for a wireframe ball looks like
Code:
int stepsize =30;
int scale = 24;
int center = 25;
float pitch = 30;
float roll =0;
float heading =0;
float zpoint(float longditude,float latitude) //returns depth information, used to mask rear of sphere
{
return 1*cos(longditude+heading )*abs(cos(latitude))*cos(pitch)+sin(pitch)*-sin(latitude);
}
float xpoint(float longditude,float latitude) //get x values from lat/long/heading
{
return scale*sin(longditude+heading)*cos(latitude);
}
float ypoint(float longditude,float latitude) //get y value from lat/long/heading and pitch
{
return scale*cos(longditude+heading )*sin(pitch)*cos(latitude)+scale*sin(latitude)*cos(pitch);
}
//
void line(float x1, float y1,float x2,float y2) //line drawing - change to suit display library
{
display.drawLine(floor(x1), floor(y1), floor(x2),floor(y2) , BLACK);
}
//
void placeLine(float startLong,float startLat,float endLong,float endLat)
{ //applies roll to final co-ordinates via vector conversion
if (zpoint(startLong,startLat)>0&&zpoint(endLong,endLat)>0){
float startDistanceFromCenter = sqrt(sq(xpoint(startLong,startLat))+sq(ypoint(startLong,startLat)));
float endDistanceFromCenter = sqrt(sq(xpoint(endLong,endLat))+sq(ypoint(endLong,endLat)));
float startAngle = atan2(ypoint(startLong,startLat),xpoint(startLong,startLat));
float endAngle = atan2(ypoint(endLong,endLat),xpoint(endLong,endLat));
int rotatedXStart = center+floor(startDistanceFromCenter*cos(roll+startAngle ));
int rotatedYStart = center+floor(startDistanceFromCenter*sin(roll+startAngle ));
int rotatedXEnd = center+floor(endDistanceFromCenter*cos(roll+endAngle));
int rotatedYEnd = center+floor(endDistanceFromCenter*sin(roll+endAngle));
line(rotatedXStart, rotatedYStart, rotatedXEnd,rotatedYEnd );
}
}
void drawBall(float pitchIn,float headingIn,float rollIn) //produces geometry
{
pitch=pitchIn;
heading=headingIn;
roll = rollIn;
for (int i = 0; i < floor(360/stepsize); i++) {
float angle = float(i*stepsize)/180*PI;
int meridiansize = floor(90/stepsize);
for (int l = -meridiansize; l< meridiansize+1; l++) {
float currantLat = float(l)*stepsize/180*PI;
placeLine(angle,currantLat,angle+PI/180*stepsize,currantLat);
placeLine(angle,currantLat,angle,currantLat+PI/180*stepsize);
}
}
}
void loop()
{
display.clearDisplay();
drawBall(sin(float(millis())/4000),float(millis())/2000,sin(float(millis())/2000)/2);
display.display();
}
Lots of optimization options since do not think this is actually deploying the floating point hardware, and I'm sure there is a way to apply roll without the vector conversion stuffed in the placeLine there but my trig isn't strong enough to make things happen in one go.