Hello :tiphat:,
My project is nicely going but I'm stucked with a solar-panels rather complicated problem. I spent an afternoon on it and my brain boils, I think I don't have the proper mathematical tools to "numerize" the situation.
As shows the picture below, my spacecraft has solar panels mounted on Y and Z axis. They can rotate rotate around these axis, and in fact I managed to code animations so that they should track the Sun... but there is a problem with rotations I don't understand.
Using a sample of code found on this forum (already used it for the Lunar Lander), I can get the spacecraft orientation relative to the Sun...
This works wonderfully for each axis... separately. I try to explain myself :
- Be the vessel in a Y rotation (yaw), on the Y plane of the Sun. The Y-axis solar panels perform perfectly. But the X-axis solar are also reacting the same way. While the angle between the nose of the vessel and the Sun grows, the X-axis solar panels tend to rotate on the X-axis. Which is completely inefficient. They should not rotate.
- Be the vessel in a X rotation (pitch), the same things occurs with the Y & X axis inverted.
At this point I'm quite confused and don't see how to proceed. So I would gladly take any idea.
Thank you in advance, :tiphat:
My project is nicely going but I'm stucked with a solar-panels rather complicated problem. I spent an afternoon on it and my brain boils, I think I don't have the proper mathematical tools to "numerize" the situation.
As shows the picture below, my spacecraft has solar panels mounted on Y and Z axis. They can rotate rotate around these axis, and in fact I managed to code animations so that they should track the Sun... but there is a problem with rotations I don't understand.
Using a sample of code found on this forum (already used it for the Lunar Lander), I can get the spacecraft orientation relative to the Sun...
Code:
//Check to see what the angle between the sun and solar arrays
VECTOR3 lspos, rspos; //holder for relative position from sun
VECTOR3 lppos = {0,0,1}; //solar panels tangent point along Y axis
VS = oapiGetFocusObject();
VESSEL * v = oapiGetVesselInterface(VS); //identify our vessel
v->GetGlobalPos(rspos); //relative Sun position
rspos = -rspos/length(rspos); //invert and normalize sun relative position
MATRIX3 R; //holder for rotation matrix
v->GetRotationMatrix(R); //get rotation matrix
lspos = tmul(R,rspos); //inverse rotation
double Roll = lspos.z*DEG; // in fact this isn't roll, I don't know what it is !!
double Pitch = lspos.y*DEG; // relative to the Sun (ecliptic plane ?)
double Yaw = lspos.x*DEG; // relative to the Sun (ecliptic plane ?)
double SunAngle = (((acos(dotp(lspos,lppos)))*(180/PI))); //calculate angle
if (MET > 300)
{
// Animate Solar Panels (up)
SetAnimation (anim_SPupR, 0.5+((SunAngle/90)/2));
SetAnimation (anim_SPdnR, 0.5+((SunAngle/90)/2));
SetAnimation (anim_SPleR, 0.5+((SunAngle/90)/2));
SetAnimation (anim_SPriR, 0.5+((SunAngle/90)/2));
}
This works wonderfully for each axis... separately. I try to explain myself :
- Be the vessel in a Y rotation (yaw), on the Y plane of the Sun. The Y-axis solar panels perform perfectly. But the X-axis solar are also reacting the same way. While the angle between the nose of the vessel and the Sun grows, the X-axis solar panels tend to rotate on the X-axis. Which is completely inefficient. They should not rotate.
- Be the vessel in a X rotation (pitch), the same things occurs with the Y & X axis inverted.
At this point I'm quite confused and don't see how to proceed. So I would gladly take any idea.
Thank you in advance, :tiphat: