public void init(FlightAssistantRegistry registry, Log log, FlightAssistantControls controls, Sensors sensors, FlightAssistantConfig config) { this.config = config; this.sensors = sensors; this.thrustControl = controls.thrustControl; this.gyroControl = controls.gyroControl; this.registry = registry; this.log = log; }
public void init(FlightAssistantRegistry registry, Log log, FlightAssistantControls controls, Sensors sensors, FlightAssistantConfig config) { this.config = config; this.sensors = sensors; this.thrustControl = controls.thrustControl; this.registry = registry; this.log = log; this.cruisingSpeed = config.cruiseControlDefaultCruisingSpeed; }
/** * Loops through all blocks of type IMyThrust and puts them in a dictionary that * groups them by the direction in which they move the ship */ public static Dictionary <Direction, List <IMyThrust> > identifyThrusters(FlightAssistantRegistry registry) { // Initialize the dictionary Dictionary <Direction, List <IMyThrust> > groupedThrusters = new Dictionary <Direction, List <IMyThrust> >(); groupedThrusters.Add(Direction.FORWARD, new List <IMyThrust>()); groupedThrusters.Add(Direction.BACKWARD, new List <IMyThrust>()); groupedThrusters.Add(Direction.LEFT, new List <IMyThrust>()); groupedThrusters.Add(Direction.RIGHT, new List <IMyThrust>()); groupedThrusters.Add(Direction.UP, new List <IMyThrust>()); groupedThrusters.Add(Direction.DOWN, new List <IMyThrust>()); // Get the thrusters from the grid List <IMyThrust> thrusters = new List <IMyThrust>(); registry.gridTerminalSystem.GetBlocksOfType <IMyThrust>(thrusters); // Get the controller's transformation matrix in relation to the grid Matrix controllerOrientationMatrix; registry.controller.Orientation.GetMatrix(out controllerOrientationMatrix); // Invert the controller's transformation matrix so it can be used in // transforming the thruster's orientation vectors to the controller's // coordinate system Matrix inverseControllerOrientationMatrix = Matrix.Invert(controllerOrientationMatrix); // Group the thrusters into the dictionary categories // NOTE: the direction in which the thruster moves the ship is opposite from // the direction in which the thruster fires in order to move the ship thrusters.ForEach(thruster => { // Align the thruster's orientation vector to the controller's coordinate // system Vector3D alignedThrustVector = Vector3D.Transform( directionToVector3D(thruster.Orientation.Forward), inverseControllerOrientationMatrix ); // Match the thruster to the appropriate direction foreach (Direction direction in groupedThrusters.Keys) { if (areVectorsOpposite(alignedThrustVector, directionToVector3D(direction))) { groupedThrusters[direction].Add(thruster); } } }); // Finally, return the populated dictionary return(groupedThrusters); }
/** * Creates a list of references to ever gyro in the grid while also computing * a rotation matrix that can be applied to a yaw/pitch/roll vector to rotate * it from the control seat's coordinate system into the coordinate system of * every individual gyro (cause the API doesn't do that for some reason) */ public static List <MyGyroWrapper> identifyGyros(FlightAssistantRegistry registry) { // Get the controller's orientation matrix Matrix controllerOrientationMatrix; registry.controller.Orientation.GetMatrix(out controllerOrientationMatrix); // Compute the inverse of the controller's orientation matrix Matrix controllerInverseOrientationMatrix = Matrix.Invert(controllerOrientationMatrix); // List the gyros from the grid List <IMyGyro> gyros = new List <IMyGyro>(); registry.gridTerminalSystem.GetBlocksOfType <IMyGyro>(gyros); // Initialize the return list List <MyGyroWrapper> ret = new List <MyGyroWrapper>(); // For each gyro in the grid gyros.ForEach(gyro => { // Get the orientation matrix of the gyro Matrix mtrx; gyro.Orientation.GetMatrix(out mtrx); // Multiply the rotation matrix of the gyro by the inverse orientation matrix // of the controller. The resulting matrix is applied to yaw/pitch/roll vectors // to rotate the gyro in reference to the controller rather than the grid mtrx = Matrix.Multiply(mtrx, controllerInverseOrientationMatrix); // Add the new GyroWrapper to the return list ret.Add(new MyGyroWrapper(gyro, mtrx)); }); // Return the list return(ret); }
public void init(FlightAssistantRegistry registry) { this.registry = registry; }
public void init(FlightAssistantRegistry registry) { thrustControl.init(registry); gyroControl.init(registry); }