Skip to content
Browse files

Updated input project

  • Loading branch information...
1 parent b962ac9 commit 452f1aa0fab6950b9f9c56276897a39bef52bcb8 @theone1984 theone1984 committed
Showing with 1,602 additions and 358 deletions.
  1. +1 −0 .gitignore
  2. +29 −0 ARDrone.sln
  3. +2 −1 ARDroneControlLibrary/ARDroneControl.cs
  4. +9 −6 ARDroneInput/ARDroneInput.csproj
  5. +2 −9 ARDroneInput/ButtonBasedInput.cs
  6. +20 −18 ARDroneInput/ConfigurableInput.cs
  7. +1 −1 ARDroneInput/GenericInput.cs
  8. +34 −0 ARDroneInput/InputConfigs/ButtonBasedInputConfig.cs
  9. +118 −0 ARDroneInput/InputConfigs/InputConfig.cs
  10. +41 −0 ARDroneInput/InputConfigs/SpeechBasedInputConfig.cs
  11. +12 −17 ARDroneInput/InputControls/ButtonBasedInputControl.cs
  12. +5 −4 ARDroneInput/InputControls/InputControl.cs
  13. +2 −0 ARDroneInput/InputControls/SpeechBasedInputControl.cs
  14. +7 −3 ARDroneInput/InputManager.cs
  15. +0 −5 ARDroneInput/InputMappings/ButtonBasedInputMapping.cs
  16. +9 −5 ARDroneInput/InputMappings/InputMapping.cs
  17. +177 −19 ARDroneInput/InputMappings/SpeechBasedInputMapping.cs
  18. +2 −1 ARDroneInput/InputMappings/ValidatedInputMapping.cs
  19. +2 −2 ARDroneInput/JoystickInput.cs
  20. +2 −1 ARDroneInput/KeyboardInput.cs
  21. +194 −0 ARDroneInput/Speech/SpeechRecognition.cs
  22. +121 −11 ARDroneInput/SpeechInput.cs
  23. +129 −0 ARDroneInput/Timing/TimeBasedCommand.cs
  24. +45 −0 ARDroneInput/Utility/InputFactory.cs
  25. +2 −1 ARDroneInput/WiimoteInput.cs
  26. +7 −53 ARDroneUI_WPF/ConfigInput.xaml
  27. +343 −201 ARDroneUI_WPF/ConfigInput.xaml.cs
  28. +66 −0 ARDrone_Testing/ARDrone_Testing.csproj
  29. +35 −0 ARDrone_Testing/Properties/AssemblyInfo.cs
  30. +81 −0 ARDrone_Testing/SpeechBasedInputMappingUnitTest.cs
  31. +73 −0 ARDrone_Testing/TimeBasedCommandUnitTest.cs
  32. +10 −0 Local.testsettings
  33. +21 −0 TraceAndTestImpact.testsettings
