SDK Question Respectfully asking help with PManager vs. RotateVector

tauruslittrow84

New member
Joined
Nov 12, 2011
Messages
58
Reaction score
0
Points
0
I know all you software developers are extremely busy, but if I might humbly ask for your expertise regarding an ongoing problem with development. My craft spent a year as a tail-sitter, but was oriented like a LEM. Its z axis was its thrust axis. This caused all sort of crazy landings due to TD points. I finally realized Orbiter was generally not meant for this orientation. So I completely redesigned my craft, Y axis up-down, z axis front back. This caused months of delay with new animation orientations, etc. I might mention I spent months of research of how to include "Payload Manager" into my craft. My skill with C++ and the combination just hated payload manger. Finally, SUCCESS. Upon the reorientation, I found that it did no good putting a tailsitter it Orbiters default orientation because the Autopilots were then screwed up. Prograde was now not Prograde, etc. I nearly started a war asking for help with Hylnkacg's code for overriding the autopilots. Meson800 was finally brilliant in helping me get that accomplished. SUCCESS again....WELL NOOOWWW...(really frustrated here) Payload Manager HATES the autopilot override. It seems it just doesnt now how to attach payloads anymore and just leaves them on the launch pad on their TD points after main ship takes off. I use the custom editor to twist and turn my payloads which are outter fairings halves that make my covered craft look like a typical Saturn or DeltaIV oriented rocket. Before the autopilot override they attached nicely anyway I needed and scenario editor saved their orientation for new launches nicely. Now as I say, it apparently doesn't know how or where to attach these fairings to my craft. It was so difficult to get PM to work. I DON"T WANT TO ABANDON PM. Some will say why dont you use UCGO, etc. If there is no way, to correct this problem... i after several years will say.....I am finally defeated. I am just frustrated that this supreme program called Orbiter is so hard to work with when it comes to craft like Surveyor, LEMs, VIKING, 4 leggers. It was once the basis of Space exploration, manned and unmanned. Here, if you are not Buck Rodgers in a space plane it seems you are doomed in your development, that is if you are a dumb noober like me. Incidentally, I have tried altering the part of the code where it says "Now we must fine tune Payload Manager for your craft" the default orientations for attachment points, etc. (No change of luck there) If I am using it right). If you look at the photo, it shows the fairings misaligned on the pad. Now with PM, I can orient them correctly. But when I launch they are left on the pad unattached. Pay no attention to the td points with the nose cone tips on the ground. I can fix that by re-ordering the td points . But that doesnt matter. My td points used to be on the fairing's sides so when they hit the ground or ocean they didnt stand up like that..but they then just lay underneath, the craft unattached also. None of this happened before the addition of the autopilot override code. But for my sanity I will have no other recourse but to give up without your much needed and much appreciated help. I respectfully ask for your reply if you are willing to deal with Payload Manager and Hylnkacg's autopilot code. Thanks so much. TaurusLittorow84.:tiphat:
Code:
#define ORBITER_MODULE
#include "chippersat.h" 
#include "Orbitersdk.h" 
#include "payloadmanager.h"
#include "ScnEditorAPI.h"
#include "DlgCtrl.h" 
#include <math.h>
#include <stdio.h>
#include "OrbiterSoundSDK40.h"
#include "OrbiterAPI.h" 
#include "DrawAPI.h"

 
 


// ==============================================================
// chippersat class implementation
// ==============================================================

// --------------------------------------------------------------
// Constructor
// --------------------------------------------------------------
 
chippersat::chippersat (OBJHANDLE hObj, int fmodel)
: VesselWithPM (hObj, fmodel)
 
{
    
	shouldAnimateTheThing = false;
	pan_proc = 0.0;
	pan_status = DOOR_CLOSED;
	radarflag_proc = 0.0; 	 
	DefineAnimations (); 
	j_name[0]	= '\0';
	j_timer		= 0;
}

 

void chippersat::PM_clbkPayloadJettisoned(int slot_idx, OBJHANDLE jettisoned_ship)
{
 

	oapiGetObjectName(jettisoned_ship, j_name, 32);
	j_timer = -5;
}

void chippersat::PM_clbkVehicleCapsChanged()
{
	//Here you can make some action on vehicle's capabilities change
}
 

//

