Skip to content

Commit

Permalink
Merge pull request #42 from joshreed13/develop
Browse files Browse the repository at this point in the history
URC 2016 Modifications
  • Loading branch information
joshreed13 authored Oct 14, 2016
2 parents a68fbff + 0ce1a96 commit 7c00e2e
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 10 deletions.
1 change: 1 addition & 0 deletions RED/Models/ArmControllerModeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ internal class ArmControllerModeModel
internal float AngleJ4;
internal float AngleJ5;
internal float AngleJ6;
internal int EndeffectorSpeedLimit = 500;
}
}
1 change: 1 addition & 0 deletions RED/Models/ControlCenterModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public class ControlCenterModel
internal DropBaysViewModel _dropBays;
internal PowerViewModel _power;
internal CameraMuxViewModel _cameraMux;
internal ExternalControlsViewModel _externalControls;
}
}
3 changes: 3 additions & 0 deletions RED/Models/ScienceModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -20,5 +21,7 @@ internal class ScienceModel
internal System.Net.IPAddress CCDIPAddress;
internal ushort CCDPortNumber;
internal string CCDFilePath = Environment.CurrentDirectory;

internal Stream SensorDataFile;
}
}
8 changes: 8 additions & 0 deletions RED/RED.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<Compile Include="Models\XboxControllerInputModel.cs" />
<Compile Include="ViewModels\ControlCenter\ArmControllerModeViewModel.cs" />
<Compile Include="ViewModels\ControlCenter\CameraMuxViewModel.cs" />
<Compile Include="ViewModels\ControlCenter\ExternalControlsViewModel.cs" />
<Compile Include="ViewModels\ControlCenter\GimbalControllerModeViewModel.cs" />
<Compile Include="ViewModels\ControlCenter\DropBaysViewModel.cs" />
<Compile Include="ViewModels\ControlCenter\NetworkManagerViewModel.cs" />
Expand Down Expand Up @@ -176,6 +177,9 @@
<Compile Include="Views\ControlCenter\DriveControllerModeView.xaml.cs">
<DependentUpon>DriveControllerModeView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ControlCenter\ExternalControlsView.xaml.cs">
<DependentUpon>ExternalControlsView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ControlCenter\GimbalControllerModeView.xaml.cs">
<DependentUpon>GimbalControllerModeView.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -225,6 +229,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ControlCenter\ExternalControlsView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ControlCenter\GimbalControllerModeView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
30 changes: 26 additions & 4 deletions RED/ViewModels/ControlCenter/ArmControllerModeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ArmControllerModeViewModel : PropertyChangedBase, IControllerMode,

private const short motorRangeFactor = 1000;
private readonly EndEffectorModes[] AvailibleEndEffectorModes = { EndEffectorModes.Gripper, EndEffectorModes.Drill, EndEffectorModes.RegulatorDetach };
private readonly string[] EndEffectorModeNames = { "Gripper", "Drill", "Regulator Detachment" };

private readonly ArmControllerModeModel _model;
private readonly ControlCenterViewModel _controlCenter;
Expand All @@ -38,6 +39,14 @@ public int CurrentEndEffectorMode
{
_model.CurrentEndEffectorMode = value;
NotifyOfPropertyChange(() => CurrentEndEffectorMode);
NotifyOfPropertyChange(() => CurrentEndEffectorModeName);
}
}
public string CurrentEndEffectorModeName
{
get
{
return EndEffectorModeNames[CurrentEndEffectorMode];
}
}

Expand Down Expand Up @@ -114,6 +123,19 @@ public float AngleJ6
}
}

public int EndeffectorSpeedLimit
{
get
{
return _model.EndeffectorSpeedLimit;
}
set
{
_model.EndeffectorSpeedLimit = value;
NotifyOfPropertyChange(() => EndeffectorSpeedLimit);
}
}