View
1 .gitignore
@@ -1,3 +1,4 @@
+TestResults
*.suo
*.sdf
*.ipch
View
29 ARDrone.sln
@@ -31,11 +31,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ARDroneInput", "ARDroneInpu
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7885A062-281E-475D-AE00-54D56221F433}"
ProjectSection(SolutionItems) = preProject
+ ARDrone.vsmdi = ARDrone.vsmdi
GNU GPL.txt = GNU GPL.txt
LibraryLicenses.txt = LibraryLicenses.txt
+ Local.testsettings = Local.testsettings
ParrotCopyrightAndDisclaimer.txt = ParrotCopyrightAndDisclaimer.txt
ParrotLicense.txt = ParrotLicense.txt
Readme.txt = Readme.txt
+ TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ARDroneCapture", "ARDroneCapture\ARDroneCapture.csproj", "{DF44B163-A438-4DCC-ADB0-5CDB08803A0F}"
@@ -54,7 +57,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DirectionControl", "Directi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ARDroneInput_Speech", "ARDroneInput_Speech\ARDroneInput_Speech.csproj", "{BE4A76AB-FA50-4E6D-BE06-D2D9A528DBB2}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ARDrone_Testing", "ARDrone_Testing\ARDrone_Testing.csproj", "{EB016BB8-3E68-4DD7-B27E-317B18024FFA}"
+EndProject
Global
+ GlobalSection(TestCaseManagementSettings) = postSolution
+ CategoryFile = ARDrone.vsmdi
+ EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
@@ -388,6 +396,27 @@ Global
{BE4A76AB-FA50-4E6D-BE06-D2D9A528DBB2}.Release|Win32.ActiveCfg = Release|Any CPU
{BE4A76AB-FA50-4E6D-BE06-D2D9A528DBB2}.Release|x64.ActiveCfg = Release|Any CPU
{BE4A76AB-FA50-4E6D-BE06-D2D9A528DBB2}.Release|x86.ActiveCfg = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Debug|Win32.ActiveCfg = Debug|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Profile|Any CPU.ActiveCfg = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Profile|Any CPU.Build.0 = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Profile|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Profile|Mixed Platforms.Build.0 = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Profile|Win32.ActiveCfg = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Profile|x64.ActiveCfg = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Profile|x86.ActiveCfg = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Release|Win32.ActiveCfg = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Release|x64.ActiveCfg = Release|Any CPU
+ {EB016BB8-3E68-4DD7-B27E-317B18024FFA}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
3 ARDroneControlLibrary/ARDroneControl.cs
@@ -317,7 +317,8 @@ public DroneData GetCurrentDroneData()
if (isConnected)
{
- return new DroneData(GetDroneState(), GetBatteryLevel(), GetTheta(), GetPhi(), GetPsi(), GetAltitude(), GetVX(), GetVY(), GetVZ());
+ return new DroneData();
+ //return new DroneData(GetDroneState(), GetBatteryLevel(), GetTheta(), GetPhi(), GetPsi(), GetAltitude(), GetVX(), GetVY(), GetVZ());
}
else
{
View
15 ARDroneInput/ARDroneInput.csproj
@@ -47,6 +47,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
+ <Reference Include="System.Speech" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@@ -60,14 +61,22 @@
<Compile Include="ButtonBasedInput.cs" />
<Compile Include="ConfigurableInput.cs" />
<Compile Include="DirectInputInput.cs" />
+ <Compile Include="InputConfigs\ButtonBasedInputConfig.cs" />
+ <Compile Include="InputConfigs\InputConfig.cs" />
+ <Compile Include="InputConfigs\SpeechBasedInputConfig.cs" />
<Compile Include="InputControls\ButtonBasedInputControl.cs" />
+ <Compile Include="InputControls\SpeechBasedInputControl.cs" />
<Compile Include="InputMappings\ButtonBasedInputMapping.cs" />
+ <Compile Include="InputMappings\SpeechBasedInputMapping.cs" />
+ <Compile Include="Timing\TimeBasedCommand.cs" />
+ <Compile Include="Speech\SpeechRecognition.cs" />
<Compile Include="Utility\Events.cs" />
<Compile Include="GenericInput.cs" />
<Compile Include="InputManager.cs" />
<Compile Include="InputMappings\ValidatedInputMapping.cs" />
<Compile Include="InputControls\InputControl.cs" />
<Compile Include="InputMappings\InputMapping.cs" />
+ <Compile Include="Utility\InputFactory.cs" />
<Compile Include="Utility\InputState.cs" />
<Compile Include="JoystickInput.cs" />
<Compile Include="KeyboardInput.cs" />
@@ -76,12 +85,6 @@
<Compile Include="Utility\DictionarySerializer.cs" />
<Compile Include="WiimoteInput.cs" />
</ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\ARDroneInput_Speech\ARDroneInput_Speech.csproj">
- <Project>{BE4A76AB-FA50-4E6D-BE06-D2D9A528DBB2}</Project>
- <Name>ARDroneInput_Speech</Name>
- </ProjectReference>
- </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
11 ARDroneInput/ButtonBasedInput.cs
@@ -26,16 +26,9 @@ public abstract class ButtonBasedInput : ConfigurableInput
public ButtonBasedInput()
: base()
- {
-
- }
-
- protected override InputMapping GetMapping(List<String> validButtons, List<String> validAxes)
- {
- return new ButtonBasedInputMapping(validButtons, validAxes);
- }
+ { }
- public override void Init()
+ public override void InitDevice()
{
Dictionary<String, float> axisValues = GetAxisValues();
SetLastAxisValues(axisValues);
View
38 ARDroneInput/ConfigurableInput.cs
@@ -5,6 +5,7 @@
using System.Linq;
using System.Text;
using System.Xml.Serialization;
+using ARDrone.Input.InputConfigs;
using ARDrone.Input.InputControls;
using ARDrone.Input.InputMappings;
using ARDrone.Input.Utility;
@@ -16,10 +17,20 @@ public abstract class ConfigurableInput : GenericInput
protected InputMapping mapping = null;
protected InputMapping backupMapping = null;
+ protected InputConfig inputConfig = null;
+
public ConfigurableInput()
: base()
{
- SetDefaultMapping();
+ inputConfig = InputFactory.CreateConfigFor(this);
+ }
+
+ public void DetermineMapping()
+ {
+ mapping = GetStandardMapping();
+ LoadMapping();
+
+ backupMapping = mapping.Clone();
}
public void SetDefaultMapping()
@@ -34,17 +45,7 @@ public void CopyMappingFrom(ConfigurableInput input)
backupMapping = input.backupMapping.Clone();
}
- protected void CreateMapping(List<String> validButtons, List<String> validAxes)
- {
- if (!LoadMapping())
- {
- GetMapping(validButtons, validAxes);
- }
- backupMapping = mapping.Clone();
- }
-
protected abstract InputMapping GetStandardMapping();
- protected abstract InputMapping GetMapping(List<String> validButtons, List<String> validAxes);
public bool LoadMapping()
{
@@ -84,13 +85,6 @@ public void SaveMapping()
String mappingFilePath = GetMappingFilePath();
DictionarySerializer.Serialize(mapping.Controls.Mappings, mappingFilePath);
-
- //XmlSerializer serializer = new XmlSerializer(typeof(Dictionary<String, String>));
- //using (System.IO.TextWriter textWriter = new System.IO.StreamWriter(mappingFilePath))
- //{
- // serializer.Serialize(textWriter, mapping.Controls.Mappings);
- // textWriter.Close();
- //}
}
catch (Exception e)
{
@@ -129,5 +123,13 @@ public virtual String FilePrefix
{
get { return string.Empty; }
}
+
+ public InputConfig InputConfig
+ {
+ get
+ {
+ return inputConfig;
+ }
+ }
}
}
View
2 ARDroneInput/GenericInput.cs
@@ -15,7 +15,7 @@ namespace ARDrone.Input
{
public abstract class GenericInput
{
- public abstract void Init();
+ public abstract void InitDevice();
public abstract void Dispose();
public virtual void StartRawInput()
View
34 ARDroneInput/InputConfigs/ButtonBasedInputConfig.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using ARDrone.Input.InputControls;
+
+namespace ARDrone.Input.InputConfigs
+{
+ public class ButtonBasedInputConfig : InputConfig
+ {
+ public ButtonBasedInputConfig()
+ : base()
+ {
+ SetStates();
+ }
+
+ private void SetStates()
+ {
+ states.Add("leftHeader", new InputConfigHeader("Axes", InputConfigState.Position.LeftColumn, 0));
+ states.Add(ButtonBasedInputControl.RollAxisField, new InputValueConfigState("Roll", InputConfigState.Position.LeftColumn, 1, InputValueConfigState.Mode.DisableOnInput, InputControl.ControlType.ContinuousValue));
+ states.Add(ButtonBasedInputControl.PitchAxisField, new InputValueConfigState("Pitch", InputConfigState.Position.LeftColumn, 2, InputValueConfigState.Mode.DisableOnInput, InputControl.ControlType.ContinuousValue));
+ states.Add(ButtonBasedInputControl.YawAxisField, new InputValueConfigState("Yaw", InputConfigState.Position.LeftColumn, 3, InputValueConfigState.Mode.DisableOnInput, InputControl.ControlType.ContinuousValue));
+ states.Add(ButtonBasedInputControl.GazAxisField, new InputValueConfigState("Gaz", InputConfigState.Position.LeftColumn, 4, InputValueConfigState.Mode.DisableOnInput, InputControl.ControlType.ContinuousValue));
+
+ states.Add("rightHeader", new InputConfigHeader("Buttons", InputConfigState.Position.RightColumn, 0));
+ states.Add(ButtonBasedInputControl.CameraSwapButtonField, new InputValueConfigState("Change Camera", InputConfigState.Position.RightColumn, 1, InputValueConfigState.Mode.DisableOnInput, InputControl.ControlType.BooleanValue));
+ states.Add(ButtonBasedInputControl.TakeOffButtonField, new InputValueConfigState("Take Off", InputConfigState.Position.RightColumn, 2, InputValueConfigState.Mode.DisableOnInput, InputControl.ControlType.BooleanValue));
+ states.Add(ButtonBasedInputControl.LandButtonField, new InputValueConfigState("Land", InputConfigState.Position.RightColumn, 3, InputValueConfigState.Mode.DisableOnInput, InputControl.ControlType.BooleanValue));
+ states.Add(ButtonBasedInputControl.HoverButtonField, new InputValueConfigState("Hover", InputConfigState.Position.RightColumn, 4, InputValueConfigState.Mode.DisableOnInput, InputControl.ControlType.BooleanValue));
+ states.Add(ButtonBasedInputControl.EmergencyButtonField, new InputValueConfigState("Emergency", InputConfigState.Position.RightColumn, 5, InputValueConfigState.Mode.DisableOnInput, InputControl.ControlType.BooleanValue));
+ states.Add(ButtonBasedInputControl.FlatTrimButtonField, new InputValueConfigState("Flat Trim", InputConfigState.Position.RightColumn, 6, InputValueConfigState.Mode.DisableOnInput, InputControl.ControlType.BooleanValue));
+ states.Add(ButtonBasedInputControl.SpecialActionButtonField, new InputValueConfigState("Special Action", InputConfigState.Position.RightColumn, 7, InputValueConfigState.Mode.DisableOnInput, InputControl.ControlType.BooleanValue));
+ }
+ }
+}
View
118 ARDroneInput/InputConfigs/InputConfig.cs
@@ -0,0 +1,118 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using ARDrone.Input.InputControls;
+
+namespace ARDrone.Input.InputConfigs
+{
+ public class InputConfig
+ {
+ protected Dictionary<String, InputConfigState> states = new Dictionary<String, InputConfigState>();
+
+ private int GetMaxRowNumber()
+ {
+ int maxRowNumber = 0;
+ foreach (KeyValuePair<String, InputConfigState> entry in states)
+ {
+ if (entry.Value.RowNumber > maxRowNumber)
+ maxRowNumber = entry.Value.RowNumber;
+ }
+
+ return maxRowNumber;
+ }
+
+ public Dictionary<String, InputConfigState> States
+ {
+ get
+ {
+ return new Dictionary<String, InputConfigState>(states);
+ }
+ }
+
+ public int MaxRowNumber
+ {
+ get
+ {
+ return GetMaxRowNumber();
+ }
+ }
+ }
+
+ public abstract class InputConfigState
+ {
+ public enum Position { LeftColumn, RightColumn };
+
+ private Position layoutPosition;
+ private int rowNumber = 0;
+ private String name = "";
+
+ public InputConfigState(String name, Position layoutPosition, int rowNumber)
+ {
+ this.layoutPosition = layoutPosition;
+ this.rowNumber = rowNumber;
+ this.name = name;
+ }
+
+ public Position LayoutPosition
+ {
+ get
+ {
+ return layoutPosition;
+ }
+ }
+
+ public int RowNumber
+ {
+ get
+ {
+ return rowNumber;
+ }
+ }
+
+ public String Name
+ {
+ get
+ {
+ return name;
+ }
+ }
+ }
+
+ public class InputValueConfigState : InputConfigState
+ {
+ public enum Mode { DisableOnInput, DisableManually, DisableManuallyKeyboardAvailable };
+
+ private Mode inputMode;
+ private InputControl.ControlType inputValueType;
+
+ public InputValueConfigState(String name, Position layoutPosition, int rowNumber, Mode inputMode, InputControl.ControlType inputValueType)
+ : base(name, layoutPosition, rowNumber)
+ {
+ this.inputMode = inputMode;
+ this.inputValueType = inputValueType;
+ }
+
+ public Mode InputMode
+ {
+ get
+ {
+ return inputMode;
+ }
+ }
+
+ public InputControl.ControlType InputValueType
+ {
+ get
+ {
+ return inputValueType;
+ }
+ }
+ }
+
+ public class InputConfigHeader : InputConfigState
+ {
+ public InputConfigHeader(String name, Position layoutPosition, int rowNumber)
+ : base(name, layoutPosition, rowNumber)
+ { }
+ }
+}
View
41 ARDroneInput/InputConfigs/SpeechBasedInputConfig.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using ARDrone.Input.InputControls;
+
+namespace ARDrone.Input.InputConfigs
+{
+ class SpeechBasedInputConfig : InputConfig
+ {
+ public SpeechBasedInputConfig()
+ : base()
+ {
+ SetStates();
+ }
+
+ private void SetStates()
+ {
+ states.Add("leftHeader", new InputConfigHeader("Axes", InputConfigState.Position.LeftColumn, 0));
+ states.Add(SpeechBasedInputControl.RollLeftInputField, new InputValueConfigState("Roll Left", InputConfigState.Position.LeftColumn, 1, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.RollRightInputField, new InputValueConfigState("Roll Right", InputConfigState.Position.LeftColumn, 2, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.PitchForwardInputField, new InputValueConfigState("Pitch Forward", InputConfigState.Position.LeftColumn, 3, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.PitchBackwardInputField, new InputValueConfigState("Pitch Backward", InputConfigState.Position.LeftColumn, 4, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.YawLeftInputField, new InputValueConfigState("Yaw Left", InputConfigState.Position.LeftColumn, 5, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.YawRightInputField, new InputValueConfigState("Yaw Right", InputConfigState.Position.LeftColumn, 6, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.GazUpInputField, new InputValueConfigState("Gaz Up", InputConfigState.Position.LeftColumn, 7, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.GazDownInputField, new InputValueConfigState("Gaz Down", InputConfigState.Position.LeftColumn, 8, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+
+ states.Add(SpeechBasedInputControl.TickInputField, new InputValueConfigState("Tick Word", InputConfigState.Position.LeftColumn, 9, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.TicksInputField, new InputValueConfigState("Tick Words", InputConfigState.Position.LeftColumn, 10, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+
+ states.Add("rightHeader", new InputConfigHeader("Buttons", InputConfigState.Position.RightColumn, 0));
+ states.Add(SpeechBasedInputControl.CameraSwapInputField, new InputValueConfigState("Change Camera", InputConfigState.Position.RightColumn, 1, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.TakeOffInputField, new InputValueConfigState("Take Off", InputConfigState.Position.RightColumn, 2, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.LandInputField, new InputValueConfigState("Land", InputConfigState.Position.RightColumn, 3, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.HoverInputField, new InputValueConfigState("Hover", InputConfigState.Position.RightColumn, 4, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.EmergencyInputField, new InputValueConfigState("Emergency", InputConfigState.Position.RightColumn, 5, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.FlatTrimInputField, new InputValueConfigState("Flat Trim", InputConfigState.Position.RightColumn, 6, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ states.Add(SpeechBasedInputControl.SpecialActionInputField, new InputValueConfigState("Special Action", InputConfigState.Position.RightColumn, 7, InputValueConfigState.Mode.DisableManuallyKeyboardAvailable, InputControl.ControlType.BooleanValue));
+ }
+ }
+}
View
29 ARDroneInput/InputControls/ButtonBasedInputControl.cs
@@ -36,24 +36,19 @@ private void InitControlTypeMap()
{
controlTypeMap = new Dictionary<String, ControlType>()
{
- { RollAxisField, ControlType.ContinuousValue},
- { PitchAxisField, ControlType.ContinuousValue},
- { YawAxisField, ControlType.ContinuousValue},
- { GazAxisField, ControlType.ContinuousValue},
-
- { CameraSwapButtonField, ControlType.BooleanValue},
- { TakeOffButtonField, ControlType.BooleanValue},
- { LandButtonField, ControlType.BooleanValue},
- { HoverButtonField, ControlType.BooleanValue},
- { EmergencyButtonField, ControlType.BooleanValue},
- { FlatTrimButtonField, ControlType.BooleanValue},
- { SpecialActionButtonField, ControlType.BooleanValue}
+ { RollAxisField, ControlType.ContinuousValue },
+ { PitchAxisField, ControlType.ContinuousValue },
+ { YawAxisField, ControlType.ContinuousValue },
+ { GazAxisField, ControlType.ContinuousValue },
+
+ { CameraSwapButtonField, ControlType.BooleanValue },
+ { TakeOffButtonField, ControlType.BooleanValue },
+ { LandButtonField, ControlType.BooleanValue },
+ { HoverButtonField, ControlType.BooleanValue },
+ { EmergencyButtonField, ControlType.BooleanValue },
+ { FlatTrimButtonField, ControlType.BooleanValue },
+ { SpecialActionButtonField, ControlType.BooleanValue }
};
}
-
- public override InputControl Clone()
- {
- return new ButtonBasedInputControl(mappings);
- }
}
}
View
9 ARDroneInput/InputControls/InputControl.cs
@@ -8,7 +8,7 @@ namespace ARDrone.Input.InputControls
{
public abstract class InputControl
{
- protected enum ControlType { BooleanValue, ContinuousValue }
+ public enum ControlType { BooleanValue, ContinuousValue }
protected Dictionary<String, ControlType> controlTypeMap = new Dictionary<String, ControlType>();
protected Dictionary<String, String> mappings;
@@ -34,7 +34,10 @@ public void SetProperty(String name, String value)
public String GetProperty(String name)
{
CheckPropertyName(name);
- return mappings[name];
+ if (mappings.ContainsKey(name))
+ return mappings[name];
+
+ return null;
}
private void CheckPropertyName(String name)
@@ -53,8 +56,6 @@ public bool IsBooleanMapping(String name)
return controlTypeMap[name] == ControlType.BooleanValue;
}
- public abstract InputControl Clone();
-
public Dictionary<String, String> Mappings
{
get
View
2 ARDroneInput/InputControls/SpeechBasedInputControl.cs
@@ -17,6 +17,7 @@ public class SpeechBasedInputControl : InputControl
public const String GazUpInputField = "GazUp";
public const String TickInputField = "Tick";
+ public const String TicksInputField = "Ticks";
public const String CameraSwapInputField = "CameraSwapButton";
public const String TakeOffInputField = "TakeOffButton";
@@ -51,6 +52,7 @@ private void InitControlTypeMap()
{ GazDownInputField, ControlType.BooleanValue },
{ GazUpInputField, ControlType.BooleanValue },
{ TickInputField, ControlType.BooleanValue },
+ { TicksInputField, ControlType.BooleanValue },
{ CameraSwapInputField, ControlType.BooleanValue },
{ TakeOffInputField, ControlType.BooleanValue },
{ LandInputField, ControlType.BooleanValue },
View
10 ARDroneInput/InputManager.cs
@@ -34,7 +34,7 @@ public enum InputMode { RawInput, ControlInput, NoInput };
private Thread inputThread = null;
private bool inputThreadEnded = false;
- private InputMode currentInputMode = InputMode.ControlInput;
+ private InputMode currentInputMode = InputMode.NoInput;
private String currentDeviceIdToListenTo = AllDevices;
private InputMode desiredInputMode = InputMode.ControlInput;
@@ -94,6 +94,8 @@ private void DeleteLostDevices()
{
if (!inputDevices[i].IsDevicePresent)
{
+ Console.WriteLine("Lost device " + inputDevices[i].DeviceName);
+
try
{
inputDevices[i].Dispose();
@@ -103,6 +105,8 @@ private void DeleteLostDevices()
String deviceId = inputDevices[i].DeviceInstanceId;
inputDevices.RemoveAt(i);
+
+
InvokeInputDeviceLostEvent(deviceId);
}
}
@@ -142,7 +146,7 @@ private void AddInputDevice(GenericInput input)
for (int i = 0; i < inputDevices.Count; i++)
{
- if (inputDevices[i].GetType() == typeof(JoystickInput))
+ if (inputDevices[i].GetType() == typeToSearchFor)
{
Console.WriteLine("Added " + input.DeviceName + " at position " + i);
@@ -157,7 +161,7 @@ private void AddInputDevice(GenericInput input)
private void InitInputDevice(GenericInput input)
{
- input.Init();
+ input.InitDevice();
InvokeNewInputDeviceEvent(input.DeviceInstanceId, input);
}
View
5 ARDroneInput/InputMappings/ButtonBasedInputMapping.cs
@@ -21,11 +21,6 @@ public override InputMapping Clone()
return clonedMapping;
}
- protected override InputControl CreateInputControlFromMappings(Dictionary<String, String> mappings)
- {
- return new ButtonBasedInputControl(mappings);
- }
-
public void SetAxisMappings(Object rollAxisMapping, Object pitchAxisMapping, Object yawAxisMapping, Object gazAxisMapping)
{
controls.SetProperty(ButtonBasedInputControl.RollAxisField, rollAxisMapping.ToString());
View
14 ARDroneInput/InputMappings/InputMapping.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using ARDrone.Input.InputControls;
+using ARDrone.Input.Utility;
namespace ARDrone.Input.InputMappings
{
@@ -31,16 +32,14 @@ public void CopyMappingsFrom(InputControl controls)
public void CopyMappingsFrom(Dictionary<String, String> mappings)
{
- InputControl controls = CreateInputControlFromMappings(mappings);
+ InputControl controls = InputFactory.CreateInputControlFromMappings(mappings, this);
SetControls(controls);
}
- protected abstract InputControl CreateInputControlFromMappings(Dictionary<String, String> mappings);
-
private void SetControls(InputControl controls)
{
CheckControls(controls);
- this.controls = controls.Clone();
+ this.controls = InputFactory.CloneInputControls(controls);
}
protected virtual void CheckControls(InputControl controls)
@@ -51,11 +50,16 @@ protected virtual void CheckControls(InputControl controls)
}
}
+ public void SetControlProperty(String name, String value)
+ {
+ controls.SetProperty(name, value);
+ }
+
public InputControl Controls
{
get
{
- return controls.Clone();
+ return InputFactory.CloneInputControls(controls);
}
}
}
View
196 ARDroneInput/InputMappings/SpeechBasedInputMapping.cs
@@ -2,14 +2,20 @@
using System.Collections.Generic;
using System.Text;
using ARDrone.Input.InputControls;
+using System.Text.RegularExpressions;
namespace ARDrone.Input.InputMappings
{
public class SpeechBasedInputMapping : InputMapping
{
+ public const int SimpleCommandDuration = 400;
+ public const int TickDuration = 2000;
+
public SpeechBasedInputMapping()
: base()
- { }
+ {
+ this.controls = new SpeechBasedInputControl();
+ }
private SpeechBasedInputMapping(InputControl controls)
: base(controls)
@@ -21,96 +27,248 @@ public override InputMapping Clone()
return clonedMapping;
}
- protected override InputControl CreateInputControlFromMappings(Dictionary<String, String> mappings)
+ public void SetAxisLikeMappingValues(String rollLeftInputMapping, String rollRightInputMapping, String pitchForwardInputMapping, String pitchBackwardInputMapping,
+ String yawLeftInputMapping, String yawRightInputMapping, String gazUpInputMapping, String gazDownInputMapping,
+ String tickInputMapping, String ticksInputMapping)
+ {
+ RollLeftInputMapping = rollLeftInputMapping;
+ RollRightInputMapping = rollRightInputMapping;
+ PitchForwardInputMapping = pitchForwardInputMapping;
+ PitchBackwardInputMapping = pitchBackwardInputMapping;
+
+ YawLeftInputMapping = yawLeftInputMapping;
+ YawRightInputMapping = yawRightInputMapping;
+ GazUpInputMapping = gazUpInputMapping;
+ GazDownInputMapping = gazDownInputMapping;
+
+ TickInputMapping = tickInputMapping;
+ TicksInputMapping = ticksInputMapping;
+ }
+
+ public void SetButtonLikeMappingValues(String takeOffInputMapping, String landInputMapping, String hoverInputMapping, String emergencyInputMapping, String flatTrimInputMapping, String cameraSwapInputMapping, String specialActionInputMapping)
+ {
+ TakeOffInputMapping = takeOffInputMapping;
+ LandInputMapping = landInputMapping;
+ HoverInputMapping = hoverInputMapping;
+ EmergencyInputMapping = emergencyInputMapping;
+ FlatTrimInputMapping = flatTrimInputMapping;
+ CameraSwapInputMapping = cameraSwapInputMapping;
+ SpecialActionInputMapping = specialActionInputMapping;
+ }
+
+ public List<String> GetNumberValues(int startNumber, int endNumber)
+ {
+ List<String> numberValues = new List<String>();
+ for (int i = startNumber; i <= endNumber; i++)
+ numberValues.Add(i.ToString());
+
+ return numberValues;
+ }
+
+ public List<String> GetDirectionMappingValues()
+ {
+ return GetListFrom(RollLeftInputMapping, RollRightInputMapping, PitchForwardInputMapping, PitchBackwardInputMapping,
+ YawLeftInputMapping, YawRightInputMapping, GazUpInputMapping, GazDownInputMapping);
+ }
+
+ public List<String> GetSimpleCommandMappingValues()
+ {
+ return GetListFrom(TakeOffInputMapping, LandInputMapping, HoverInputMapping,
+ EmergencyInputMapping, FlatTrimInputMapping, SpecialActionInputMapping);
+ }
+
+ private List<String> GetListFrom(params String[] verbs)
+ {
+ List<String> list = new List<String>();
+
+ foreach (String verb in verbs)
+ {
+ if (verb != null && verb != "")
+ list.Add(verb);
+ }
+
+ return list;
+ }
+
+ public void ExtractCommandFromSentence(String commandSentence, out String command, out int duration)
+ {
+ // Parsing "(<Number> ([<TickWord>|<TicksWord>])?)? <Command> | <Command>"
+
+ String whiteSpaces = "(\\s)+";
+ String directionPattern = GetNumberAlternatives() + "(" + whiteSpaces + GetTickAlternatives() + ")?" + whiteSpaces + GetDirectionAlternatives();
+
+ Regex regex = new Regex(directionPattern, RegexOptions.IgnoreCase);
+ Match match = regex.Match(commandSentence);
+
+ if (match.Success)
+ {
+ int tickNumber = Int32.Parse(match.Groups[1].Value);
+ String directionValue = match.Groups[6].Value;
+
+ duration = tickNumber * TickDuration;
+ command = GetDirectionCommandValue(directionValue);
+ }
+ else if (GetSimpleCommandValue(commandSentence) != null)
+ {
+ command = GetSimpleCommandValue(commandSentence);
+ duration = SimpleCommandDuration;
+ }
+ else
+ {
+ command = null;
+ duration = 0;
+ }
+ }
+
+ private String GetNumberAlternatives()
+ {
+ List<String> numberValues = GetNumberValues(1, 9);
+ return CreateAlternateGroupFromList(numberValues);
+ }
+
+ private String GetTickAlternatives()
+ {
+ List<String> tickValues = new List<String>(new String[] { TickInputMapping, TicksInputMapping });
+ return CreateAlternateGroupFromList(tickValues);
+ }
+
+ private String GetDirectionAlternatives()
+ {
+ List<String> directionValues = GetDirectionMappingValues();
+ return CreateAlternateGroupFromList(directionValues);
+ }
+
+ private String GetDirectionCommandValue(String command)
+ {
+ List<String> commandValues = GetDirectionMappingValues();
+ String resultingCommand = commandValues.Find(delegate(String value) { return value.ToLower() == command.ToLower(); });
+
+ return resultingCommand;
+ }
+
+ private String GetSimpleCommandValue(String commandSentence)
+ {
+ List<String> commandValues = GetSimpleCommandMappingValues();
+ String resultingCommand = commandValues.Find(delegate(String value) { return value.ToLower() == commandSentence.ToLower(); });
+
+ return resultingCommand;
+ }
+
+ private String CreateAlternateGroupFromList(List<String> values)
{
- return new SpeechBasedInputControl(mappings);
+ if (values == null || values.Count == 0)
+ return "";
+
+ String regex = "(";
+ for (int i = 0; i < values.Count; i++)
+ {
+ if (i != 0)
+ regex += "|";
+
+ regex += values[i];
+ }
+ regex += ")";
+
+ return regex;
}
- public String RollLeftInput
+ public String RollLeftInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.RollLeftInputField); }
set { controls.SetProperty(SpeechBasedInputControl.RollLeftInputField, value); }
}
- public String RollRightInput
+ public String RollRightInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.RollRightInputField); }
set { controls.SetProperty(SpeechBasedInputControl.RollRightInputField, value); }
}
- public String PitchForwardInput
+ public String PitchForwardInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.PitchForwardInputField); }
set { controls.SetProperty(SpeechBasedInputControl.PitchForwardInputField, value); }
}
- public String PitchBackwardInput
+ public String PitchBackwardInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.PitchBackwardInputField); }
set { controls.SetProperty(SpeechBasedInputControl.PitchBackwardInputField, value); }
}
- public String YawLeftInput
+ public String YawLeftInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.YawLeftInputField); }
set { controls.SetProperty(SpeechBasedInputControl.YawLeftInputField, value); }
}
- public String YawRightInput
+ public String YawRightInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.YawRightInputField); }
set { controls.SetProperty(SpeechBasedInputControl.YawRightInputField, value); }
}
- public String GazUpInput
+ public String GazUpInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.GazUpInputField); }
set { controls.SetProperty(SpeechBasedInputControl.GazUpInputField, value); }
}
- public String GazDownInput
+ public String GazDownInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.GazDownInputField); }
set { controls.SetProperty(SpeechBasedInputControl.GazDownInputField, value); }
}
- public String CameraSwapInput
+ public String TickInputMapping
+ {
+ get { return controls.GetProperty(SpeechBasedInputControl.TickInputField); }
+ set { controls.SetProperty(SpeechBasedInputControl.TickInputField, value); }
+ }
+
+ public String TicksInputMapping
+ {
+ get { return controls.GetProperty(SpeechBasedInputControl.TicksInputField); }
+ set { controls.SetProperty(SpeechBasedInputControl.TicksInputField, value); }
+ }
+
+ public String CameraSwapInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.CameraSwapInputField); }
set { controls.SetProperty(SpeechBasedInputControl.CameraSwapInputField, value); }
}
- public String TakeOffInput
+ public String TakeOffInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.TakeOffInputField); }
set { controls.SetProperty(SpeechBasedInputControl.TakeOffInputField, value); }
}
- public String LandInput
+ public String LandInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.LandInputField); }
set { controls.SetProperty(SpeechBasedInputControl.LandInputField, value); }
}
- public String HoverInput
+ public String HoverInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.HoverInputField); }
set { controls.SetProperty(SpeechBasedInputControl.HoverInputField, value); }
}
- public String EmergencyInput
+ public String EmergencyInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.EmergencyInputField); }
set { controls.SetProperty(SpeechBasedInputControl.EmergencyInputField, value); }
}
- public String FlatTrimInput
+ public String FlatTrimInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.FlatTrimInputField); }
set { controls.SetProperty(SpeechBasedInputControl.FlatTrimInputField, value); }
}
- public String SpecialActionInput
+ public String SpecialActionInputMapping
{
get { return controls.GetProperty(SpeechBasedInputControl.SpecialActionInputField); }
set { controls.SetProperty(SpeechBasedInputControl.SpecialActionInputField, value); }
@@ -124,4 +282,4 @@ private SpeechBasedInputControl SpeechControls
}
}
}
-}
+}
View
3 ARDroneInput/InputMappings/ValidatedInputMapping.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using ARDrone.Input.InputControls;
+using ARDrone.Input.Utility;
namespace ARDrone.Input.InputMappings
{
@@ -45,7 +46,7 @@ private void InitializeValidation(List<String> validBooleanInputValues, List<Str
private void InitializeControls(InputControl controls)
{
CheckControls(controls);
- this.controls = controls.Clone();
+ this.controls = InputFactory.CloneInputControls(controls);
}
public void CopyValidInputValuesFrom(ButtonBasedInputMapping mappingToCopyFrom)
View
4 ARDroneInput/JoystickInput.cs
@@ -62,7 +62,7 @@ public JoystickInput(Device device) : base()
{
this.device = device;
- CreateMapping(GetValidButtons(), GetValidAxes());
+ DetermineMapping();
}
protected override InputMapping GetStandardMapping()
@@ -133,7 +133,7 @@ public override List<String> GetPressedButtons()
public override Dictionary<String, float> GetAxisValues()
{
Dictionary<String, float> axisValues = new Dictionary<String, float>();
- axisValues[Axis.Axis_X.ToString()] = axisValues[Axis.Axis_Y.ToString()] =axisValues[Axis.Axis_Z.ToString()] = axisValues[Axis.Axis_R.ToString()] = 0.0f;
+ axisValues[Axis.Axis_X.ToString()] = axisValues[Axis.Axis_Y.ToString()] =axisValues[Axis.Axis_Z.ToString()] = axisValues[Axis.Axis_R.ToString()] = axisValues[Axis.Axis_POV_1.ToString()] = 0.0f;
try
{
View
3 ARDroneInput/KeyboardInput.cs
@@ -49,7 +49,8 @@ public static List<GenericInput> GetNewInputDevices(IntPtr windowHandle, List<Ge
public KeyboardInput(Device device) : base()
{
this.device = device;
- CreateMapping(GetValidButtons(), GetValidAxes());
+
+ DetermineMapping();
}
protected override InputMapping GetStandardMapping()
View
194 ARDroneInput/Speech/SpeechRecognition.cs
@@ -0,0 +1,194 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Speech.Recognition;
+using System.Speech.Recognition.SrgsGrammar;
+using System.Text;
+using ARDrone.Input.InputMappings;
+
+namespace ARDrone.Input.Speech
+{
+ public class SpeechRecognition
+ {
+ private const float speechRecognitionThreshold = 0.3f;
+
+ public delegate void SpeechRecognizedEventHandler(object sender, String recognizedExpression);
+ public event SpeechRecognizedEventHandler SpeechRecognized;
+
+ private SpeechRecognitionEngine speechRecognizer;
+ private SpeechInput speechInput;
+ private SpeechBasedInputMapping mapping;
+
+
+ Dictionary<String, SrgsRule> usedRules = new Dictionary<String, SrgsRule>();
+
+ public SpeechRecognition(SpeechInput speechInput)
+ {
+ if (speechInput.Mapping == null)
+ throw new Exception("The given mapping must not be null");
+
+ this.speechInput = speechInput;
+
+ InitSpeechRecognition();
+ }
+
+ private void InitSpeechRecognition()
+ {
+ speechRecognizer = new SpeechRecognitionEngine();
+ speechRecognizer.SetInputToDefaultAudioDevice();
+
+ speechRecognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(speechRecognizer_SpeechRecognized);
+ }
+
+ public void RecognizeMappingGrammar()
+ {
+ LoadGrammar(GetMappingGrammar());
+ speechRecognizer.RecognizeAsync(RecognizeMode.Multiple);
+ }
+
+ public void RecognizeUnrestrictedGrammar()
+ {
+ LoadGrammar(GetUnrestrictedGrammar());
+ speechRecognizer.RecognizeAsync(RecognizeMode.Multiple);
+ }
+
+ private void LoadGrammar(Grammar grammar)
+ {
+ EndSpeechRecognition();
+
+ speechRecognizer.UnloadAllGrammars();
+ speechRecognizer.LoadGrammar(grammar);
+ }
+
+ public void EndSpeechRecognition()
+ {
+ speechRecognizer.RecognizeAsyncStop();
+ }
+
+ private Grammar GetUnrestrictedGrammar()
+ {
+ return new DictationGrammar();
+ }
+
+ private Grammar GetMappingGrammar()
+ {
+ SrgsDocument document = new SrgsDocument();
+ mapping = (SpeechBasedInputMapping)speechInput.Mapping;
+
+ SrgsRule rootRule = GetRootRule();
+ rootRule.Scope = SrgsRuleScope.Public;
+
+ document.Root = rootRule;
+
+ foreach (KeyValuePair<String, SrgsRule> rule in usedRules)
+ {
+ document.Rules.Add(rule.Value);
+ }
+ usedRules.Clear();
+
+ return new Grammar(document);
+ }
+
+ private SrgsRule GetRootRule()
+ {
+ SrgsRule rootRule = new SrgsRule("rootRule");
+ usedRules.Add("rootRule", rootRule);
+
+ SrgsRule directionRules = GetDirectionRules();
+ SrgsRule simpleCommandsRule = GetSimpleCommandsRule();
+
+ SrgsOneOf oneOfElements = new SrgsOneOf(
+ new SrgsItem(new SrgsRuleRef(directionRules)),
+ new SrgsItem(new SrgsRuleRef(simpleCommandsRule))
+ );
+
+ rootRule.Add(oneOfElements);
+ return rootRule;
+ }
+
+ private SrgsRule GetDirectionRules()
+ {
+ SrgsRule directionRule = new SrgsRule("directionRule");
+ usedRules.Add("directionRule", directionRule);
+
+ List<String> oneTickNumberValues = mapping.GetNumberValues(1, 1);
+ List<String> multipleTicksNumberValues = mapping.GetNumberValues(2, 9);
+ List<String> directionValues = mapping.GetDirectionMappingValues();
+
+ SrgsRule oneTickGrammarRule = GetDirectionRule(oneTickNumberValues, mapping.TickInputMapping, directionValues, "oneTickRule");
+ SrgsRule multipleTicksGrammarRule = GetDirectionRule(multipleTicksNumberValues, mapping.TicksInputMapping, directionValues, "multipleTicksRule");
+
+ SrgsRule oneTickNoBindingWordGrammarRule = GetDirectionRule(oneTickNumberValues, null, directionValues, "oneTickRuleNoBindingWord");
+ SrgsRule multipleTicksNoBindingWordGrammarRule = GetDirectionRule(multipleTicksNumberValues, null, directionValues, "multipleTicksRuleNoBindingWord");
+
+ SrgsOneOf oneOfElements = new SrgsOneOf(
+ new SrgsItem(new SrgsRuleRef(oneTickGrammarRule)),
+ new SrgsItem(new SrgsRuleRef(multipleTicksGrammarRule)),
+ new SrgsItem(new SrgsRuleRef(oneTickNoBindingWordGrammarRule)),
+ new SrgsItem(new SrgsRuleRef(multipleTicksNoBindingWordGrammarRule))
+ );
+
+ directionRule.Add(oneOfElements);
+
+ return directionRule;
+ }
+
+ private SrgsRule GetDirectionRule(List<String> numberValues, String tickWord, List<String> directions, String ruleName)
+ {
+ SrgsRule rootRule = new SrgsRule(ruleName);
+ usedRules.Add(ruleName, rootRule);
+
+ String numberRuleName = ruleName + "_numberRule";
+ SrgsRule numberRule = GetRuleFromList(numberValues, numberRuleName);
+
+ String directionRuleName = ruleName + "_directionRules";
+ SrgsRule directionRule = GetRuleFromList(directions, directionRuleName);
+
+ rootRule.Elements.Add(new SrgsItem(new SrgsRuleRef(numberRule)));
+ if (tickWord != null)
+ rootRule.Elements.Add(new SrgsItem(tickWord));
+ rootRule.Elements.Add(new SrgsItem(new SrgsRuleRef(directionRule)));
+
+ return rootRule;
+ }
+
+ private SrgsRule GetSimpleCommandsRule()
+ {
+ List<String> simpleCommandValues = mapping.GetSimpleCommandMappingValues();
+ SrgsRule simpleCommandsRule = GetRuleFromList(simpleCommandValues, "simpleCommandsRule");
+
+ return simpleCommandsRule;
+ }
+
+ private SrgsRule GetRuleFromList(List<String> list, String ruleName)
+ {
+ SrgsOneOf oneOfElements = new SrgsOneOf();
+ foreach (String listEntry in list)
+ {
+ oneOfElements.Add(new SrgsItem(listEntry));
+ }
+
+ SrgsRule rule = new SrgsRule(ruleName, oneOfElements);
+ usedRules.Add(ruleName, rule);
+
+ return rule;
+ }
+
+ private void PerformSpeechRecognizedEvent(SpeechRecognizedEventArgs e)
+ {
+ if (e.Result.Confidence > speechRecognitionThreshold)
+ InvokeSpeechRecognized(e.Result.Text);
+ }
+
+ private void InvokeSpeechRecognized(String recognizedText)
+ {
+ if (SpeechRecognized != null)
+ SpeechRecognized.Invoke(this, recognizedText);
+ }
+
+ private void speechRecognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
+ {
+ PerformSpeechRecognizedEvent(e);
+ }
+ }
+}
View
132 ARDroneInput/SpeechInput.cs
@@ -1,12 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
+using ARDrone.Input.InputMappings;
+using ARDrone.Input.Speech;
using ARDrone.Input.Utility;
+using ARDrone.Input.Timing;
namespace ARDrone.Input
{
- class SpeechInput : GenericInput
+ public class SpeechInput : ConfigurableInput
{
+ private enum SpeechMode { Raw, Controlled, None };
+
+ private SpeechRecognition speechRecognition;
+ private TimeBasedCommand timeBasedCommand;
+
+ private SpeechMode currentMode = SpeechMode.None;
+
+ private String lastCommand = null;
+ private InputState lastInputState = new InputState();
+
public static List<GenericInput> GetNewInputDevices(IntPtr windowHandle, List<GenericInput> currentDevices)
{
List<GenericInput> newDevices = new List<GenericInput>();
@@ -32,52 +45,128 @@ private static bool CheckIfDeviceExists(List<GenericInput> currentDevices)
public SpeechInput()
: base()
- { }
+ {
+ timeBasedCommand = new TimeBasedCommand();
- public override void Dispose()
+ DetermineMapping();
+ InitSpeechRecognition();
+ }
+
+ private void InitSpeechRecognition()
+ {
+ speechRecognition = new SpeechRecognition(this);
+ speechRecognition.SpeechRecognized += new SpeechRecognition.SpeechRecognizedEventHandler(speechRecognition_SpeechRecognized);
+ }
+
+ protected override InputMapping GetStandardMapping()
{
+ SpeechBasedInputMapping mapping = new SpeechBasedInputMapping();
+
+ mapping.SetAxisLikeMappingValues("nach links", "nach rechts", "vorwärts", "rückwärts", "links rollen", "rechts rollen", "nach oben", "nach unten", "Tick", "Ticks");
+ mapping.SetButtonLikeMappingValues("Start", "Landung", "Schweben", "Notfall", "Nullstellung", "Kamera wechseln", "Spezial");
+ return mapping;
}
- public override void Init()
+ public override void Dispose()
{
+ timeBasedCommand.Dispose();
+ }
+ public override void InitDevice()
+ {
+ // Nothing to do
}
public override void StartRawInput()
{
-
+ speechRecognition.RecognizeUnrestrictedGrammar();
+ currentMode = SpeechMode.Raw;
}
public override String GetCurrentRawInput(out bool isAxis)
{
isAxis = false;
- return "";
+ return timeBasedCommand.CurrentCommand;
}
public override void EndRawInput()
{
-
+ currentMode = SpeechMode.None;
+ speechRecognition.EndSpeechRecognition();
}
public override void StartControlInput()
{
-
+ speechRecognition.RecognizeMappingGrammar();
+ currentMode = SpeechMode.Controlled;
}
public override InputState GetCurrentControlInput()
{
- return null;
+ String command = timeBasedCommand.CurrentCommand;
+
+ if (command == null && lastCommand == null)
+ return null;
+
+ lastCommand = command;
+
+ float roll = (command == SpeechMapping.RollLeftInputMapping) ? -1.0f : (command == SpeechMapping.RollRightInputMapping) ? 1.0f : 0.0f;
+ float pitch = (command == SpeechMapping.PitchForwardInputMapping) ? -1.0f : (command == SpeechMapping.PitchBackwardInputMapping) ? 1.0f : 0.0f;
+ float yaw = (command == SpeechMapping.YawLeftInputMapping) ? -1.0f : (command == SpeechMapping.YawRightInputMapping) ? 1.0f : 0.0f;
+ float gaz = (command == SpeechMapping.GazDownInputMapping) ? -1.0f : (command == SpeechMapping.GazUpInputMapping) ? 1.0f : 0.0f;
+
+ bool cameraSwap = (command == SpeechMapping.CameraSwapInputMapping);
+ bool takeOff = (command == SpeechMapping.TakeOffInputMapping);
+ bool land = (command == SpeechMapping.LandInputMapping);
+ bool hover = (command == SpeechMapping.HoverInputMapping);
+ bool emergency = (command == SpeechMapping.EmergencyInputMapping);
+ bool flatTrim = (command == SpeechMapping.FlatTrimInputMapping);
+
+ bool specialAction = (command == SpeechMapping.SpecialActionInputMapping);
+
+ if (roll != lastInputState.Roll || pitch != lastInputState.Pitch || yaw != lastInputState.Yaw || gaz != lastInputState.Gaz || cameraSwap != lastInputState.CameraSwap || takeOff != lastInputState.TakeOff ||
+ land != lastInputState.Land || hover != lastInputState.Hover || emergency != lastInputState.Emergency || flatTrim != lastInputState.FlatTrim || specialAction != lastInputState.SpecialAction)
+ {
+ InputState newInputState = new InputState(roll, pitch, yaw, gaz, cameraSwap, takeOff, land, hover, emergency, flatTrim, specialAction);
+ lastInputState = newInputState;
+ return newInputState;
+ }
+ else
+ {
+ return null;
+ }
}
public override void EndControlInput()
{
-
+ currentMode = SpeechMode.None;
+ speechRecognition.EndSpeechRecognition();
}
public override void CancelEvents()
{
-
+ timeBasedCommand.CancelCurrentCommand();
+ lastCommand = null;
+ }
+
+ private void UpdateCurrentlyRecognizedCommand(String commandSentence)
+ {
+ System.Console.WriteLine("Recognized + '" + commandSentence + "'");
+
+ if (currentMode == SpeechMode.Controlled)
+ {
+ int duration = 0;
+ String command = "";
+ SpeechMapping.ExtractCommandFromSentence(commandSentence, out command, out duration);
+
+ if (command != null && command != "" && duration > 0)
+ timeBasedCommand.SetCommand(command, duration);
+ }
+ else if (currentMode == SpeechMode.Raw)
+ {
+ timeBasedCommand.SetCommand(commandSentence, 400);
+ }
}
public override bool Cancellable
@@ -102,5 +191,26 @@ public override String DeviceInstanceId
{
get { return "SP"; }
}
+
+ public override String FilePrefix
+ {
+ get
+ {
+ return "SP";
+ }
+ }
+
+ public SpeechBasedInputMapping SpeechMapping
+ {
+ get
+ {
+ return (SpeechBasedInputMapping) mapping;
+ }
+ }
+
+ private void speechRecognition_SpeechRecognized(object sender, String recognizedSentence)
+ {
+ UpdateCurrentlyRecognizedCommand(recognizedSentence);
+ }
}
}
View
129 ARDroneInput/Timing/TimeBasedCommand.cs
@@ -0,0 +1,129 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading;
+
+namespace ARDrone.Input.Timing
+{
+ public class TimeBasedCommand
+ {
+ private Thread commandThread;
+ private Object synchronizer = new Object();
+ private bool disposed = false;
+
+ private String currentCommand = null;
+ private TimeSpan currentDuration;
+ private DateTime currentCommandStart;
+
+ private bool cancelDesired = false;
+ private String desiredCommand = null;
+ private TimeSpan desiredDuration;
+
+ public TimeBasedCommand()
+ {
+ StartCommandThread();
+ }
+
+ public void Dispose()
+ {
+ EndCommandThread();
+ }
+
+ private void StartCommandThread()
+ {
+ commandThread = new Thread(new ThreadStart(UpdateCommandsThreaded));
+ commandThread.Start();
+ }
+
+ private void EndCommandThread()
+ {
+ disposed = true;
+
+ try
+ {
+ commandThread.Join();
+ }
+ catch (Exception)
+ { }
+ }
+
+ private void UpdateCommandsThreaded()
+ {
+ bool cancelDesired = true;
+ String desiredCommand;
+ TimeSpan desiredDuration;
+
+ while (true)
+ {
+ if (disposed)
+ break;
+
+ lock (synchronizer)
+ {
+ desiredCommand = this.desiredCommand;
+ desiredDuration = this.desiredDuration;
+ cancelDesired = this.cancelDesired;
+
+ this.desiredCommand = null;
+ this.cancelDesired = false;
+ }
+
+ SetNewCommand(cancelDesired, desiredCommand, desiredDuration);
+ RemoveDeprecatedCommand();
+
+ Thread.Sleep(100);
+ }
+ }
+
+ private void SetNewCommand(bool cancelDesired, String desiredCommand, TimeSpan desiredDuration)
+ {
+ if (cancelDesired)
+ {
+ currentCommand = null;
+ }
+
+ if (desiredCommand != null)
+ {
+ currentCommand = desiredCommand;
+ currentCommandStart = DateTime.Now;
+ currentDuration = desiredDuration;
+ }
+ }
+
+ private void RemoveDeprecatedCommand()
+ {
+ if (currentCommandStart + currentDuration <= DateTime.Now)
+ {
+ currentCommand = null;
+ }
+ }
+
+ public void SetCommand(String command, int durationMillis)
+ {
+ if (command == null || durationMillis <= 0)
+ throw new Exception("The command must be given when setting it and the duration must be greater than 0");
+
+ lock (synchronizer)
+ {
+ desiredCommand = command;
+ desiredDuration = TimeSpan.FromMilliseconds(durationMillis);
+ }
+ }
+
+ public void CancelCurrentCommand()
+ {
+ lock (synchronizer)
+ {
+ cancelDesired = true;
+ }
+ }
+
+ public String CurrentCommand
+ {
+ get
+ {
+ return currentCommand;
+ }
+ }
+ }
+}
View
45 ARDroneInput/Utility/InputFactory.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using ARDrone.Input.InputConfigs;
+using ARDrone.Input.InputControls;
+using ARDrone.Input.InputMappings;
+
+namespace ARDrone.Input.Utility
+{
+ public class InputFactory
+ {
+
+ public static InputConfig CreateConfigFor(GenericInput input)
+ {
+ if (input is ButtonBasedInput)
+ return new ButtonBasedInputConfig();
+ else if (input is SpeechInput)
+ return new SpeechBasedInputConfig();
+
+ throw new Exception("No suitable input config class found");
+ }
+
+ public static InputControl CloneInputControls(InputControl controls)
+ {
+ if (controls is ButtonBasedInputControl)
+ return new ButtonBasedInputControl(controls.Mappings);
+ else if (controls is SpeechBasedInputControl)
+ return new SpeechBasedInputControl(controls.Mappings);
+
+
+ throw new Exception("No suitable input control class found");
+ }
+
+ public static InputControl CreateInputControlFromMappings(Dictionary<String, String> mappings, InputMapping mappingToCreateFor)
+ {
+ if (mappingToCreateFor is ButtonBasedInputMapping)
+ return new ButtonBasedInputControl(mappings);
+ else if (mappingToCreateFor is SpeechBasedInputMapping)
+ return new SpeechBasedInputControl(mappings);
+
+ throw new Exception("No suitable input mapping class found to create the input controls for");
+ }
+ }
+}
View
3 ARDroneInput/WiimoteInput.cs
@@ -86,7 +86,8 @@ protected static bool CheckIfDeviceExists(Wiimote wiimote, List<GenericInput> cu
public WiimoteInput(Wiimote wiimote) : base()
{
InitWiimote(wiimote);
- CreateMapping(GetValidButtons(), GetValidAxes());
+
+ DetermineMapping();
}
private void InitWiimote(Wiimote wiimote)
View
60 ARDroneUI_WPF/ConfigInput.xaml
@@ -11,8 +11,8 @@
<Window x:Class="ARDrone.UI.ConfigInput"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- Title="Configure Input Devices" Width="545" Height="340" MinWidth="545" MinHeight="340" MaxHeight="340" ShowInTaskbar="False" ResizeMode="NoResize" Closing="Window_Closing" MouseDown="Window_MouseDown">
- <Grid Background="#FFF0F0F0">
+ Title="Configure Input Devices" Width="545" MinWidth="545" ShowInTaskbar="True" Closing="Window_Closing" MouseDown="Window_MouseDown" SizeToContent="Height" Topmost="False" ResizeMode="NoResize">
+ <Grid Name="gridMain" Background="#FFF0F0F0">
<Grid.Resources>
<Style x:Key="styleContentLabel" TargetType="{x:Type Label}">
<Setter Property="Padding" Value="2,4,0,0" />
@@ -27,7 +27,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
- <RowDefinition Height="*"></RowDefinition>
+ <RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
@@ -45,59 +45,13 @@
<Label Name="labelDevicePresentInfo" Content="" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" Margin="1" Foreground="Red" />
- <Grid Grid.Row="1" Grid.ColumnSpan="2">
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto"></RowDefinition>
- <RowDefinition Height="Auto"></RowDefinition>
- <RowDefinition Height="Auto"></RowDefinition>
- <RowDefinition Height="Auto"></RowDefinition>
- <RowDefinition Height="Auto"></RowDefinition>
- <RowDefinition Height="Auto"></RowDefinition>
- <RowDefinition Height="Auto"></RowDefinition>
- <RowDefinition Height="Auto"></RowDefinition>
- <RowDefinition Height="Auto"></RowDefinition>
- </Grid.RowDefinitions>
-
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="Auto"></ColumnDefinition>
- <ColumnDefinition Width="*"></ColumnDefinition>
- <ColumnDefinition Width="Auto"></ColumnDefinition>
- <ColumnDefinition Width="*"></ColumnDefinition>
- </Grid.ColumnDefinitions>
-
- <Label Content="Axes" HorizontalAlignment="Center" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" />
- <Label Content="Buttons" HorizontalAlignment="Center" Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2" />
-
- <Label Content="Roll:" Grid.Row="1" Grid.Column="0" Style="{StaticResource styleContentLabel}" />
- <TextBox Name="textBoxAxisRoll" Text="" Grid.Row="1" Grid.Column="1" Style="{StaticResource styleContentTextBox}" IsReadOnly="True" GotFocus="textBoxControl_GotFocus" LostFocus="textBoxControl_LostFocus" IsEnabled="False" />
- <Label Content="Pitch:" Grid.Row="2" Grid.Column="0" Style="{StaticResource styleContentLabel}" />
- <TextBox Name="textBoxAxisPitch" Text="" Grid.Row="2" Grid.Column="1" Style="{StaticResource styleContentTextBox}" IsReadOnly="True" GotFocus="textBoxControl_GotFocus" LostFocus="textBoxControl_LostFocus" IsEnabled="False" />
- <Label Content="Yaw:" Grid.Row="3" Grid.Column="0" Style="{StaticResource styleContentLabel}" />
- <TextBox Name="textBoxAxisYaw" Text="" Grid.Row="3" Grid.Column="1" Style="{StaticResource styleContentTextBox}" IsReadOnly="True" GotFocus="textBoxControl_GotFocus" LostFocus="textBoxControl_LostFocus" IsEnabled="False" />
- <Label Content="Gaz:" Grid.Row="4" Grid.Column="0" Style="{StaticResource styleContentLabel}" />
- <TextBox Name="textBoxAxisGaz" Text="" Grid.Row="4" Grid.Column="1" Style="{StaticResource styleContentTextBox}" IsReadOnly="True" GotFocus="textBoxControl_GotFocus" LostFocus="textBoxControl_LostFocus" IsEnabled="False" />
- <Label Content="Tick Keyword:" Grid.Row="5" Grid.Column="0" Style="{StaticResource styleContentLabel}" Visibility="Hidden" />
- <TextBox Name="textBoxAxisTick" Text="" Grid.Row="5" Grid.Column="1" Style="{StaticResource styleContentTextBox}" IsReadOnly="True" GotFocus="textBoxControl_GotFocus" LostFocus="textBoxControl_LostFocus" IsEnabled="False" Visibility="Hidden" />
-
- <Label Content="Take Off:" Grid.Row="1" Grid.Column="2" Style="{StaticResource styleContentLabel}" />
- <TextBox Name="textBoxButtonTakeOff" Text="" Grid.Row="1" Grid.Column="3" Style="{StaticResource styleContentTextBox}" IsReadOnly="True" GotFocus="textBoxControl_GotFocus" LostFocus="textBoxControl_LostFocus" IsEnabled="False" />
- <Label Content="Land:" Grid.Row="2" Grid.Column="2" Style="{StaticResource styleContentLabel}" />
- <TextBox Name="textBoxButtonLand" Text="" Grid.Row="2" Grid.Column="3" Style="{StaticResource styleContentTextBox}" IsReadOnly="True" GotFocus="textBoxControl_GotFocus" LostFocus="textBoxControl_LostFocus" IsEnabled="False" />
- <Label Content="Hover:" Grid.Row="3" Grid.Column="2" Style="{StaticResource styleContentLabel}" />
- <TextBox Name="textBoxButtonHover" Text="" Grid.Row="3" Grid.Column="3" Style="{StaticResource styleContentTextBox}" IsReadOnly="True" GotFocus="textBoxControl_GotFocus" LostFocus="textBoxControl_LostFocus" IsEnabled="False" />
- <Label Content="Emergency:" Grid.Row="4" Grid.Column="2" Style="{StaticResource styleContentLabel}" />
- <TextBox Name="textBoxButtonEmergency" Text="" Grid.Row="4" Grid.Column="3" Style="{StaticResource styleContentTextBox}" IsReadOnly="True" GotFocus="textBoxControl_GotFocus" LostFocus="textBoxControl_LostFocus" IsEnabled="False" />
- <Label Content="Flat Trim:" Grid.Row="5" Grid.Column="2" Style="{StaticResource styleContentLabel}" />
- <TextBox Name="textBoxButtonFlatTrim" Text="" Grid.Row="5" Grid.Column="3" Style="{StaticResource styleContentTextBox}" IsReadOnly="True" GotFocus="textBoxControl_GotFocus" LostFocus="textBoxControl_LostFocus" IsEnabled="False" />
- <Label Content="Change Camera:" Grid.Row="6" Grid.Column="2" Style="{StaticResource styleContentLabel}" />
- <TextBox Name="textBoxButtonChangeCamera" Text="" Grid.Row="6" Grid.Column="3" Style="{StaticResource styleContentTextBox}" IsReadOnly="True" GotFocus="textBoxControl_GotFocus" LostFocus="textBoxControl_LostFocus" IsEnabled="False" />
- <Label Content="Special Action:" Grid.Row="7" Grid.Column="2" Style="{StaticResource styleContentLabel}" />
- <TextBox Name="textBoxButtonSpecialAction" Text="" Grid.Row="7" Grid.Column="3" Style="{StaticResource styleContentTextBox}" IsReadOnly="True" GotFocus="textBoxControl_GotFocus" LostFocus="textBoxControl_LostFocus" IsEnabled="False" />
+ <Grid Name="gridCommands" Grid.Row="1" Grid.ColumnSpan="2">
+ <!-- Insert commands here -->
</Grid>
- <StackPanel Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" Orientation="Horizontal">
+ <StackPanel Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" Orientation="Horizontal" Margin ="5">
<Button Name="buttonReset" Content="Reset" Margin="3" Padding="2" DockPanel.Dock="Left" Click="buttonReset_Click" />
</StackPanel>
- <StackPanel Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
+ <StackPanel Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal" Margin ="5">
<Button Name="buttonCancel" Content="Cancel" Margin="3" Padding="2" DockPanel.Dock="Left" Click="buttonCancel_Click" />
<Button Name="buttonSubmit" Content="Submit" Margin="0,3,3,3" Padding="2" DockPanel.Dock="Left" Click="buttonSubmit_Click" />
</StackPanel>
View
544 ARDroneUI_WPF/ConfigInput.xaml.cs
@@ -23,29 +23,25 @@
using System.Windows.Threading;
using ARDrone.Input;
using ARDrone.Input.Utility;
+using ARDrone.Input.InputConfigs;
+using ARDrone.Input.InputControls;
using ARDrone.Input.InputMappings;
namespace ARDrone.UI
{
public partial class ConfigInput : Window
{
- private enum Control { None, AxisRoll, AxisPitch, AxisYaw, AxisGaz, ButtonTakeoff, ButtonLand, ButtonHover, ButtonEmergency, ButtonFlatTrim, ButtonChangeCamera, ButtonSpecialAction };
- private enum ControlType { None, Axis, Button };
-
- private Dictionary<String, Control> nameControlMap = null;
- private Dictionary<Control, ControlType> controlTypeMap = null;
-
private ARDrone.Input.InputManager inputManager = null;
- private ButtonBasedInput selectedDevice = null;
+ List<ConfigurableInput> devices = null;
+
+ private ConfigurableInput selectedDevice = null;
private bool isSelectedDevicePresent = false;
- private Control selectedControl = Control.None;
- private ControlType selectedControlType = ControlType.None;
+ private String selectedControl = null;
+ private String tempContinuousInput = "";
- private String tempAxisInput = "";
-
- List<ButtonBasedInput> devices = null;
+ private String lastInputValue = null;
public ConfigInput()
{
@@ -58,39 +54,17 @@ public ConfigInput()
public ConfigInput(ARDrone.Input.InputManager inputManager)
{
InitializeComponent();
+ CreateControlsForNoDevice();
+
Init(inputManager);
}
public void Init(ARDrone.Input.InputManager inputManager)
{
- InitializeControlMap();
InitializeInputManager(inputManager);
InitializeDeviceList();
}
- public void InitializeControlMap()
- {
- nameControlMap = new Dictionary<String, Control>();
-
- nameControlMap.Add(textBoxAxisRoll.Name, Control.AxisRoll); nameControlMap.Add(textBoxAxisPitch.Name, Control.AxisPitch);
- nameControlMap.Add(textBoxAxisYaw.Name, Control.AxisYaw); nameControlMap.Add(textBoxAxisGaz.Name, Control.AxisGaz);
-
- nameControlMap.Add(textBoxButtonTakeOff.Name, Control.ButtonTakeoff); nameControlMap.Add(textBoxButtonLand.Name, Control.ButtonLand);
- nameControlMap.Add(textBoxButtonHover.Name, Control.ButtonHover); nameControlMap.Add(textBoxButtonEmergency.Name, Control.ButtonEmergency);
- nameControlMap.Add(textBoxButtonFlatTrim.Name, Control.ButtonFlatTrim); nameControlMap.Add(textBoxButtonChangeCamera.Name, Control.ButtonChangeCamera);
- nameControlMap.Add(textBoxButtonSpecialAction.Name, Control.ButtonSpecialAction);
-
- controlTypeMap = new Dictionary<Control, ControlType>();
-
- controlTypeMap.Add(Control.AxisRoll, ControlType.Axis); controlTypeMap.Add(Control.AxisPitch, ControlType.Axis);
- controlTypeMap.Add(Control.AxisYaw, ControlType.Axis); controlTypeMap.Add(Control.AxisGaz, ControlType.Axis);
-
- controlTypeMap.Add(Control.ButtonTakeoff, ControlType.Button); controlTypeMap.Add(Control.ButtonLand, ControlType.Button);
- controlTypeMap.Add(Control.ButtonHover, ControlType.Button); controlTypeMap.Add(Control.ButtonEmergency, ControlType.Button);
- controlTypeMap.Add(Control.ButtonFlatTrim, ControlType.Button); controlTypeMap.Add(Control.ButtonChangeCamera, ControlType.Button);
- controlTypeMap.Add(Control.ButtonSpecialAction, ControlType.Button);
- }
-
public void InitializeInputManager(ARDrone.Input.InputManager inputManager)
{
this.inputManager = inputManager;
@@ -103,14 +77,12 @@ public void InitializeInputManager(ARDrone.Input.InputManager inputManager)
public void InitializeDeviceList()
{
- devices = new List<ButtonBasedInput>();
+ devices = new List<ConfigurableInput>();
foreach (GenericInput inputDevice in inputManager.InputDevices)
{
- if (inputDevice is ButtonBasedInput)
- {
- AddDeviceToDeviceList((ButtonBasedInput)inputDevice);
- }
+ if (inputDevice is ConfigurableInput)
+ AddDeviceToDeviceList((ConfigurableInput)inputDevice);
}
}
@@ -128,7 +100,7 @@ private void DisposeInputManager()
inputManager.RawInputReceived -= new RawInputReceivedHandler(inputManager_RawInputReceived);
}
- private void HandleNewDevice(String deviceId, ButtonBasedInput inputDevice)
+ private void HandleNewDevice(String deviceId, ConfigurableInput inputDevice)
{
AddDeviceToDeviceList(inputDevice);
@@ -143,20 +115,8 @@ private void HandleNewDevice(String deviceId, ButtonBasedInput inputDevice)
}
}
- private void HandleLostDevice(String deviceId)
- {
- if (selectedDevice != null && selectedDevice.DeviceInstanceId == deviceId)
- {
- isSelectedDevicePresent = false;
- UpdateCurrentDeviceDescription();
- }
- else
- {
- RemoveDeviceFromDeviceList(deviceId);
- }
- }
- private void AddDeviceToDeviceList(ButtonBasedInput inputDevice)
+ private void AddDeviceToDeviceList(ConfigurableInput inputDevice)
{
bool foundReplacement = false;
for (int i = 0; i < devices.Count; i++)
@@ -181,9 +141,22 @@ private void AddDeviceToDeviceList(ButtonBasedInput inputDevice)
}
}
+ private void HandleLostDevice(String deviceId)
+ {
+ if (selectedDevice != null && selectedDevice.DeviceInstanceId == deviceId)
+ {
+ isSelectedDevicePresent = false;
+ UpdateCurrentDeviceDescription();
+ }
+ else
+ {
+ RemoveDeviceFromDeviceList(deviceId);
+ }
+ }
+
private void RemoveDeviceFromDeviceList(String deviceId)
{
- ButtonBasedInput inputDevice = GetDeviceById(deviceId);
+ ConfigurableInput inputDevice = GetDeviceById(deviceId);
if (inputDevice != null)
{
@@ -200,9 +173,9 @@ private void RemoveDeviceFromDeviceList(String deviceId)
}
}
- private ButtonBasedInput GetDeviceById(String deviceId)
+ private ConfigurableInput GetDeviceById(String deviceId)
{
- ButtonBasedInput input = null;
+ ConfigurableInput input = null;
for (int i = 0; i < devices.Count; i++)
{
if (devices[i].DeviceInstanceId == deviceId)
@@ -229,14 +202,13 @@ private void ChangeInputDevice()
for (int i = 0; i < devices.Count; i++)
{
if (devices[i].DeviceName == selectedDeviceName)
- {
selectedDevice = devices[i];
- }
}
if (selectedDevice != null)
{
- TakeOverMapping((ButtonBasedInputMapping)selectedDevice.Mapping);
+ CreateControlsForSelectedDevice();
+ TakeOverMapping(((ConfigurableInput)selectedDevice).Mapping);
isSelectedDevicePresent = true;
UpdateCurrentDeviceDescription();
}
@@ -257,171 +229,192 @@ private void UpdateCurrentDeviceDescription()
labelDevicePresentInfo.Content = isSelectedDevicePresent ? "" : "The device is not connected!";
}
- private void FocusInputElement(TextBox textBox)
+ private void SetMappingEnabledState(bool enabled)
{
- if (textBox != null && nameControlMap.ContainsKey(textBox.Name))
+ foreach (UIElement element in gridCommands.Children)
{
- inputManager.SwitchInputMode(Input.InputManager.InputMode.RawInput, selectedDevice.DeviceInstanceId);
-
- selectedControl = nameControlMap[textBox.Name];
- selectedControlType = controlTypeMap[selectedControl];
-
- textBox.Foreground = new SolidColorBrush(Colors.LightGray);
- textBox.Text = "-- Assigning a value --";
+ if (element is TextBox)
+ element.IsEnabled = enabled;
}
}
- private void UnfocusInputElement(TextBox textBox)
+ private void CreateControlsForSelectedDevice()
{
- if (textBox != null && nameControlMap.ContainsKey(textBox.Name))
+ if (selectedDevice != null)
{
- inputManager.SwitchInputMode(Input.InputManager.InputMode.NoInput);
+ InputConfig config = selectedDevice.InputConfig;
- selectedControl = Control.None;
- selectedControlType = ControlType.None;
+ gridCommands.Children.Clear();
+ CreateGridDefinitions(config.MaxRowNumber);
- textBox.Foreground = new SolidColorBrush(Colors.Black);
-
- if (selectedDevice != null)
+ foreach (KeyValuePair<String, InputConfigState> entry in config.States)
{
- TakeOverMapping((ButtonBasedInputMapping)selectedDevice.Mapping);
+ String name = entry.Key;
+ InputConfigState state = entry.Value;
+
+ CreateControl(name, state);
}
}
+ else
+ {
+ CreateControlsForNoDevice();
+ }
}
- private void SetMappingEnabledState(bool enabled)
+ private void CreateGridDefinitions(int maxRowNumber)
{
- textBoxAxisRoll.IsEnabled = enabled; textBoxAxisPitch.IsEnabled = enabled;
- textBoxAxisYaw.IsEnabled = enabled; textBoxAxisGaz.IsEnabled = enabled;
-
- textBoxButtonTakeOff.IsEnabled = enabled; textBoxButtonLand.IsEnabled = enabled;
- textBoxButtonHover.IsEnabled = enabled; textBoxButtonEmergency.IsEnabled = enabled;
- textBoxButtonFlatTrim.IsEnabled = enabled; textBoxButtonChangeCamera.IsEnabled = enabled;
- textBoxButtonSpecialAction.IsEnabled = enabled;
- }
+ gridCommands.RowDefinitions.Clear();
+ gridCommands.ColumnDefinitions.Clear();
- private void SaveMapping()
- {
- for (int i = 0; i < devices.Count; i++)
+ for (int i = 0; i < 2; i++)
{
- devices[i].SaveMapping();
+ gridCommands.ColumnDefinitions.Add(new ColumnDefinition() { Width = System.Windows.GridLength.Auto });
+ gridCommands.ColumnDefinitions.Add(new ColumnDefinition() { Width = new System.Windows.GridLength(1.0, GridUnitType.Star) });
}
- }
-
- private void RevertMapping()
- {
- for (int i = 0; i < devices.Count; i++)
+ for (int i = 0; i <= maxRowNumber; i++)
{
- devices[i].SaveMapping();
+ gridCommands.RowDefinitions.Add(new RowDefinition() { Height = System.Windows.GridLength.Auto });
}
}
- private void ResetMapping()
+ private void CreateControl(String name, InputConfigState state)
{
- if (selectedDevice == null)
+ if (state is InputValueConfigState)
{
- return;
- }
+ Label label = new Label() { Content = state.Name + ":" , Style = (Style)gridMain.FindResource("styleContentLabel") };
+ Grid.SetColumn(label, state.LayoutPosition == InputConfigState.Position.LeftColumn ? 0 : 2);
+ Grid.SetRow(label, state.RowNumber);
+ gridCommands.Children.Add(label);
- MessageBoxResult result = MessageBox.Show(this, "Do you really want to reset the setting to default values?", "Reset mapping", MessageBoxButton.YesNo, MessageBoxImage.Question);
+ TextBox textBox = new TextBox() { Name = "textBox" + name, IsReadOnly = true, Style = (Style)gridMain.FindResource("styleContentTextBox") };
+ Grid.SetColumn(textBox, state.LayoutPosition == InputConfigState.Position.LeftColumn ? 1 : 3);
+ Grid.SetRow(textBox, state.RowNumber);
- if (result == MessageBoxResult.Yes)
+ gridCommands.Children.Add(textBox);
+
+ textBox.GotFocus += new RoutedEventHandler(textBoxControl_GotFocus);
+ textBox.LostFocus += new RoutedEventHandler(textBoxControl_LostFocus);
+ }
+ else if (state is InputConfigHeader)
{
- selectedDevice.SetDefaultMapping();
- TakeOverMapping((ButtonBasedInputMapping)selectedDevice.Mapping);
+ Label label = new Label() { Content = state.Name, HorizontalAlignment = System.Windows.HorizontalAlignment.Center };
+ Grid.SetColumn(label, state.LayoutPosition == InputConfigState.Position.LeftColumn ? 0 : 2);
+ Grid.SetRow(label, state.RowNumber);
+ Grid.SetColumnSpan(label, 2);
+
+ gridCommands.Children.Add(label);
}
}
- private void TakeOverMapping(ButtonBasedInputMapping mapping)
+ private void CreateControlsForNoDevice()
{
- textBoxAxisRoll.Text = mapping.RollAxisMapping;
- textBoxAxisPitch.Text = mapping.PitchAxisMapping;
- textBoxAxisYaw.Text = mapping.YawAxisMapping;
- textBoxAxisGaz.Text = mapping.GazAxisMapping;
+ gridCommands.Children.Clear();
- textBoxButtonTakeOff.Text = mapping.TakeOffButton;
- textBoxButtonLand.Text = mapping.LandButton;
- textBoxButtonHover.Text = mapping.HoverButton;
- textBoxButtonEmergency.Text = mapping.EmergencyButton;
- textBoxButtonFlatTrim.Text = mapping.FlatTrimButton;
- textBoxButtonChangeCamera.Text = mapping.CameraSwapButton;
- textBoxButtonSpecialAction.Text = mapping.SpecialActionButton;
+ Label label = new Label() { Content = "No device selected", HorizontalAlignment = System.Windows.HorizontalAlignment.Center, VerticalAlignment = System.Windows.VerticalAlignment.Center };
+ label.Margin = new Thickness(20);
- CheckForDoubleInput();
+ gridCommands.Children.Add(label);
}
- private void UpdateMapping(ButtonBasedInputMapping mapping, Control control, String inputValue)
+ private void TakeOverMapping(InputMapping mapping)
{
- String currentValue = GetInputMappingValue(mapping, control);
+ Dictionary<String, String> mappings = mapping.Controls.Mappings;
- if (currentValue != inputValue)
+ foreach (KeyValuePair<String, String> entry in mappings)
{
- SetInputMappingValue(mapping, control, inputValue);
+ TextBox control = GetTextBoxByControlName(entry.Key);
+ control.Text = entry.Value;
}
- else
+
+ CheckForDoubleInput();
+ }
+
+ private void UpdateMappings()
+ {
+ if (selectedControl != null)
{
- SetInputMappingValue(mapping, control, "");
+ InputMapping mapping = selectedDevice.Mapping;
+
+ TextBox textBox = GetTextBoxByControlName(selectedControl);
+
+ String inputField = selectedControl;
+ String inputValue = textBox.Text;
+
+ UpdateMapping(mapping, inputField, inputValue);
}
}
- private String GetInputMappingValue(ButtonBasedInputMapping mapping, Control control)
+ private void UpdateMapping(InputMapping mapping, String inputField, String inputValue)
{
- if (control == Control.AxisRoll) { return mapping.RollAxisMapping; }
- if (control == Control.AxisPitch) { return mapping.PitchAxisMapping; }
- if (control == Control.AxisYaw) { return mapping.YawAxisMapping; }
- if (control == Control.AxisGaz) { return mapping.GazAxisMapping; }
-
- if (control == Control.ButtonTakeoff) { return mapping.TakeOffButton; }
- if (control == Control.ButtonLand) { return mapping.LandButton; }
- if (control == Control.ButtonHover) { return mapping.HoverButton; }
- if (control == Control.ButtonEmergency) { return mapping.EmergencyButton; }
- if (control == Control.ButtonFlatTrim) { return mapping.FlatTrimButton; }
- if (control == Control.ButtonChangeCamera) { return mapping.CameraSwapButton; }
- if (control == Control.ButtonSpecialAction) { return mapping.SpecialActionButton; }
+ String currentValue = GetInputMappingValue(mapping, inputField);
- return "";
+ if (currentValue != inputValue)
+ mapping.SetControlProperty(inputField, inputValue);
+ else
+ mapping.SetControlProperty(inputField, "");
}
- private void SetInputMappingValue(ButtonBasedInputMapping mapping, Control control, String inputValue)
+ private String GetInputMappingValue(InputMapping mapping, String inputField)
{
- if (control == Control.AxisRoll) { mapping.RollAxisMapping = inputValue; }
- if (control == Control.AxisPitch) { mapping.PitchAxisMapping = inputValue; }
- if (control == Control.AxisYaw) { mapping.YawAxisMapping = inputValue; }
- if (control == Control.AxisGaz) { mapping.GazAxisMapping = inputValue; }
+ Dictionary<String, String> mappings = mapping.Controls.Mappings;
+
+ if (mappings.ContainsKey(inputField))
+ return mappings[inputField];
- if (control == Control.ButtonTakeoff) { mapping.TakeOffButton = inputValue; }
- if (control == Control.ButtonLand) { mapping.LandButton = inputValue; }
- if (control == Control.ButtonHover) { mapping.HoverButton = inputValue; }
- if (control == Control.ButtonEmergency) { mapping.EmergencyButton = inputValue; }
- if (control == Control.ButtonFlatTrim) { mapping.FlatTrimButton = inputValue; }
- if (control == Control.ButtonChangeCamera) { mapping.CameraSwapButton = inputValue; }
- if (control == Control.ButtonSpecialAction) { mapping.SpecialActionButton = inputValue; }
+ throw new Exception("There is no mapping value named '" + inputField + "'");
+ }
+
+ private String GetCombinedText(String inputValue)
+ {
+ TextBox textBox = GetTextBoxByControlName(selectedControl);
+ return textBox.Text;
}
private void CheckForDoubleInput()
{
List<String> inputValues = new List<String>();
- inputValues.AddRange(textBoxAxisRoll.Text.Split('-')); inputValues.AddRange(textBoxAxisPitch.Text.Split('-'));
- inputValues.AddRange(textBoxAxisYaw.Text.Split('-')); inputValues.AddRange(textBoxAxisGaz.Text.Split('-'));
- inputValues.Add(textBoxButtonTakeOff.Text); inputValues.Add(textBoxButtonLand.Text); inputValues.Add(textBoxButtonHover.Text);