// --------------------------------------------------------------
// Define animation sequences for moving parts
// --------------------------------------------------------------
void chippersat::DefineAnimations (void)
{
	// 1. SolarPanels
	 ANIMATIONCOMPONENT_HANDLE parent1,parent2; 
 
    static UINT  mgroup_pan1arm[1] = {4};  //PANEL with arm
	static MGROUP_ROTATE pan1arm (0, mgroup_pan1arm, 1,
        _V(1.987,1.780, 0.218 ), _V(0,-1,0), (float)(88*RAD));
    static UINT mgroup_pan2arm[1] = {6};  //PANEL with arm
    static MGROUP_ROTATE pan2arm (0, mgroup_pan2arm, 1,
        _V(-2.172,1.780,0.035), _V(0,-1,0), (float)(95*RAD));
    static UINT mgroup_pan3top[1] = {5}; //PANEL 
    static MGROUP_ROTATE pan3top (0, mgroup_pan3top, 1,
        _V(2.045,1.940,1.882), _V(0, 0, 1), (float)(165*RAD));  
    static UINT mgroup_pan4top[1] = {7}; //PANEL 
    static MGROUP_ROTATE pan4top (0, mgroup_pan4top, 1,
        _V(-2.125,1.940,.502 ), _V(0, 0, 1), (float)(-195*RAD));	   
	static UINT mgroup_panRtop[1] = {7}; //PANEL 
    static MGROUP_ROTATE panRtop (0, mgroup_panRtop, 1,
        _V(-2.093,1.940,1.414 ), _V(0, 1, 0), (float)(-8*RAD));
       anim_pan = CreateAnimation (0.0);
       parent1 = AddAnimationComponent (anim_pan, 0, .4, &pan1arm);
       parent2 = AddAnimationComponent (anim_pan, 0, .4, &pan2arm);     
                 AddAnimationComponent (anim_pan, .35, 1, &pan3top, parent1);
                 AddAnimationComponent (anim_pan, .35, 1, &pan4top, parent2);
       anim_panRtop = CreateAnimation (0.0);
		   AddAnimationComponent (anim_pan, 0,.4, &panRtop);
                        
     
	// 2. Radar Flag
	static UINT meshgroup_radarflag[1] = {8};
	static MGROUP_ROTATE radarflag (0, meshgroup_radarflag, 1, _V(0.148,3.062,0.166), _V(0,1,0), (float)(360*RAD));
	anim_radarflag = CreateAnimation (0);
	AddAnimationComponent (anim_radarflag, 0, 1, &radarflag);

	
}

void chippersat::ActivateSolarPanels (DoorStatus action)
{
	pan_status = action;
}

void chippersat::RevertSolarPanels (void)
{
	ActivateSolarPanels ((pan_status == DOOR_CLOSED || pan_status == DOOR_CLOSING) ?
		DOOR_OPENING : DOOR_CLOSING);
}

void chippersat::ActivateRadarflag (DoorStatus action)
{
	radarflag_status = action;
}
 // --------------------------------------------------------------
 
 

// ==============================================================
// Overloaded callback functions
// ==============================================================

// --------------------------------------------------------------
// Set vessel class parameters
// --------------------------------------------------------------
 // ==============================================================
// Some vessel parameters
// ==============================================================
 
