AnimatLab  2
Test
DynamixelUSB.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using AnimatGUI.Framework;
6 
7 namespace RoboticsGUI
8 {
9  namespace RobotIOControls
10  {
11  namespace DynamixelUSB
12  {
13 
14  public class DynamixelUSB : AnimatGUI.DataObjects.Robotics.RobotIOControl
15  {
16  #region " Attributes "
17 
18  protected int m_iPortNumber = 3;
19  protected int m_iBaudRate = 1;
20 
21  #endregion
22 
23  #region " Attributes "
24 
25  public override string Description {get {return "Performs IO with the Dynamixel USB controller using their SDK to control servo motors. Implements angular or linear motor systems.";} set { }}
26  public override string ButtonImageName {get {return "RoboticsGUI.Graphics.DynamixelUSB.gif";}}
27  public override string WorkspaceImageName {get {return "RoboticsGUI.Graphics.DynamixelUSBSmall.gif";}}
28  public override string PartType {get { return "DynamixelUSB"; }}
29  public override string ModuleName { get { return "RoboticsAnimatSim"; } }
30 
31  public virtual int PortNumber
32  {
33  get
34  {
35  return m_iPortNumber;
36  }
37  set
38  {
39  SetSimData("PortNumber", value.ToString(), true);
40  m_iPortNumber = value;
41  }
42  }
43 
44  public virtual int BaudRate
45  {
46  get
47  {
48  return m_iBaudRate;
49  }
50  set
51  {
52  if (!((value == 1) || (value == 3) || (value == 4) || (value == 7) || (value == 9) ||
53  (value == 9) || (value == 16) || (value == 34) || (value == 103) || (value == 207)))
54  throw new System.Exception("Invalid baud rate specified. Rate: " + value.ToString());
55 
56  SetSimData("BaudRate", value.ToString(), true);
57  m_iBaudRate = value;
58  }
59  }
60 
61  #endregion
62 
63  #region " Methods "
64 
65  public DynamixelUSB(AnimatGUI.Framework.DataObject doParent)
66  : base(doParent)
67  {
68  m_strName = "Dynamixel USB";
69 
70  //Setup the parts that are available for this type of controller.
71  m_aryAvailablePartTypes.Add(new DynamixelUSBHingeServo(this));
72  m_aryAvailablePartTypes.Add(new DynamixelUSBPrismaticServo(this));
73  }
74 
75  public override AnimatGUI.Framework.DataObject Clone(AnimatGUI.Framework.DataObject doParent, bool bCutData, AnimatGUI.Framework.DataObject doRoot)
76  {
77  DynamixelUSB doInterface = new DynamixelUSB(doParent);
78  return doInterface;
79  }
80 
81  protected override void CloneInternal(DataObject doOriginal, bool bCutData, DataObject doRoot)
82  {
83  base.CloneInternal(doOriginal, bCutData, doRoot);
84 
85  DynamixelUSB doOrig = (DynamixelUSB)doOriginal;
86 
87  if (doOrig != null)
88  {
89  m_iPortNumber = doOrig.m_iPortNumber;
90  m_iBaudRate = doOrig.m_iBaudRate;
91  }
92  }
93 
94  public override void BuildProperties(ref AnimatGuiCtrls.Controls.PropertyTable propTable)
95  {
96  base.BuildProperties(ref propTable);
97 
98  propTable.Properties.Add(new AnimatGuiCtrls.Controls.PropertySpec("Com Port", this.PortNumber.GetType(), "PortNumber", "Properties", "Com port number", this.PortNumber));
99  propTable.Properties.Add(new AnimatGuiCtrls.Controls.PropertySpec("Baud Rate", this.BaudRate.GetType(), "BaudRate", "Properties", "Baud rate to use for communications", this.BaudRate));
100  }
101 
102  public override void LoadData(ManagedAnimatInterfaces.IStdXml oXml)
103  {
104  base.LoadData(oXml);
105 
106  oXml.IntoElem();
107 
108  m_iPortNumber = oXml.GetChildInt("PortNumber", m_iPortNumber);
109  m_iBaudRate = oXml.GetChildInt("BaudRate", m_iBaudRate);
110 
111  oXml.OutOfElem();
112  }
113 
114  public override void SaveData(ManagedAnimatInterfaces.IStdXml oXml)
115  {
116  base.SaveData(oXml);
117 
118  oXml.IntoElem();
119 
120  oXml.AddChildElement("PortNumber", m_iPortNumber);
121  oXml.AddChildElement("BaudRate", m_iBaudRate);
122 
123  oXml.OutOfElem();
124  }
125 
126  public override void SaveSimulationXml(ManagedAnimatInterfaces.IStdXml oXml, ref DataObject nmParentControl, string strName = "")
127  {
128  base.SaveSimulationXml(oXml, ref nmParentControl, strName);
129 
130  oXml.IntoElem();
131 
132  oXml.AddChildElement("PortNumber", m_iPortNumber);
133  oXml.AddChildElement("BaudRate", m_iBaudRate);
134 
135  oXml.OutOfElem();
136  }
137 
138  #endregion
139 
140  }
141  }
142  }
143 }