Example #1
0
        public byte Tick(SensorUpdate sensors, FlightState state)
        {
            if (state != lastState)
            {
                // Trigger ignition with state change
                if (state == FlightState.LAUNCH)
                {
                    flightStatusController.RequestFlightStateChange(FlightState.ASCENT_PHASE);
                    lastState = state;
                    return(Ignition(0x01, true));
                }
            }
            switch (state)
            {
            case FlightState.DESCENT_PHASE:
                return(HandleDescent(sensors));

            case FlightState.ASCENT_PHASE:
            case FlightState.LAUNCH:
            case FlightState.MISSION_ENDED:
            case FlightState.ON_PAD:
            default:
                return(Pyros);
            }
        }
Example #2
0
        private static SensorUpdate GetDynamics()
        {
            SensorUpdate newSense = new SensorUpdate();

            // Calculate Acceleration Vectors
            Vector3D <float> accel     = new Vector3D <float>();
            Vector3D <float> velocity  = new Vector3D <float>();
            Vector3D <float> dragForce = new Vector3D <float>();

            // Compute drag force
            velocity = accel.Multiply(Time.FLIGHT_RESOLUTION);
            // dragForce = Cd * p * v^2 / 2 * A
            dragForce = simRocket.GetDragCoefficients().Multiply(sensorPackage.BarometricPressure);
            // RAY TRACING FOR DRAG ???
            dragForce = dragForce * velocity * velocity;// * simRocket.GetSurfaceAreas(); <-- Need to find a way to do this...
            dragForce = dragForce.Divide(2);

            // Set new acceleration vectors
            accel           = currentControl.Thrust - dragForce;
            newSense.AccelX = accel.X;
            newSense.AccelY = accel.Y;
            newSense.AccelZ = accel.Z;

            // Calculate Gyro Vectors (no need for this right now)
            newSense.RotX = 0;
            newSense.RotY = 0;
            newSense.RotZ = 0;

            // Calculate Barometric Pressure (deltaH?)
            newSense.BarometricPressure = sensorPackage.BarometricPressure + 0.1f;
            return(newSense);
        }
Example #3
0
        private async Task <bool> UpdateSecret(Sensor sensor, SensorUpdate update)
        {
            ApiKey key = null;

            if (!string.IsNullOrEmpty(update.Secret))
            {
                key = await this.m_keys.GetAsync(update.Secret).ConfigureAwait(false);
            }

            if (key != null)
            {
                return(false);                /* Key already exists */
            }

            var old = await this.m_keys.GetAsync(sensor.Secret).ConfigureAwait(false);

            var oldSecret = sensor.Secret;

            sensor.Secret = string.IsNullOrEmpty(update.Secret) ? NextStringWithSymbols(this.m_rng, SensorSecretLength) : update.Secret;

            await Task.WhenAll(
                this.m_mqtt.PublishCommandAsync(CommandType.FlushSensor, sensor.InternalId.ToString()),
                this.m_mqtt.PublishCommandAsync(CommandType.FlushKey, oldSecret)
                ).ConfigureAwait(false);

            var cache = this.m_cache.RemoveAsync(this.GenerateCacheKey(null, 0, 10, true));
            await Task.WhenAll(
                this.m_keys.UpdateAsync(old.Key, sensor.Secret),
                this.m_sensors.UpdateSecretAsync(sensor.InternalId, sensor.Secret),
                cache
                ).ConfigureAwait(false);

            return(true);
        }
Example #4
0
        public async Task <IActionResult> Put(string id, [FromBody] SensorUpdate update)
        {
            Sensor sensor;

            if (!ObjectId.TryParse(id, out _))
            {
                var response = new Response <string>();

                response.AddError("Unable to parse sensor ID");
                return(this.UnprocessableEntity(response));
            }

            sensor = await this.m_sensors.GetAsync(id).ConfigureAwait(false);

            if (!await this.AuthenticateUserForSensor(sensor, false).ConfigureAwait(false))
            {
                return(this.Forbidden());
            }

            if (sensor == null)
            {
                return(this.NotFound());
            }

            ApplyUpdate(sensor, update);
            await this.m_mqtt.PublishCommandAsync(CommandType.FlushSensor, sensor.InternalId.ToString()).ConfigureAwait(false);

            var cache    = this.m_cache.RemoveAsync(this.GenerateCacheKey(null, 0, 10, true));
            var sensordb = this.m_sensors.UpdateAsync(sensor);
            await Task.WhenAll(cache, sensordb).ConfigureAwait(false);

            await this.m_mqtt.PublishCommandAsync(CommandType.AddSensor, sensor.InternalId.ToString()).ConfigureAwait(false);

            return(this.Ok(new Response <Sensor>(sensor)));
        }
Example #5
0
 private static void Run()
 {
     rocket = new RocketController();
     DefaultMakeRocket();
     simRocket      = rocketCreation();
     currentControl = InitializeControlOutput();
     sensorPackage  = InitialSensorReadings();
     while (rocket.GetFlightStatus() != FlightState.MISSION_ENDED)
     {
         sensorPackage  = GetDynamics();
         currentControl = rocket.Tick(sensorPackage);
     }
 }
Example #6
0
        private static void ApplyUpdate(Sensor sensor, SensorUpdate update)
        {
            if (!string.IsNullOrEmpty(update.Name))
            {
                sensor.Name = update.Name;
            }

            if (!string.IsNullOrEmpty(update.Description))
            {
                sensor.Description = update.Description;
            }

            if (update.StorageEnabled.HasValue)
            {
                sensor.StorageEnabled = update.StorageEnabled.Value;
            }
        }
Example #7
0
        public async Task <IActionResult> PutSecret(string id, [FromBody] SensorUpdate update)
        {
            Sensor sensor;

            update ??= new SensorUpdate();

            if (!ObjectId.TryParse(id, out _))
            {
                var response = new Response <string>();

                response.AddError("Unable to parse sensor ID");
                return(this.UnprocessableEntity(response));
            }

            sensor = await this.m_sensors.GetAsync(id).ConfigureAwait(false);

            if (!await this.AuthenticateUserForSensor(sensor, false).ConfigureAwait(false))
            {
                return(this.Forbidden());
            }

            if (sensor == null)
            {
                return(this.NotFound());
            }

            var success = await this.UpdateSecret(sensor, update).ConfigureAwait(false);

            if (!success)
            {
                var resp = new Response <string>();

                resp.AddError("Unable to update sensor secret.");
                return(this.BadRequest(resp));
            }

            ApplyUpdate(sensor, update);
            await this.m_sensors.UpdateAsync(sensor).ConfigureAwait(false);             /* Update other settings */

            await Task.WhenAll(this.m_mqtt.PublishCommandAsync(CommandType.AddKey, sensor.Secret),
                               this.m_mqtt.PublishCommandAsync(CommandType.AddSensor, sensor.InternalId.ToString())
                               ).ConfigureAwait(false);

            return(this.Ok(new Response <Sensor>(sensor)));
        }
Example #8
0
 public Vector3D <float> Tick(SensorUpdate sensors, FlightState flightState)
 {
     return(new Vector3D <float>());
 }
Example #9
0
 public byte HandleDescent(SensorUpdate sensors)
 {
     return(0x00);
 }
 public FlightState Tick(SensorUpdate sensors)
 {
     FlightStatus += 1;
     return(FlightStatus);
 }