const double MASS = 1815.0;
const double FUELMASS = 10000;
const double ISP = 3e4;
const double MAXMAINTH = 500000;
const double MAXHOVERTH = 35000;
const double MAXRCSTH = 8000;


 
// --------------------------------------------------------------
// Set the capabilities of the vessel class
// --------------------------------------------------------------
 
 void chippersat::clbkSetClassCaps (FILEHANDLE cfg)

 {
 	
	SetEmptyMass (1863.0);	 
	SetSize (4);
	SetCW (0.7, 0.7, 0.7, 0.4);
	SetCrossSections (_V(42.19, 34.58, 38.11)); 
	SetRotDrag (_V(0.4,0.4,0.4));	 
	SetPMI (_V(7.16,4.08,7.27));
	SetCameraOffset (_V(0,0.8,0));
	SetDockParams  (_V(0,1.3,-1), _V(0,1,0), _V(0,0,-1));
	SetTouchdownPoints (_V(4,-5.9,-4),_V(0,-5.9,4),_V(0,-5.9,-4));
    SetSurfaceFrictionCoeff (0.4, 0.4);
   
  
 

	// propellant resource
	PROPELLANT_HANDLE hpr = CreatePropellantResource (FUELMASS);
	
	// ***************** thruster definitions *******************
THRUSTER_HANDLE th_main, th_hover;
	THRUSTER_HANDLE th_rcs[24], th_group[4];
 


	PARTICLESTREAMSPEC contrail_main = {
		0, 5.0, 16, 200, 0.15, 1.0, 5, 3.0, PARTICLESTREAMSPEC::DIFFUSE,
		PARTICLESTREAMSPEC::LVL_PSQRT, 0, 2,
		PARTICLESTREAMSPEC::ATM_PLOG, 1e-4, 1
	};
	PARTICLESTREAMSPEC contrail_hover = {
		0, 5.0, 8, 200, 0.15, 1.0, 5, 3.0, PARTICLESTREAMSPEC::DIFFUSE,
		PARTICLESTREAMSPEC::LVL_PSQRT, 0, 2,
		PARTICLESTREAMSPEC::ATM_PLOG, 1e-4, 1
	};
	PARTICLESTREAMSPEC exhaust_main = {
		0, 8.0, 20, 0.0, 0.1, 0.3, 16, 3.0, PARTICLESTREAMSPEC::EMISSIVE,
		PARTICLESTREAMSPEC::LVL_LIN, 0, 1,
		PARTICLESTREAMSPEC::ATM_FLAT, 1, 1
	};

	PARTICLESTREAMSPEC exhaust_hover = {
		0, 2.0, 10, 200, 0.05, 0.05, 8, 1.0, PARTICLESTREAMSPEC::EMISSIVE,
		PARTICLESTREAMSPEC::LVL_SQRT, 0, 1,
		PARTICLESTREAMSPEC::ATM_PLOG, 1e-5, 0.1
	};
	th_main = CreateThruster (_V(0,-4.35,0), _V(0,1,0), MAXMAINTH, hpr, ISP);
	CreateThrusterGroup (&th_main, 1, THGROUP_MAIN);
	AddExhaust (th_main, 8, 1, _V(0,-4.35,0), _V(0,1,0));

	th_hover = CreateThruster (_V(0,-4.35,0), _V(0,1,0), MAXHOVERTH, hpr, ISP);
	CreateThrusterGroup (&th_hover, 1, THGROUP_HOVER);
	AddExhaust (th_hover, 8, 1, _V(0,-4.35,0), _V(0,1,0));
	 

	AddExhaustStream (th_hover, _V(0,-10,0), &contrail_hover); 
	AddExhaustStream (th_main, _V(0,-10,0), &contrail_main);
	AddExhaustStream (th_hover, _V(0,-5,0), &exhaust_hover);	 
	AddExhaustStream (th_main, _V(0,-5,0), &exhaust_main);

	th_rcs[ 0] = CreateThruster (_V(0,1.3,2), _V(0,0,-1), MAXRCSTH, hpr, ISP);
	th_rcs[ 1] = CreateThruster (_V(0,-1.3,2), _V(0,0,-1), MAXRCSTH, hpr, ISP);
	th_rcs[ 2] = CreateThruster (_V(0,1.3,2), _V(0,0,-1), MAXRCSTH, hpr, ISP);
	th_rcs[ 3] = CreateThruster (_V(0,-1.3,2), _V(0,0,-1), MAXRCSTH, hpr, ISP);
	th_rcs[ 4] = CreateThruster (_V(0,1.3,-2), _V(0,0,1),MAXRCSTH, hpr, ISP);
	th_rcs[ 5] = CreateThruster (_V(0,-1.3,-2), _V(0,0,1), MAXRCSTH, hpr, ISP);
	th_rcs[ 6] = CreateThruster (_V(0,1.3,-2), _V(0,0,1), MAXRCSTH, hpr, ISP);
	th_rcs[ 7] = CreateThruster (_V(0,-1.3,2), _V(0,0,1), MAXRCSTH, hpr, ISP);
	th_rcs[ 8] = CreateThruster (_V(2,1.3,0), _V(-1,0,0), MAXRCSTH, hpr, ISP);
	th_rcs[ 9] = CreateThruster (_V(2,-1.3,0),_V(-1,0,0), MAXRCSTH, hpr, ISP);
	th_rcs[10] = CreateThruster (_V(2,1.3,0), _V(-1,0,0), MAXRCSTH, hpr, ISP);
	th_rcs[11] = CreateThruster (_V(2,-1.3,0), _V(-1,0,0), MAXRCSTH, hpr, ISP);
    th_rcs[12] = CreateThruster (_V(-2,1.3,0), _V(1,0,0), MAXRCSTH, hpr, ISP);
	th_rcs[13] = CreateThruster (_V(-2,-1.3,0),_V(1,0,0), MAXRCSTH, hpr, ISP);
	th_rcs[14] = CreateThruster (_V(-2,1.3,0), _V(1,0,0), MAXRCSTH, hpr, ISP);
	th_rcs[15] = CreateThruster (_V(-2,-1.3,0), _V(1,0,0), MAXRCSTH, hpr, ISP);
	th_rcs[16] = CreateThruster (_V(-2.287,-1.5,-2.126), _V(0,0,1), MAXRCSTH, hpr, ISP);
	th_rcs[17] = CreateThruster (_V(2.287,-1.5,2.126), _V(0,0,-1), MAXRCSTH, hpr, ISP); 
	th_rcs[18] = CreateThruster (_V(-2.126,-1.5,2.287), _V(0,0,-1), MAXRCSTH, hpr, ISP);
	th_rcs[19] = CreateThruster (_V(2.126,-1.5,-2.287), _V(0,0,1), MAXRCSTH, hpr, ISP);
    th_rcs[20] = CreateThruster (_V(-1.8,-1.5,-1.8), _V(0,-1,0), MAXRCSTH, hpr, ISP);
	th_rcs[21] = CreateThruster (_V(1.8,-1.5,1.8), _V(0,-1,0), MAXRCSTH, hpr, ISP); 
    th_rcs[22] = CreateThruster (_V(-1.8,-2.6,1.8), _V(0,1,0), MAXRCSTH, hpr, ISP);
	th_rcs[23] = CreateThruster (_V(1.8,-2.6,-1.8), _V(0,1,0), MAXRCSTH, hpr, ISP); 


	th_group[0] = th_rcs[2];
	th_group[1] = th_rcs[7];	 
	CreateThrusterGroup (th_group, 2, THGROUP_ATT_PITCHUP);

	th_group[0] = th_rcs[3];
	th_group[1] = th_rcs[6];	 
	CreateThrusterGroup (th_group, 2, THGROUP_ATT_PITCHDOWN);

	th_group[0] = th_rcs[8];
	th_group[1] = th_rcs[13]; 
	CreateThrusterGroup (th_group, 2, THGROUP_ATT_BANKLEFT);

	th_group[0] = th_rcs[9];
	th_group[1] = th_rcs[12];
	CreateThrusterGroup (th_group, 2, THGROUP_ATT_BANKRIGHT);

	th_group[0] = th_rcs[8];
	th_group[1] = th_rcs[9];
	th_group[2] = th_rcs[10];
	th_group[3] = th_rcs[11];
	CreateThrusterGroup (th_group, 4, THGROUP_ATT_LEFT);

	th_group[0] = th_rcs[12];
	th_group[1] = th_rcs[13];
	th_group[2] = th_rcs[14];
	th_group[3] = th_rcs[15];
	CreateThrusterGroup (th_group, 4, THGROUP_ATT_RIGHT);

	th_group[0] = th_rcs[18];
	th_group[1] = th_rcs[19];
	CreateThrusterGroup (th_group, 2, THGROUP_ATT_YAWLEFT);

	th_group[0] = th_rcs[16];
	th_group[1] = th_rcs[17];
	CreateThrusterGroup (th_group, 2, THGROUP_ATT_YAWRIGHT);

	th_group[0] = th_rcs[22];
	th_group[1] = th_rcs[23];	 
	CreateThrusterGroup (th_group, 2, THGROUP_ATT_BACK);

	th_group[0] = th_rcs[20];
	th_group[1] = th_rcs[21];	 
	CreateThrusterGroup (th_group, 2, THGROUP_ATT_FORWARD);

    th_group[0] = th_rcs[0];
	th_group[1] = th_rcs[1];
	th_group[2] = th_rcs[2];
	th_group[3] = th_rcs[3];
	CreateThrusterGroup (th_group, 4, THGROUP_ATT_UP);

	th_group[0] = th_rcs[4];
	th_group[1] = th_rcs[5];
	th_group[2] = th_rcs[6];
	th_group[3] = th_rcs[7];
	CreateThrusterGroup (th_group, 4, THGROUP_ATT_DOWN); //Really ATT__FORW, cause 9 is ahead of 6 on number pad

	AddExhaust (th_rcs [0], 1, 0.1, _V(0,1.3,2), _V(0,0,1)); 
    AddExhaust (th_rcs [1], 1, 0.1, _V(0,-1.0,2), _V(0,0,1)); 
    AddExhaust (th_rcs [4], 1, 0.1, _V(0,1.3,-2), _V(0,0,-1)); 
    AddExhaust (th_rcs [5], 1, 0.1, _V(0,-1.0,-2), _V(0,0,-1));
    AddExhaust (th_rcs [6], 1, 0.1, _V(0,1.3,-2), _V(0,0,-1)); 
    AddExhaust (th_rcs [3], 1, 0.1, _V(0,-1.0,2), _V(0,0,1)); 
    AddExhaust (th_rcs [2], 1, 0.1, _V(0,1.3,2), _V(0,0,1)); 
    AddExhaust (th_rcs [7], 1, 0.1, _V(0,-1.0,-2), _V(0,0,-1));
    AddExhaust (th_rcs [8], 1, 0.1, _V(2,1.3,0), _V(1,0,0)); 
    AddExhaust (th_rcs [9], 1, 0.1, _V(2,-1.0,0), _V(1,0,0)); 
    AddExhaust (th_rcs [12], 1, 0.1, _V(-2,1.3,0), _V(-1,0,0)); 
    AddExhaust (th_rcs [13], 1, 0.1, _V(-2,-1.0,0), _V(-1,0,0)); 
    AddExhaust (th_rcs [16], 2, 0.1, _V(-2.287,-1.5,-2.126), _V(0,0,-1)); 
    AddExhaust (th_rcs [17], 2, 0.1, _V(2.287,-1.5,2.126), _V(0,0,1)); 
    AddExhaust (th_rcs [18], 2, 0.1, _V(-2.126,-1.5,2.287), _V(0,0,1)); 
    AddExhaust (th_rcs [19], 2, 0.1, _V(2.126,-1.5,-2.287), _V(0,0,-1)); 
    AddExhaust (th_rcs [20], 2, 0.1, _V(-1.8,-1.5,-1.8), _V(0,1,0)); 
    AddExhaust (th_rcs [21], 2, 0.1, _V(1.8,-1.5,1.8), _V(0,1,0)); 
	AddExhaust (th_rcs [22], 2, 0.1, _V(-1.8,-2.6,1.8), _V(0,-1,0)); 
    AddExhaust (th_rcs [23], 2, 0.1, _V(1.8,-2.6,-1.8), _V(0,-1,0));  


	 
int i;
static VECTOR3 beaconpos[3] = {{-0.875,0.287,2.033},{0.971,1.24,-1.930},{0.996,-0.781,-1.980}};
	static VECTOR3 beaconcol[3] = {{.1, .2, .992},{1,0,0},{0,1,0}};
	for (i = 0; i < 3; i++) {
		beacon[i].shape = (i < 3 ? BEACONSHAPE_STAR : BEACONSHAPE_DIFFUSE);
		beacon[i].pos = beaconpos+i;
		beacon[i].col = beaconcol+i;
		beacon[i].size = (i < 3 ? 0.7 : 0.71);
		beacon[i].falloff = (i < 3 ? 0.6 : 0.61);
		beacon[i].period = (i < 1 ? 13 : 9);
		beacon[i].duration = (i < 1 ? 7 : 5);
		beacon[i].tofs = (i < 1 ? 2 :i < 2 ? 3 :5);
		beacon[i].active = false;
		AddBeacon (beacon+i);



	}

  
 
	// visual specs
	AddMesh ("chippersat");

 
	

	




    // Now it is necessary to tune Payload Manager for your ship
	// default position and orientation for payload slots:
	PM_SetDefaultAttachmentParams(_V(3.09, 0, 0), _V(1, 0, 0), _V(0, 1, 0));
	// the special definition for default position and orientation for payload slot 0 (up-forward with 30 deg pitch):
	PM_SetSlotAttachmentParams(0, _V(3.09, 0, 0), _V(1, 0, 0), _V(0,1,0));
	// the special definition for default position and orientation for payload slot 1 (down-forward with -30 deg pitch):
	PM_SetSlotAttachmentParams(1, _V(-3.09,0,0), _V(-1,0,0), _V(0,1,0));
	// time interval between payload separation, s (1 second by default):
	PM_SetDetachInterval(1.5);
	// speed of payload separation, m/s (1 m/s by default):
	PM_SetDetachSpeed(0.5);
	// transfer control focus to separated payload if it allows control focus (true by default):
	PM_SetSendFocus(false);
	// let Payload Manager to know Principal Moments of Inertia (PMI) of vehicle ship:
	PM_SetVehiclePMI(_V(6.57,6.66,3.70));
	// let Payload Manager to know Cross Sections (CS) of vehicle ship and rules of calculating total cross sections:
	PM_SetVehicleCS (_V(41.58, 36.06, 34.60),_V(0,0,1));
	// maximum number of payloads capability for your vehicle ship (10 by default):
	PM_SetMaximumPayloadsNumber(11);
	// setting period of refreshing PMI and CS on 10 seconds
	PM_SetCapsRefreshPeriod(10);

}



