AnimatLab  2
Test
FirmataHingeServo.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 
6 namespace RoboticsGUI
7 {
8  namespace RobotIOControls
9  {
10  namespace Firmata
11  {
12 
13  public class FirmataHingeServo : AnimatGUI.DataObjects.Robotics.MotorControlSystem
14  {
15 
16  protected int m_iMinPulse = 544;
17  protected int m_iMaxPulse = 2400;
18 
22  protected bool m_bResetToStartPos = false;
23 
24  public override string Description {get {return "Controls a standard servo motor for a hinge joint using a Firmata controller";}set { }}
25  public override string WorkspaceImageName {get {return "RoboticsGUI.Graphics.HingeServoSmall.gif";}}
26  public override string ButtonImageName {get {return "RoboticsGUI.Graphics.HingeServoLarge.gif";}}
27  public override string PartType {get { return "FirmataHingeServo"; }}
28  public override string ModuleName { get { return "RoboticsAnimatSim"; } }
29  protected override Type GetLinkedPartDropDownTreeType() {return typeof(AnimatGUI.TypeHelpers.DropDownTreeEditorNoFirstSelect);}
30 
31  public virtual int MinPulse
32  {
33  get { return m_iMinPulse; }
34  set
35  {
36  if (value < 0)
37  throw new System.Exception("Invalid minimum pulse time specified. Value: " + m_iMinPulse);
38 
39  if (value >= m_iMaxPulse)
40  throw new System.Exception("The minimum pulse must be less than the maximum pulse of " + m_iMaxPulse);
41 
42  SetSimData("MinPulse", value.ToString(), true);
43  m_iMinPulse = value;
44  }
45  }
46 
47  public virtual int MaxPulse
48  {
49  get { return m_iMaxPulse; }
50  set
51  {
52  if (value < 0)
53  throw new System.Exception("Invalid maximum pulse time specified. Value: " + m_iMinPulse);
54 
55  if (value <= m_iMinPulse)
56  throw new System.Exception("The maximum pulse must be greater than the minimum pulse of " + m_iMinPulse);
57 
58  SetSimData("MaxPulse", value.ToString(), true);
59  m_iMaxPulse = value;
60  }
61  }
62 
63  public virtual bool ResetToStartPos
64  {
65  get { return m_bResetToStartPos; }
66  set
67  {
68  SetSimData("ResetToStartPos", m_bResetToStartPos.ToString(), true);
69  m_bResetToStartPos = true;
70  }
71  }
72 
73  public FirmataHingeServo(AnimatGUI.Framework.DataObject doParent)
74  : base(doParent)
75  {
76  m_strName = "Standard Hinge Servo";
77 
78  m_aryCompatiblePartTypes.Clear();
79  m_aryCompatiblePartTypes.Add(typeof(AnimatGUI.DataObjects.Physical.Joints.Hinge));
80  }
81 
82  public override AnimatGUI.Framework.DataObject Clone(AnimatGUI.Framework.DataObject doParent, bool bCutData, AnimatGUI.Framework.DataObject doRoot)
83  {
84  FirmataHingeServo doController = new FirmataHingeServo(doParent);
85  return doController;
86  }
87 
88  protected override void CloneInternal(AnimatGUI.Framework.DataObject doOriginal, bool bCutData, AnimatGUI.Framework.DataObject doRoot)
89  {
90  base.CloneInternal(doOriginal, bCutData, doRoot);
91 
92  FirmataHingeServo servo = (FirmataHingeServo)doOriginal;
93 
94  m_iMaxPulse = servo.m_iMaxPulse;
95  m_iMinPulse = servo.m_iMinPulse;
96  }
97 
98  public override void BuildProperties(ref AnimatGuiCtrls.Controls.PropertyTable propTable)
99  {
100  base.BuildProperties(ref propTable);
101 
102  propTable.Properties.Add(new AnimatGuiCtrls.Controls.PropertySpec("Min Pulse", this.MinPulse.GetType(), "MinPulse", "Properties", "Minimum pulse duration of servo", this.MinPulse));
103  propTable.Properties.Add(new AnimatGuiCtrls.Controls.PropertySpec("Max Pulse", this.MaxPulse.GetType(), "MaxPulse", "Properties", "Maximum pulse duration of servo", this.MaxPulse));
104  propTable.Properties.Add(new AnimatGuiCtrls.Controls.PropertySpec("Reset To Start Pos", this.ResetToStartPos.GetType(), "ResetToStartPos",
105  "Properties", "If true then it will reset the joint to a known position at the start the simulation", this.ResetToStartPos));
106  }
107 
108  public override void LoadData(ManagedAnimatInterfaces.IStdXml oXml)
109  {
110  base.LoadData(oXml);
111 
112  oXml.IntoElem();
113  m_iMaxPulse = oXml.GetChildInt("MaxPulse", m_iMaxPulse);
114  m_iMinPulse = oXml.GetChildInt("MinPulse", m_iMinPulse);
115  m_bResetToStartPos = oXml.GetChildBool("ResetToStartPos", m_bResetToStartPos);
116  oXml.OutOfElem();
117  }
118 
119  public override void SaveData(ManagedAnimatInterfaces.IStdXml oXml)
120  {
121  base.SaveData(oXml);
122 
123  oXml.IntoElem();
124  oXml.AddChildElement("MaxPulse", m_iMaxPulse);
125  oXml.AddChildElement("MinPulse", m_iMinPulse);
126  oXml.AddChildElement("ResetToStartPos", m_bResetToStartPos);
127  oXml.OutOfElem();
128  }
129 
130  public override void SaveSimulationXml(ManagedAnimatInterfaces.IStdXml oXml, ref AnimatGUI.Framework.DataObject nmParentControl, string strName = "")
131  {
132  base.SaveSimulationXml(oXml, ref nmParentControl, strName);
133 
134  oXml.IntoElem();
135  oXml.AddChildElement("MaxPulse", m_iMaxPulse);
136  oXml.AddChildElement("MinPulse", m_iMinPulse);
137  oXml.AddChildElement("ResetToStartPos", m_bResetToStartPos);
138  oXml.OutOfElem();
139  }
140  }
141  }
142  }
143 }
bool m_bResetToStartPos
If true then when the simulation starts it will always reset the position of the servo to 0 to begin ...