From d040cf3c385f8fea90aa28c23bc11fbb97149ddc Mon Sep 17 00:00:00 2001
From: mehtank <mehtank@ucla.edu>
Date: Fri, 9 Sep 2022 06:40:15 +0000
Subject: [PATCH] Servofix

---
 rocolib/builders/MountedServoBuilder.py |  2 +-
 rocolib/builders/WheelBuilder.py        |  2 +-
 rocolib/library/MountedServo.yaml       |  2 +-
 rocolib/library/ServoMotor.py           | 12 ++++++++----
 rocolib/library/Wheel.yaml              |  2 +-
 rocolib/utils/dimensions.py             | 11 +++++++++++
 6 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/rocolib/builders/MountedServoBuilder.py b/rocolib/builders/MountedServoBuilder.py
index e1e8fda..305bfa7 100644
--- a/rocolib/builders/MountedServoBuilder.py
+++ b/rocolib/builders/MountedServoBuilder.py
@@ -9,6 +9,6 @@ c.addSubcomponent("servo", "ServoMotor", inherit=True, prefix=None)
 c.inheritAllInterfaces("mount", prefix=None)
 c.inheritAllInterfaces("servo", prefix=None)
 c.addConnection(("mount", "mount.decoration"),
-                ("servo", "horn"))
+                ("servo", "mount"))
 
 c.toLibrary("MountedServo")
diff --git a/rocolib/builders/WheelBuilder.py b/rocolib/builders/WheelBuilder.py
index 3dd5384..9ee698f 100644
--- a/rocolib/builders/WheelBuilder.py
+++ b/rocolib/builders/WheelBuilder.py
@@ -8,7 +8,7 @@ c.addSubcomponent("tire", "Tire", inherit="radius tire_thickness".split(), prefi
 
 
 c.inheritAllInterfaces("drive", prefix=None)
-c.addConnection(("drive", "mount"),
+c.addConnection(("drive", "horn"),
                 ("tire", "face"))
 
 c.toLibrary("Wheel")
diff --git a/rocolib/library/MountedServo.yaml b/rocolib/library/MountedServo.yaml
index 3a41255..aaaa270 100644
--- a/rocolib/library/MountedServo.yaml
+++ b/rocolib/library/MountedServo.yaml
@@ -3,7 +3,7 @@ connections:
   - - mount
     - mount.decoration
   - - servo
-    - horn
+    - mount
   - {}
 interfaces:
   botedge0:
diff --git a/rocolib/library/ServoMotor.py b/rocolib/library/ServoMotor.py
index 5881e47..954d2a9 100644
--- a/rocolib/library/ServoMotor.py
+++ b/rocolib/library/ServoMotor.py
@@ -1,6 +1,7 @@
 from rocolib.api.components import FoldedComponent
 from rocolib.api.composables.graph.Face import Rectangle as Shape
 from rocolib.api.ports import AnchorPort
+from rocolib.utils.utils import decorateGraph
 from rocolib.utils.dimensions import getDim
 from rocolib.utils.transforms import Translate, RotateZ
 from rocolib.utils.numsym import dot
@@ -10,16 +11,19 @@ class ServoMotor(FoldedComponent):
   def define(self):
     self.addParameter("angle", 0, paramType="angle", minValue=None, maxValue=None)
     self.addParameter("servo", "fs90r", paramType="dimension")
-    self.addInterface("horn", AnchorPort(self, self.getGraph(), "h", Translate([0,0,0])))
-    self.addFaceInterface("mount", "h")
+    self.addInterface("mount", AnchorPort(self, self.getGraph(), "horn", Translate([0,0,0])))
+    self.addFaceInterface("horn", "horn")
 
   def assemble(self):
     s = self.getParameter("servo")
     a = self.getParameter("angle")
     dz = getDim(s, "hornheight")
+    dy = getDim(s, "motorlength") / 2 - getDim(s, "hornoffset")
 
-    self.addFace(Shape("h", 0, 0))
-    self.setInterface("horn", AnchorPort(self, self.getGraph(), "h", dot(RotateZ(a), Translate([0,0,dz]))))
+    f = Shape("horn", 0, 0)
+    decorateGraph(f, Shape("hole", 1, 1))
+    self.addFace(f)
+    self.setInterface("mount", AnchorPort(self, self.getGraph(), "horn", dot(RotateZ(a), Translate([0,-dy,dz]))))
 
 if __name__ == "__main__":
     ServoMotor.test()
diff --git a/rocolib/library/Wheel.yaml b/rocolib/library/Wheel.yaml
index ed257d9..7f2f802 100644
--- a/rocolib/library/Wheel.yaml
+++ b/rocolib/library/Wheel.yaml
@@ -1,7 +1,7 @@
 connections:
   connection0:
   - - drive
-    - mount
+    - horn
   - - tire
     - face
   - {}
diff --git a/rocolib/utils/dimensions.py b/rocolib/utils/dimensions.py
index f54306f..4d87f57 100644
--- a/rocolib/utils/dimensions.py
+++ b/rocolib/utils/dimensions.py
@@ -86,6 +86,17 @@ Should horn be a different object?
 
 '''
 
+dims["ds2g"] = { "type" : "servo",
+    "motorlength"   : 17,
+    "motorwidth"    : 8.5,
+    "motorheight"   : 11,
+    "shoulderlength": 3.5,
+    "hornlength"    : 11,
+    "hornheight"    : 9,
+    "hornoffset"    : 4,
+    "horndepth"     : 1,
+}
+
 dims["s4303r"] = { "type" : "servo",
     "motorlength"   : 31,
     "motorwidth"    : 17,
-- 
GitLab