// --------------------------------------------------------------
// Read status from scenario file
// --------------------------------------------------------------
void chippersat::clbkLoadStateEx (FILEHANDLE scn, void *vs)
{
	char *line;

	while (oapiReadScenario_nextline (scn, line)) {
		if (!_strnicmp (line, "PAN", 3)) {
			sscanf (line+3, "%d%lf", &pan_status, &pan_proc);
		}  
else if (!_strnicmp (line, "ANIMATED_THING", 14)) {
			int intToBoolTemp; // MSVC's sscanf doesn't have a format modifier to read a 8-bit int value (other than literally the character itself)
			sscanf (line + 14, "%i %1f", &intToBoolTemp, &radarflag_proc);
			shouldAnimateTheThing = intToBoolTemp != 0;


		}  else {
            PM_LoadState(line);
			ParseScenarioLineEx (line, vs);
		}
	}

	SetAnimation (anim_pan, pan_proc);
	SetAnimation (anim_radarflag, radarflag_proc);
	 
}

// --------------------------------------------------------------
// Save status to scenario file
// --------------------------------------------------------------
void chippersat::clbkSaveState (FILEHANDLE scn)
{
	char cbuf[256];
	SaveDefaultState (scn);
	sprintf (cbuf, "%d %0.4f", pan_status, pan_proc);
	oapiWriteScenario_string (scn, "PAN", cbuf);
	char buf [256];
	sprintf (buf, "%i %1f", (int)shouldAnimateTheThing, radarflag_proc);
	oapiWriteScenario_string (scn, "ANIMATED_THING", buf);
    baseClass::clbkSaveState(scn);

}

 
void chippersat::clbkPreStep (double simt, double simdt, double mjd) 
{ 
  
	 
	//Autopilot variables.
	GetGlobalPos(gPos);				// Get position of vessel in global frame. 
	rBody = GetGravityRef();		// Set object handle 'rBody' to the planet or moon currently being orbited.
	GetRelativePos(rBody, rPos);	// Get position of vessel relative to reference body.
	GetRelativeVel(rBody, rVel);	// Get velocity of vessel relative to reference body.
	GetWeightVector(vGravity);		// Get force exerted on vessel by rbody. (Gravity)

	vHorizon = crossp(rVel, rPos);	// First we use the cross-product of 'rVel' and 'rPos' to find our orbit's "horizon".

	 

 

	Global2Local((rVel + gPos), vPrograde); // To find our prograde vector we need to combine gPos with rVel because Global2Local normally converts positions, not velocities. 
	normalise(vPrograde);

	Global2Local( RotateVector( (rVel+gPos), 90*RAD, vHorizon), vNormal); // We find our orbit-normal vector by repeating the process then rotating the result 90 degrees about the 'horizon'. 
	normalise(vNormal);

	//// Debuggery
	//sprintf(oapiDebugString(), "z %0.3f, y %0.3f, z %0.3f", vPrograde.x, vPrograde.y, vPrograde.z);
	//sprintf(oapiDebugString(), "z %0.3f, y %0.3f, z %0.3f", vNormal.x, vNormal.y, vNormal.z);

	 
 

  // We find our normal vector by repeating the process to find prograde and then rotating it 90 degrees about the 'horizon'.
// ==============================================================
	// This vessel is a "Tail-sitter" who's axis of thrust aligned with the Y axis. 
	// Because Orbiter's default autopilots assume that the vessel's axis of thrust is along the Z+ axis we need to over-ride them.
	// The following code checks to see if a default autopilot is active and if it is, activates the coorisonding over-ride function.
	// ==============================================================

	if (GetNavmodeState(1)==true) AUTOPILOT = Off; // NavmodeState(1) is the default Killrot program. This function did not need to be over-ridden so the custom autopilot stays off. 
	if (GetNavmodeState(2)==true) AUTOPILOT = Off; // NavmodeState(2) is the default Horizon Level program. This function did not get over-ridden either.
	if (GetNavmodeState(3)==true) AUTOPILOT = Prograde;	// Set autopilot to prograde mode.
	if (GetNavmodeState(4)==true) AUTOPILOT = Retrograde; // Set autopilot to retrograde mode.
	if (GetNavmodeState(5)==true) AUTOPILOT = Normal; // Set autopilot to orbit-normal mode.
	if (GetNavmodeState(6)==true) AUTOPILOT = Antinormal; // Set autopilot to anti-normal mode.
	if (GetNavmodeState(7)==true) AUTOPILOT = Hover; // Set autopilot to decent/hover mode.

	// Implement autopilot control inputs.
	if (AUTOPILOT==Prograde)	chippersat::OrientForBurn( vPrograde);
	if (AUTOPILOT==Retrograde)	chippersat::OrientForBurn(-vPrograde);
	if (AUTOPILOT==Normal)	chippersat::OrientForBurn( vNormal);
	if (AUTOPILOT==Antinormal)	chippersat::OrientForBurn(-vNormal);
	//if (AUTOPILOT==Hover)	*Descent/Hover autopilot not yet implimented*
}
 
 void chippersat::clbkPostStep (double simt, double simdt, double mjd)
 {
 	// Animate Solar Panels
 if (pan_status >= DOOR_CLOSING){ 
		double da = simdt * SOLARPANEL_OPERATING_SPEED;
PlayVesselWave(MyID,SOLARPANELSOUND,NOLOOP,255);
		if (pan_status == DOOR_CLOSING) {
			if (pan_proc > 0.0) pan_proc = max (0.0, pan_proc-da);       
			else                pan_status = DOOR_CLOSED;
 PlayVesselWave(MyID,SOLARPANELSOUND,NOLOOP,255);
		} else {
			if (pan_proc < 1.0) pan_proc = min (1.0, pan_proc+da);          
			else                pan_status = DOOR_OPEN;
 
		}
		SetAnimation (anim_pan, pan_proc);
	}
 
	// Animate Radar Flag
	 if (shouldAnimateTheThing) {
double da = simdt * RADARFLAG_OPERATING_SPEED;
radarflag_proc = fmod (radarflag_proc + da, 1.0);
	PlayVesselWave(MyID,RADARFLAGSOUND,NOLOOP,115);
		SetAnimation (anim_radarflag, radarflag_proc);
	}
{
// Translating clbkPostStep to PayloadManager
	baseClass::clbkPostStep(simt, simdt, mjd);

/* Here you can place your poststep procedures
	........
*/

	if(j_timer < 0)
		j_timer += simdt;
}
 }
 void chippersat::OrientForBurn(VECTOR3& tgtVector)
{
	int i;
	for (i = 1; i <= 7; i++) DeactivateNavmode(i); // To prevent competing inputs deactivate Orbiter's default autopilots.
	if (oapiGetTimeAcceleration()> 10) oapiSetTimeAcceleration(1); // To prevent the autopilot from wasting fuel I've restricted time-accel to 10x or less.

	normalise (tgtVector); // The target vector should already been normalised but I'll do it again just to be safe. Normalizing saves us from having to do a lot of math further down the line.
	VECTOR3 ThrustVector = {0,1,0}; // chippersat::GetThrusterDir(th_descent, ThrustVector) // Get the direction of thrust for the main engine.
	VECTOR3 input = crossp(tgtVector,ThrustVector);

	VECTOR3 aVel; chippersat::GetAngularVel(aVel); // Get vessel's current angular velocity and break it down into...
	double PitchV = aVel.x*DEG;	// Pitch [degrees/sec]
	double RollV = aVel.z*DEG;	// Roll [degrees/sec]
	double YawV = aVel.y*DEG;	// Yaw [degrees/sec]

	// Pitch Inputs
	double CurrentRate = PitchV;
	double CommandedRate = asin(input.x)*DEG;
	double pDelta = (CommandedRate - CurrentRate); 

	if ( (pDelta > 0.00) && (CurrentRate <= 5.00) ) chippersat::IncThrusterGroupLevel_SingleStep(THGROUP_ATT_PITCHUP, pDelta);
	else if ( (pDelta < 0.00) && (CurrentRate >= -5.00) ) chippersat::IncThrusterGroupLevel_SingleStep(THGROUP_ATT_PITCHDOWN, -pDelta);

	// Roll Inputs
	CurrentRate = RollV;
	CommandedRate = asin(input.z)*DEG;
	double rDelta = (CommandedRate - CurrentRate); 

	if ( (rDelta > 0.00) && (CurrentRate <= 5.00) ) chippersat::IncThrusterGroupLevel_SingleStep(THGROUP_ATT_BANKRIGHT, rDelta);
	else if ( (rDelta < 0.00) && (CurrentRate >= -5.00) ) chippersat::IncThrusterGroupLevel_SingleStep(THGROUP_ATT_BANKLEFT, -rDelta);

	// Yaw Inputs
	CurrentRate = YawV; 
	CommandedRate = asin(input.y)*DEG;
	double yDelta = (-CommandedRate + CurrentRate);
	
	if ( (yDelta > 0.00) && (CurrentRate >= -5.00) ) chippersat::IncThrusterGroupLevel_SingleStep(THGROUP_ATT_YAWRIGHT, yDelta);
	else if ( (yDelta < 0.00) && (CurrentRate <= 5.00) ) chippersat::IncThrusterGroupLevel_SingleStep(THGROUP_ATT_YAWLEFT, -yDelta);

//// Debuggery
//sprintf(oapiDebugString(), "X %0.3f, Y %0.3f, Z %0.3f", tgtVector.x, tgtVector.y, tgtVector.z);
//sprintf(oapiDebugString(), "X %0.3f, Y %0.3f, Z %0.3f", input.x, input.y, input.z);
//sprintf(oapiDebugString(), "Pitch %0.3f, Roll %0.3f, Yaw %0.3f", PitchV, RollV, YawV);
//sprintf(oapiDebugString(), "Pitch %0.3f, Roll %0.3f, Yaw %0.3f", pDelta, rDelta, yDelta);

}

 
  
 

	 
 


