From 1b3f9dbc3af30f4213e8ad0d56883dea2de53a92 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Fri, 17 Feb 2017 23:40:46 +0100 Subject: [PATCH] Robotarm: Generator for servo powered robot arm segments --- boxes/generators/robotarm.py | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 boxes/generators/robotarm.py diff --git a/boxes/generators/robotarm.py b/boxes/generators/robotarm.py new file mode 100644 index 0000000..cba3dfb --- /dev/null +++ b/boxes/generators/robotarm.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +# Copyright (C) 2017 Florian Festi +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from boxes import * +from boxes import robot, servos + +class RobotArm(Boxes): # change class name here and below + """Segments of servo powered robot arm""" + + ui_group = "Part" + + def __init__(self): + Boxes.__init__(self) + + self.addSettingsArgs(edges.FingerJointSettings) + for i in range(1, 6): + ra = robot.RobotArg(True) + sa = servos.ServoArg() + self.argparser.add_argument( + "--type%i" % i, action="store", type=ra, + default="none", choices=ra.choices(), + help="type of arm segment") + self.argparser.add_argument( + "--servo%ia" % i, action="store", type=sa, default="Servo9g", + help="type of servo to use") + self.argparser.add_argument( + "--servo%ib" % i, action="store", type=sa, default="Servo9g", + help="type of servo to use on second side (if different is supported)") + self.argparser.add_argument( + "--length%i" % i, action="store", type=float, default=50., + help="length of segment axle to axle") + + def render(self): + # Initialize canvas + self.open() + + for i in range(5, 0,-1): + armtype = getattr(self, "type%i" % i) + length = getattr(self, "length%i" % i) + servoA = getattr(self, "servo%ia" % i) + servoB = getattr(self, "servo%ib" % i) + armcls = getattr(robot, armtype, None) + if not armcls: + continue + servoClsA = getattr(servos, servoA) + servoClsB = getattr(servos, servoB) + armcls(self, servoClsA(self), servoClsB(self))(length, move="up") + self.close() + +def main(): + b = RobotArm() + b.parseArgs() + b.render() + +if __name__ == '__main__': + main()