public ArmControllerModeViewModel(IInputDevice inputVM, ControlCenterViewModel cc)
{
_model = new ArmControllerModeModel();
Expand Down Expand Up @@ -199,9 +221,9 @@ public void EvaluateMode()
{
case EndEffectorModes.Gripper:
if (InputVM.GripperClose > 0)
_controlCenter.DataRouter.Send(_controlCenter.MetadataManager.GetId("Gripper"), (Int16)(InputVM.GripperClose * motorRangeFactor));
_controlCenter.DataRouter.Send(_controlCenter.MetadataManager.GetId("Gripper"), (Int16)(InputVM.GripperClose * EndeffectorSpeedLimit));
else if (InputVM.GripperOpen > 0)
_controlCenter.DataRouter.Send(_controlCenter.MetadataManager.GetId("Gripper"), (Int16)(-InputVM.GripperOpen * motorRangeFactor));
_controlCenter.DataRouter.Send(_controlCenter.MetadataManager.GetId("Gripper"), (Int16)(-InputVM.GripperOpen * EndeffectorSpeedLimit));
else
_controlCenter.DataRouter.Send(_controlCenter.MetadataManager.GetId("Gripper"), (Int16)(0));
break;
Expand All @@ -216,9 +238,9 @@ public void EvaluateMode()

case EndEffectorModes.RegulatorDetach:
if (InputVM.GripperClose > 0)
_controlCenter.DataRouter.Send(_controlCenter.MetadataManager.GetId("Gripper"), (Int16)(InputVM.GripperClose * motorRangeFactor));
_controlCenter.DataRouter.Send(_controlCenter.MetadataManager.GetId("Gripper"), (Int16)(InputVM.GripperClose * EndeffectorSpeedLimit));
else if (InputVM.GripperOpen > 0)
_controlCenter.DataRouter.Send(_controlCenter.MetadataManager.GetId("Gripper"), (Int16)(-InputVM.GripperOpen * motorRangeFactor));
_controlCenter.DataRouter.Send(_controlCenter.MetadataManager.GetId("Gripper"), (Int16)(-InputVM.GripperOpen * EndeffectorSpeedLimit));
else
_controlCenter.DataRouter.Send(_controlCenter.MetadataManager.GetId("Gripper"), (Int16)(0));

Expand Down
30 changes: 30 additions & 0 deletions RED/ViewModels/ControlCenter/ExternalControlsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RED.ViewModels.ControlCenter
{
public class ExternalControlsViewModel
{
private ControlCenterViewModel _cc;

private const byte GimbalDisableCommand = 0x00;
private const byte GimbalEnableCommand = 0x01;

public ExternalControlsViewModel(ControlCenterViewModel cc)
{
_cc = cc;
}

public void EnableAll()
{
_cc.DataRouter.Send(_cc.MetadataManager.GetId("GimbalEnableAll"), GimbalEnableCommand);
}
public void DisableAll()
{
_cc.DataRouter.Send(_cc.MetadataManager.GetId("GimbalEnableAll"), GimbalDisableCommand);
}
}
}
39 changes: 38 additions & 1 deletion RED/ViewModels/ControlCenter/ScienceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ public string CCDFilePath
}
}

public Stream SensorDataFile
{
get
{
return _model.SensorDataFile;
}
set
{
_model.SensorDataFile = value;
NotifyOfPropertyChange(() => SensorDataFile);
}
}

public ScienceViewModel(ControlCenterViewModel cc)
{
_model = new ScienceModel();
Expand Down Expand Up @@ -239,7 +252,7 @@ public void RequestCCD()
public async void DownloadCCD()
{
_cc.Console.WriteToConsole("CCD data downloaded started.");
string filename = Path.Combine(CCDFilePath, "REDCCDData" + DateTime.Now.ToString("s") + ".dat");
string filename = Path.Combine(CCDFilePath, "REDCCDData" + DateTime.Now.ToString("yyyyMMdd'T'HHmmss") + ".dat");
using (var client = new TcpClient())
{
await client.ConnectAsync(CCDIPAddress, CCDPortNumber);
Expand Down Expand Up @@ -295,33 +308,57 @@ public void FunnelClose()
_cc.DataRouter.Send(_cc.MetadataManager.GetId("ScienceCommand"), (byte)ScienceRequestTypes.FunnelClose);
}

public void SaveFileStart()
{
SensorDataFile = new FileStream("REDSensorData" + DateTime.Now.ToString("yyyyMMdd'T'HHmmss") + ".dat", FileMode.Create);
}
public void SaveFileStop()
{
if (SensorDataFile.CanWrite)
SensorDataFile.Close();
}
private async void SaveFileWrite(string sensorName, object value)
{
if (!SensorDataFile.CanWrite) return;
var data = Encoding.UTF8.GetBytes(String.Format("{0:s} {1} {2}{3}", DateTime.Now, sensorName, value.ToString(), Environment.NewLine));
await SensorDataFile.WriteAsync(data, 0, data.Length);
}

public void ReceiveFromRouter(ushort dataId, byte[] data)
{
switch (_cc.MetadataManager.GetTelemetry(dataId).Name)
{
case "Temperature1":
Temperature1Value = BitConverter.ToSingle(data, 0);
SaveFileWrite("Temperature1", Temperature1Value);
break;
case "Temperature2":
Temperature2Value = BitConverter.ToSingle(data, 0);
SaveFileWrite("Temperature2", Temperature2Value);
break;
case "Temperature3":
Temperature3Value = BitConverter.ToSingle(data, 0);
SaveFileWrite("Temperature3", Temperature3Value);
break;
case "Temperature4":
Temperature4Value = BitConverter.ToSingle(data, 0);
SaveFileWrite("Temperature4", Temperature4Value);
break;
case "Moisture1":
Moisture1Value = BitConverter.ToSingle(data, 0);
SaveFileWrite("Moisture1", Moisture1Value);
break;
case "Moisture2":
Moisture2Value = BitConverter.ToSingle(data, 0);
SaveFileWrite("Moisture2", Moisture2Value);
break;
case "Moisture3":
Moisture3Value = BitConverter.ToSingle(data, 0);
SaveFileWrite("Moisture3", Moisture3Value);
break;
case "Moisture4":
Moisture4Value = BitConverter.ToSingle(data, 0);
SaveFileWrite("Moisture4", Moisture4Value);
break;
}
}
Expand Down
13 changes: 13 additions & 0 deletions RED/ViewModels/ControlCenterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ public CameraMuxViewModel CameraMux
NotifyOfPropertyChange(() => CameraMux);
}
}
public ExternalControlsViewModel ExternalControls
{
get
{
return _model._externalControls;
}
set
{
_model._externalControls = value;
NotifyOfPropertyChange(() => ExternalControls);
}
}