// --------------------------------------------------------------
// Keyboard interface handler (buffered key events)
// --------------------------------------------------------------
 

 

int chippersat::clbkConsumeBufferedKey (DWORD key, bool down, char *kstate)
{
	if (!down) return 0; // only process keydown events

	if (KEYMOD_CONTROL (kstate)) {

		switch (key) {
        case OAPI_KEY_DIVIDE:  // enable/disable RCS
			if (SetAttitudeMode (GetAttitudeMode() >= 1 ? 0 : 1));			 
			return 1;
			case OAPI_KEY_1:
			PM_DetachPayloadByIndex(0);
			return 1;
		case OAPI_KEY_2:
			PM_DetachPayloadByIndex(1);
			return 1;
		case OAPI_KEY_3:
			PM_DetachPayloadByIndex(2);
			return 1;
		case OAPI_KEY_4:
			PM_DetachPayloadByIndex(3);
			return 1;
		case OAPI_KEY_5:
			PM_DetachPayloadByIndex(4);
			return 1;
		case OAPI_KEY_6:
			PM_DetachPayloadByIndex(5);
			return 1;
		case OAPI_KEY_7:
			PM_DetachPayloadByIndex(6);
			return 1;
		case OAPI_KEY_8:
			PM_DetachPayloadByIndex(7);
			return 1;
		case OAPI_KEY_9:
			PM_DetachPayloadByIndex(8);
			return 1;
		case OAPI_KEY_0:
			PM_DetachPayloadByIndex(9);
			return 1;
		}
	}else{
	switch (key) {
		case OAPI_KEY_1: // deploy/retract solar panels
			 
			RevertSolarPanels();
			return 1;
		case OAPI_KEY_2: // start/stop radarflag
		 
			shouldAnimateTheThing = !shouldAnimateTheThing; 
			return 1;
		case OAPI_KEY_J:
			// Pressing J-key will starting payloads jettisoning sequence
			PM_BeginDetachPayloads();
			return 1;


		case OAPI_KEY_7:
			    
for (int i = 0; i < 3; i++) {
		 beacon[0].active = true;
         beacon[1].active = true;
		 beacon[2].active = true;
		 return 1;
	 
	 
}
  
		case OAPI_KEY_8:
 
    
for (int i = 0; i < 3; i++) {
		 beacon[0].active = false;
		 beacon[1].active = false;
		 beacon[2].active = false;
		 return 1;
		 
		 
}
 
 
 

	}
	
	 
	}
	return 0;
}
 void chippersat::clbkPostCreation ()
{
MyID=ConnectToOrbiterSoundDLL(GetHandle());
    SetMyDefaultWaveDirectory("Sound\\_CustomVesselsSounds\\Chippersat\\");
	RequestLoadVesselWave(MyID,SOLARPANELSOUND,"mypanelopening.wav",EXTERNAL_ONLY_FADED_CLOSE);
	RequestLoadVesselWave(MyID,RADARFLAGSOUND,"radflagstart.wav",BOTHVIEW_FADED_CLOSE);
}

 bool chippersat::clbkLoadVC (int id) 
{ 
   SetMeshVisibilityMode (AddMesh (vcmesh_tpl = oapiLoadMeshGlobal ("chippersat_vc")), MESHVIS_VC);
		SetCameraOffset (_V(0,0.3,1)); SetCameraDefaultDirection (_V(0,0,1)); 
 SetCameraRotationRange (RAD*180, RAD*180, RAD*180, RAD*180); 
 SetCameraShiftRange (_V(0,0,0.1), _V(-0.2,0,0), _V(0.2,0,0)); 
 
oapiVCSetNeighbours(-2, 2, 3, -3);
VCMFDSPEC mfd;
 VCHUDSPEC hud;
 

		hud.nmesh = 1;//WHICH MECH NUMBER
		hud.ngroup = 53;//HUD MESH GROUP
		hud.hudcnt = _V(.132,-1.027, 4.434);
		hud.size = 4;
		oapiVCRegisterHUD(&hud);
		mfd.ngroup = 47;//LEFT MFD 
		mfd.nmesh = 1; //WHICH MECH NUMBER
		oapiVCRegisterMFD(0, &mfd);
		mfd.ngroup = 48;//RIGHT MFD 
		mfd.nmesh = 1;  //WHICH MECH NUMBER
		oapiVCRegisterMFD(1, &mfd);
		return 1;
	 
	 

 }


  
 
 

