Question Question about Sun-tracking solar panels (Advanced)

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
9,995
Reaction score
4,419
Points
203
Location
Toulouse
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...

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:
 
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...

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:
Well, you've only calculated one "SunAngle", and you're sending that to all four solar panels, so they all move the same. You need to calculate two different "SunAngle"s--one for the x-axis solar panels and one for the y-axis solar panels--and send those to their corresponding panels.
 
A. I'm no expert
B. Maybe this will put you on the path...

would an if-then test, work for attitude?

while angle is perpendicular
. lock array
else
. rotate array to perpendicular
. next array
loop

maybe a check state, for each axis?

do period of time
. time expired, is array alligned
. align array, do not align array
new period of time
loop
 
The big problem I think, is that when I calculate "SunAngle" with lppos _V(0,0,1) then "SunAngle2" with lppos2 _V(0,1,0), summing up the two don't give 180° (or 1).

The "x" component _V(x,y,z) plays a role I can't identify.

I would think that summing up the vertical & horizontal components should give me 1, but no.

In fact I get it to work in 2D, but not in 3D.

do period of time
. time expired, is array alligned
. align array, do not align array
new period of time
loop

I don't think we should introduce time there.

Well, you've only calculated one "SunAngle", and you're sending that to all four solar panels, so they all move the same. You need to calculate two different "SunAngle"s--one for the x-axis solar panels and one for the y-axis solar panels--and send those to their corresponding panels.

I fear that the problem is more complex than that.
 
Last edited:
I think I begin to understand the problem a little more.

The problem is that 1° of pitch/yaw (relative to the Sun) when the vessel is "wings leveled" on the ecliptic plane is not equal to 1° of pitch/yaw (r. Sun) in any other configuration.

What I don't have, and I can't get with what I know of maths/physics, is the relationship between those two series of numbers (the math. function that "translates" one serie into the other) :idk:
 
Took another look at the code.

I'm not sure why you need to get the rotation of your vessel relative to the ecliptic. If you use Global2Local, you can determine the location of the sun in the vessel's local frame (which rotates with the vessel). Then, you can use the z and x coordinates to calculate the angle for one set of solar arrays, and the z and y coordinates to calculate the angle of the other set.
 
Back
Top