SHARE
TWEET

Untitled

a guest Sep 19th, 2019 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %clear java;
  2.  
  3. %javaaddpath(fullfile(pwd, 'krpc-java-0.4.8.jar'));
  4. %javaaddpath(fullfile(pwd, 'javatuples-1.2.jar'));
  5. %javaaddpath(fullfile(pwd, 'protobuf-java-3.8.0.jar'));
  6.  
  7. %import krpc.client.*
  8. import krpc.client.Connection
  9. import krpc.client.RPCException
  10. import krpc.client.services.KRPC
  11. %import krpc.client.services.SpaceCenter
  12. import krpc.client.services.SpaceCenter
  13. import java.io.IOException
  14.  
  15. try
  16.     connection = Connection.newInstance('Foobar');
  17.     krpc = KRPC.newInstance(connection);
  18.     disp(krpc.getStatus().getVersion());
  19.    
  20.     krpc_sc = SpaceCenter.newInstance(connection);
  21.     vessel = krpc_sc.getActiveVessel();
  22.     disp(vessel.getName());
  23.    
  24.     orbit = vessel.getOrbit();
  25.     body = orbit.getBody();
  26.     refFrame = body.getReferenceFrame();
  27.     surfRefFrame = vessel.getSurfaceReferenceFrame();
  28.     FlightFrame = vessel.flight(surfRefFrame);
  29.        
  30.     VesselPos = vessel.position(refFrame);
  31.     VesselVel = vessel.velocity(refFrame);
  32.     VesselDir = vessel.direction(refFrame);
  33.     CtrlIntf = vessel.getControl();
  34.    
  35.     pos_i = VesselPos.getValue0(); pos_j = VesselPos.getValue1(); pos_k = VesselPos.getValue2();
  36.     vel_i = VesselVel.getValue0(); vel_j = VesselVel.getValue1(); vel_k = VesselVel.getValue2();
  37.     dir_i = VesselDir.getValue0(); dir_j = VesselDir.getValue1(); dir_k = VesselDir.getValue2();
  38.    
  39.     tic
  40.     pause('on');
  41.    
  42.     IntError = 0;
  43.     PrevT = toc;
  44.     PrevError = 0;
  45.    
  46.     while 0 == 0,
  47.         FAlt = FlightFrame.getMeanAltitude();
  48.         NewT = toc;
  49.        
  50.         DeltaT = NewT - PrevT;
  51.        
  52.         TargetVal = 300 + heaviside(NewT - 60) .* (NewT - 60) .* -1;
  53.        
  54.         Error = TargetVal - FAlt;
  55.         IntError = IntError + Error .* DeltaT;
  56.         DiffError = (Error - PrevError) ./ DeltaT;    
  57.         Throttle = 0.1 * ( Error + 0.0001 .* IntError + 3.5 .* DiffError);
  58.         PrevError = Error; PrevT = NewT;
  59.        
  60.         Throttle = max(min(Throttle, 1.0), 0.0);
  61.         CtrlIntf.setThrottle(Throttle);
  62.      
  63.         pause(0.010);
  64.     end;
  65.    
  66. catch ME
  67.     disp(ME);
  68. end;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top