public DriveControllerModeViewModel DriveControllerMode
{
Expand Down Expand Up @@ -242,6 +254,7 @@ public ControlCenterViewModel()
DropBays = new DropBaysViewModel(this);
Power = new PowerViewModel(this);
CameraMux = new CameraMuxViewModel(this);
ExternalControls = new ExternalControlsViewModel(this);

SettingsManager = new SettingsManagerViewModel(this);

Expand Down
6 changes: 5 additions & 1 deletion RED/Views/ControlCenter/ArmControllerModeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0">Current Endeffector Mode</Label>
<Label Grid.Row="0" Grid.Column="1" x:Name="CurrentEndEffectorMode" />
<Label Grid.Row="0" Grid.Column="1" x:Name="CurrentEndEffectorModeName" />
</Grid>
<DockPanel>
<Label x:Name="EndeffectorSpeedLimit" Width="40px" DockPanel.Dock="Right" HorizontalContentAlignment="Right" />
<Slider Minimum="0" Maximum="1000" Value="{Binding EndeffectorSpeedLimit}" Margin="3px" />
</DockPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
Expand Down
15 changes: 15 additions & 0 deletions RED/Views/ControlCenter/ExternalControlsView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<UserControl x:Class="RED.Views.ControlCenter.ExternalControlsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<DockPanel>
<Label DockPanel.Dock="Left">12V</Label>
<UniformGrid Rows="1">
<Button x:Name="EnableAll">Enable</Button>
<Button x:Name="DisableAll">Disable</Button>
</UniformGrid>
</DockPanel>
</UserControl>
28 changes: 28 additions & 0 deletions RED/Views/ControlCenter/ExternalControlsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace RED.Views.ControlCenter
{
/// <summary>
/// Interaction logic for ExternalControlsView.xaml
/// </summary>
public partial class ExternalControlsView : UserControl
{
public ExternalControlsView()
{
InitializeComponent();
}
}
}
6 changes: 6 additions & 0 deletions RED/Views/ControlCenter/ScienceView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
Expand Down Expand Up @@ -105,6 +106,11 @@
<Button x:Name="RequestCCD">Request</Button>
<Button x:Name="DownloadCCD">Download</Button>
</UniformGrid>
<Label Grid.Row="4" Grid.Column="0">Save</Label>
<UniformGrid Grid.Row="4" Grid.Column="1" Rows="1">
<Button x:Name="SaveFileStart">Start</Button>
<Button x:Name="SaveFileStop">Stop</Button>
</UniformGrid>
</Grid>

</StackPanel>
Expand Down
11 changes: 7 additions & 4 deletions RED/Views/ControlCenterView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@
<ContentControl x:Name="Sensor" />
</Expander>
<Expander Header="Gimbal">
<UniformGrid Rows="1">
<ContentControl x:Name="GimbalControllerMode" />
<ContentControl x:Name="Gimbal2ControllerMode" />
</UniformGrid>
<StackPanel>
<ContentControl x:Name="ExternalControls" />
<UniformGrid Rows="1">
<ContentControl x:Name="GimbalControllerMode" />
<ContentControl x:Name="Gimbal2ControllerMode" />
</UniformGrid>
</StackPanel>
</Expander>
<Expander Header="Drop Bays">
<ContentControl x:Name="DropBays" />
Expand Down

0 comments on commit 7c00e2e

Please sign in to comment.