// Scenario Editor definations
DLLCLBK void secInit (HWND hEditor, OBJHANDLE hVessel){
	//Here you can define your own Scenario Editor vessel-specific pages
	//...

	//Define PayloadManager Scenario Editor interface
	PayloadManager::DefineScenarioEditorPage(hEditor, hVessel);
}




 
  
 


 

// ==============================================================
// API callback interface
// ==============================================================
// --------------------------------------------------------------
// Vessel initialisation
// --------------------------------------------------------------
DLLCLBK VESSEL *ovcInit (OBJHANDLE hvessel, int flightmodel)
{
	return new chippersat (hvessel, flightmodel);
}

// --------------------------------------------------------------
// Vessel cleanup
// --------------------------------------------------------------
DLLCLBK void ovcExit (VESSEL *vessel)
{
	if (vessel) delete (chippersat*)vessel;
}
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,588
Reaction score
2,312
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
About the payload fairings, did you remember that Orbiters coordinate system is left handed, not right handed?

Also, you define 11 payloads, but only 2 slots (0, 1) and a single default parameter. Is that your intention? And you set the maximum number after defining payloads slots - is that also your intention?
 

tauruslittrow84

New member
Joined
Nov 12, 2011
Messages
58
Reaction score
0
Points
0
This part of the code was simple cut and paste from the codes own author. I agree the 11 vs. only 2 is puzzling. However, I only need two for my two fairing halves. The most important thing is that I've witness the code work as it should just as it is printed here. The only thing different is that I added the override of Orbiters autopilots. In thought, I for one can imagine why it might affect payload manger. I've changed the ships whole coordinate system so-to-speak and now I want to mix it with code that was only intended for orbiter with its default autopilots. It may be simply not compatible and the only one who may be sure is Kulch...the author. Thanks.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
Are you using PM for just the fairing? Then just do it with attachments.
 

tauruslittrow84

New member
Joined
Nov 12, 2011
Messages
58
Reaction score
0
Points
0
When you say "attachments" thats new to me. Is that like writing Flaghalf: attached in the scenario. That'd be ok. But PManager allows me to keep the fairing on until I press CTR + 1 and CTR +2......How does attachments work and would it do this?
Thanks.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,636
Reaction score
2,613
Points
203
Location
Dallas, TX
You can add a line that detach on key control. In the scenario you would have to attach.

so in the cpp:
Code:
	fairing1 = CreateAttachment(true, _V(-.974, 1, .62), _V(0, 1, 0), _V(0, 0, 1), "CHAIR", false);
You will need to figure out the attachment location.

h:
Code:
ATTACHMENTHANDLE fairing1;

then to detach:
Code:
if (key == OAPI_KEY_D&&KEYMOD_SHIFT(kstate))
{ 
	DetachChild(fairing1);
	return 1;
}
 
Last edited:
Top