Esempio n. 1
0
        private void loop()
        {
            try
            {
                while (!cancel && !finished && (LoopCheck._IsAutonomous() || LoopCheck._IsTeleoporated() || overrideSaftey))
                {
                    main();
                    Timer.Delay(cycleTime);
                }
            }
            catch (ThreadAbortException)
            {
                Report.General($"{GetType()} was forcefully aborted.");
            }

            if (cancel)
            {
                CancelationComplete?.Invoke(this, new EventArgs());
                Report.General($"{GetType()} was canceled.");
            }
            else
            {
                Finished?.Invoke(this, new EventArgs());
                Report.General($"{GetType()} ran to completion.");
            }
        }
 /// <summary>
 ///     Sends data to the dashboard
 /// </summary>
 /// <param name="key">network table key</param>
 /// <param name="value">double value to send</param>
 /// <param name="announcePeriod">should the key be prefixed with the current robot state? (auton/teleop)</param>
 public void SendData(string key, double value, bool announcePeriod = true)
 {
     if (LoopCheck._IsTeleoporated() && announcePeriod)
     {
         dashboardComm.PutNumber($"TELEOP_{key}", value);
     }
     else if (LoopCheck._IsAutonomous() && announcePeriod)
     {
         dashboardComm.PutNumber($"AUTON_{key}", value);
     }
     else
     {
         dashboardComm.PutNumber($"{key}", value);
     }
 }
 /// <summary>
 ///     Sends data to the dashboard
 /// </summary>
 /// <param name="key">network table key</param>
 /// <param name="value">double value to send</param>
 /// <param name="announcePeriod">should the key be prefixed with the current robot state? (auton/teleop)</param>
 public void SendData(string key, object value, bool announcePeriod = true)
 {
     if (LoopCheck._IsTeleoporated() && announcePeriod)
     {
         dashboardComm.PutValue($"TELEOP_{key}", Value.MakeValue(value));
     }
     else if (LoopCheck._IsAutonomous() && announcePeriod)
     {
         dashboardComm.PutValue($"AUTON_{key}", Value.MakeValue(value));
     }
     else
     {
         dashboardComm.PutValue($"{key}", Value.MakeValue(value));
     }
 }
Esempio n. 4
0
        private void VirtualControlEvent_ValueChanged(object sender, EventArgs e)
        {
            if ((!EnabledDuringAuton || !LoopCheck._IsAutonomous()) &&
                (!EnabledDuringTeleop || !LoopCheck._IsTeleoporated()))
            {
                return;
            }
            try
            {
                var param = e as VirtualControlEventArgs;

                if (param == null)
                {
                    return;
                }

                foreach (var component in actors)
                {
                    if (component.InUse)
                    {
                        continue;                  //skip if the component is in use
                    }
                    var actor = component;

                    if (EventType == VirtualControlEventType.Value &&
                        SetMethod == VirtualControlEventSetMethod.Passthrough)
                    {
                        (actor as Motor)?.Set(param.Value, this);
                        (actor as OutputComponent)?.Set(Math.Abs(param.Value), this);
                        (actor as DoubleSolenoidItem)?.Set(Math.Abs(param.Value), this);
                        (actor as RelayItem)?.Set((Relay.Value)Math.Abs(param.Value), this);
                    }
                    else if (EventType == VirtualControlEventType.Value &&
                             SetMethod == VirtualControlEventSetMethod.Adjusted)
                    {
                        if (sender is AnalogInputItem || sender is PotentiometerItem)
                        {
                            (actor as Motor)?.Set(param.Value / 5, this);
                            (actor as OutputComponent)?.Set(Math.Abs(param.Value), this);
                            (actor as DoubleSolenoidItem)?.Set(Math.Abs(param.Value), this);
                            (actor as RelayItem)?.Set((Relay.Value)Math.Abs(param.Value), this);
                        }
                        else if (sender is EncoderItem)
                        {
                            var tmp = (EncoderItem)sender;
                            (actor as Motor)?.Set(param.Value / ((Encoder)tmp.GetRawComponent()).EncodingScale, this);
                            (actor as OutputComponent)?.Set(
                                Math.Abs(param.Value / ((Encoder)tmp.GetRawComponent()).EncodingScale), this);
                            (actor as DoubleSolenoidItem)?.Set(
                                Math.Abs(param.Value / ((Encoder)tmp.GetRawComponent()).EncodingScale), this);
                            (actor as RelayItem)?.Set(
                                (Relay.Value)(Math.Abs(param.Value) / ((Encoder)tmp.GetRawComponent()).EncodingScale),
                                this);
                        }
                        else
                        {
                            (actor as Motor)?.Set(param.Value, this);
                            (actor as DigitalOutputItem)?.Set(param.Value, this);
                            (actor as AnalogOutputItem)?.Set(Math.Abs(param.Value) * 5, this);
                            (actor as DoubleSolenoidItem)?.Set(Math.Abs(param.Value), this);
                            (actor as RelayItem)?.Set((Relay.Value)Math.Abs(param.Value), this);
                        }
                    }
                    else if (EventType == VirtualControlEventType.Usage &&
                             SetMethod == VirtualControlEventSetMethod.Passthrough)
                    {
                        (actor as Motor)?.Set(Convert.ToDouble(param.InUse), this);
                        (actor as OutputComponent)?.Set(param.InUse, this);
                        (actor as DoubleSolenoidItem)?.Set(param.InUse, this);
                        (actor as RelayItem)?.Set((Relay.Value)Convert.ToDouble(param.InUse), this);
                    }
                    else
                    {
                        (actor as Motor)?.Set(Convert.ToDouble(param.InUse), this);
                        (actor as OutputComponent)?.Set(param.InUse, this);
                        (actor as DoubleSolenoidItem)?.Set(param.InUse, this);
                        (actor as RelayItem)?.Set((Relay.Value)Convert.ToDouble(param.InUse), this);
                    }
                }
            }
            catch (Exception ex)
            {
                Report.Error(ex.Message);
                Log.Write(ex);
            }
        }