├── ServoAbstractor.py ├── LICENSE ├── TARSRunner.py ├── README.md └── ServoController.py /ServoAbstractor.py: -------------------------------------------------------------------------------- 1 | import time 2 | import TARS_Servo_Controller3 3 | 4 | def stepForward(): 5 | TARS_Servo_Controller3.height_neutral_to_up() 6 | TARS_Servo_Controller3.torso_neutral_to_forwards() 7 | TARS_Servo_Controller3.torso_bump() 8 | TARS_Servo_Controller3.torso_return() 9 | 10 | def turnRight(): 11 | TARS_Servo_Controller3.neutral_to_down() 12 | TARS_Servo_Controller3.turn_right() 13 | TARS_Servo_Controller3.down_to_neutral() 14 | TARS_Servo_Controller3.neutral_from_right() 15 | 16 | def turnLeft(): 17 | TARS_Servo_Controller3.neutral_to_down() 18 | TARS_Servo_Controller3.turn_left() 19 | TARS_Servo_Controller3.down_to_neutral() 20 | TARS_Servo_Controller3.neutral_from_left() 21 | 22 | def pose(): 23 | TARS_Servo_Controller3.neutral_to_down() 24 | TARS_Servo_Controller3.torso_neutral_to_backwards() 25 | TARS_Servo_Controller3.down_to_up() 26 | 27 | def unpose(): 28 | TARS_Servo_Controller3.torso_return2() 29 | 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 metaforismo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /TARSRunner.py: -------------------------------------------------------------------------------- 1 | import evdev 2 | import time 3 | import TARS_Servo_Abstractor3 4 | import TARS_Servo_Controller3 5 | from evdev import InputDevice, categorize, ecodes 6 | import Adafruit_PCA9685 7 | 8 | pwm = Adafruit_PCA9685.PCA9685() 9 | 10 | #port 11 | pwm.set_pwm(3, 3, 610) 12 | pwm.set_pwm(4, 4, 570) 13 | pwm.set_pwm(5, 5, 570) 14 | #starboard 15 | pwm.set_pwm(6, 6, 200) 16 | pwm.set_pwm(7, 7, 200) 17 | pwm.set_pwm(8, 8, 240) 18 | 19 | # Set frequency to 60hz, good for servos. 20 | pwm.set_pwm_freq(60) 21 | 22 | gamepad = InputDevice('/dev/input/event3') 23 | 24 | lTrg = 37 25 | rTrg = 50 26 | upBtn = 46 27 | downBtn = 32 28 | lBtn = 18 29 | rBtn = 33 30 | xBtn = 23 31 | yBtn = 35 32 | aBtn = 36 33 | bBtn = 34 34 | minusBtn = 49 35 | plusBtn = 24 36 | 37 | toggle = True 38 | pose = False 39 | 40 | print(gamepad) 41 | 42 | for event in gamepad.read_loop(): 43 | if event.type == ecodes.EV_KEY: 44 | if event.value == 1: 45 | if event.code == lTrg: 46 | print("Left Trigger") 47 | if toggle == True: 48 | TARS_Servo_Controller3.portMainPlus() 49 | elif toggle == False: 50 | TARS_Servo_Controller3.portMainMinus() 51 | elif event.code == rTrg: 52 | print("Right Trigger") 53 | if toggle == True: 54 | TARS_Servo_Controller3.starMainPlus() 55 | elif toggle == False: 56 | TARS_Servo_Controller3.starMainMinus() 57 | elif event.code == upBtn: 58 | print("Up - Step Forward") 59 | TARS_Servo_Abstractor3.stepForward() 60 | elif event.code == downBtn: 61 | print("Down") 62 | if pose == False: 63 | TARS_Servo_Abstractor3.pose() 64 | pose = True 65 | elif pose == True: 66 | TARS_Servo_Abstractor3.unpose() 67 | pose = False 68 | elif event.code == lBtn: 69 | print("Left - Turn Left") 70 | TARS_Servo_Abstractor3.turnLeft() 71 | elif event.code == rBtn: 72 | print("Right - Turn Right") 73 | TARS_Servo_Abstractor3.turnRight() 74 | elif event.code == xBtn: 75 | print("X") 76 | if toggle == True: 77 | TARS_Servo_Controller3.starForarmPlus() 78 | elif toggle == False: 79 | TARS_Servo_Controller3.starForarmMinus() 80 | elif event.code == yBtn: 81 | print("Y") 82 | if toggle == True: 83 | TARS_Servo_Controller3.portForarmPlus() 84 | elif toggle == False: 85 | TARS_Servo_Controller3.portForarmMinus() 86 | elif event.code == aBtn: 87 | print("A") 88 | if toggle == True: 89 | TARS_Servo_Controller3.starHandPlus() 90 | elif toggle == False: 91 | TARS_Servo_Controller3.starHandMinus() 92 | elif event.code == bBtn: 93 | print("B") 94 | if toggle == True: 95 | TARS_Servo_Controller3.portHandPlus() 96 | elif toggle == False: 97 | TARS_Servo_Controller3.portHandMinus() 98 | elif event.code == plusBtn: 99 | print("+") 100 | toggle = True 101 | elif event.code == minusBtn: 102 | print("-") 103 | toggle = False 104 | elif event.value == 0: 105 | print("Stop") -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TarsGPT: Detailed Guide to Building a Replica of TARS from Interstellar 2 | 3 | Welcome to the detailed guide for building your own replica of TARS, the iconic robot from the movie Interstellar. This project, named TarsGPT, will walk you through every step needed to create your functional robot. 4 | 5 | ## Introduction 6 | 7 | TARS, the iconic robot from the film Interstellar, has been a source of inspiration for many robotics and movie enthusiasts. Thanks to the work of Charles Diaz and other contributors, it is now possible to build a functional replica of TARS using easily accessible components and 3D printing techniques. This guide will provide you with all the information necessary to complete the TarsGPT project. 8 | ![TARS](https://github.com/user-attachments/assets/cb7f6acf-b7c4-41ff-ab1a-2640e8610c68) 9 | 10 | 11 | ## Original Guide 12 | 13 | For further details and inspiration, you can refer to the original guides by Charles Diaz and other contributors: 14 | - [Hackster.io - How to build your own replica of TARS from Interstellar](https://www.hackster.io/charlesdiaz/how-to-build-your-own-replica-of-tars-from-interstellar-224833) 15 | - [Medium - How to build a replica of the TARS robot from Interstellar](https://braintitan.medium.com/how-to-build-a-replica-of-the-tars-robot-from-interstellar-00ef00d4ac56) 16 | - [Instructables - Build a Moving TARS Robot From Interstellar](https://www.instructables.com/Build-a-Moving-TARS-Robot-From-Interstellar/) 17 | - [Raspberry Pi - Go interstellar and build your own replica TARS robot](https://www.raspberrypi.com/news/go-interstellar-and-build-your-own-replica-tars-robot/) 18 | - [Reddit - Interstellar TARS build](https://www.therpf.com/forums/threads/interstellar-tars-build.228377/) 19 | - [GitHub - GPTARS_Interstellar](https://github.com/poboisvert/GPTARS_Interstellar) 20 | 21 | ## Required Components 22 | 23 | Here is a list of the components and tools needed to build TarsGPT: 24 | 25 | ### Electronic Components 26 | 1. **Raspberry Pi** (or any other compatible control board) 27 | 2. **6 High-Torque Continuous Rotation Servo Motors** (for leg movement) 28 | 3. **Power Supply** (suitable for servo motors and Raspberry Pi) 29 | 4. **Connection Cables** 30 | 5. **Breadboard and Jumper Wires** (for prototyping) 31 | 32 | ### 3D Printing Materials 33 | 1. **PLA or ABS Filament** (for printing robot parts) 34 | 2. **3D Printer** 35 | 36 | ### Tools 37 | 1. **3D Slicing Software** (e.g., Cura, PrusaSlicer) 38 | 2. **3D Modeling Software** (e.g., Tinkercad, Fusion 360) 39 | 3. **Screwdrivers and Pliers** 40 | 4. **Glue or Adhesive Tape** (for assembly) 41 | 42 | ### Files and Code 43 | Files TARS v3_10 - Fix Case Clip 44 | [DOWNLOAD](https://uploadnow.io/f/MPLCGwg) 45 | print 46 | 47 | 48 | ## Step-by-Step Guide 49 | 50 | ### Step 1: Prepare CAD Files 51 | 1. Download the CAD files from the links provided in the original guide. 52 | 2. Open the CAD files in your preferred 3D modeling software. 53 | 3. Ensure all parts are correctly dimensioned and ready for printing. 54 | 55 | ### Step 2: 3D Print the Parts 56 | 1. Load the CAD files into your 3D slicing software. 57 | 2. Configure the printing settings (temperature, speed, infill, etc.). 58 | 3. Start printing all the necessary robot parts, including leg components and the body. 59 | 60 | ### Step 3: Assemble the Printed Parts 61 | 1. Once all parts are printed, begin assembly following the instructions provided in the original guide links. 62 | 2. Use glue or adhesive tape to secure parts together if necessary. 63 | 3. Ensure all parts are properly aligned and that the joints are movable. 64 | 65 | ### Step 4: Mount the Servo Motors 66 | 1. Place the servo motors in their designated printed slots. 67 | 2. Secure the servo motors using screws or glue. 68 | 3. Connect the servo motors to the Raspberry Pi using connection cables. 69 | 70 | ### Step 5: Electronic Wiring 71 | 1. Connect the Raspberry Pi and servo motors to the breadboard using jumper wires. 72 | 2. Ensure all connections are correct and secure. 73 | 3. Connect the power supply to the Raspberry Pi and servo motors. 74 | 75 | ### Step 6: Program the Raspberry Pi 76 | 1. Download the control code from the links provided in the original guide. 77 | 2. Upload the code to the Raspberry Pi. 78 | 3. Configure the code to control the servo motors and test the leg movement of the robot. 79 | 80 | ### Step 7: Testing and Calibration 81 | 1. Power on the robot and observe the leg movement. 82 | 2. Adjust the code and servo motor positions to achieve smooth and stable movement. 83 | 3. Test the robot on different surfaces to ensure it functions correctly in various environments. 84 | 85 | ## Conclusion 86 | 87 | Congratulations! You have completed the construction of your TARS replica, TarsGPT. Now you can enjoy your functional robot and, if you wish, make further improvements and customizations. 88 | 89 | For more details and updates, refer to the original guide links and join the community of TARS enthusiasts to share your experiences and discoveries. 90 | 91 | Enjoy your TarsGPT! 92 | 93 | --- 94 | 95 | ## Additional Resources 96 | 97 | ### Software 98 | - **Fusion 360**: [Autodesk Fusion 360](https://www.autodesk.com/ca-en/products/fusion360/personal) 99 | - **Raspberry Pi OS**: [Raspberry Pi Software](https://www.raspberrypi.com/software/) 100 | - **Getting Started with Raspberry Pi Pico**: [Raspberry Pi Projects](https://projects.raspberrypi.org/en/projects/getting-started-with-thepico/2) 101 | 102 | ### Tutorials 103 | - **Setting Up Raspberry Pi OS on SD Card**: [Tom's Hardware Guide](https://www.tomshardware.com/how-to/set-up-raspberrypi) 104 | 105 | ### Adafruit 16-Channel PWM HAT with Raspberry Pi 106 | - **Videos**: [YouTube Tutorial](https://www.youtube.com/watch?v=bB-xymRI8BY) 107 | - **Documentation**: [Adafruit Learning System](https://learn.adafruit.com/adafruit-16-channel-pwm-servo-hat-for-raspberry-pi), [Core Electronics Guide](https://core-electronics.com.au/guides/raspberry-pi/servo-hat-raspberry-pi/) 108 | 109 | ### Without HAT 110 | - **Videos**: [YouTube Tutorial 1](https://www.youtube.com/watch?v=ea6tSppgZlY), [YouTube Tutorial 2](https://www.youtube.com/watch?v=9jcEwn), [YouTube Tutorial 3](https://www.youtube.com/watch?v=40tZQPd3z8g) 111 | - **Documentation**: [Adafruit Servo Motor Lesson](https://learn.adafruit.com/adafruits-raspberry-pi-lesson-8-using-a-servo-motor/overview), [Adafruit Servo Driver Configuration](https://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi/configuring-your-pi-for-i2c), [YouTube Tutorial 4](https://www.youtube.com/watch?v=-x2EEIUMm6A) 112 | 113 | ### 3D Printing Services 114 | - **Steel/Stainless/Aluminium**: [Forgelabs](https://forgelabs.ca/) 115 | - **PLA/ABS**: [JLC 3D Printing](https://jlc3dp.com/3d-printing-quote), [Treatstock](https://www.treatstock.com/) 116 | 117 | ## Hardware 118 | 119 | ### Power 120 | - **12V to 6V 3A DC Converter**: [AliExpress](https://www.aliexpress.com/item/32968137531.html) 121 | - **5V DC 4A Fixed Power Adapter**: [Amazon](https://www.amazon.ca/Power-Adapter-100-240V-Transformers-Supply/dp/B087LY41PV/ref=asc_df_B08722QC75/?tag=googleshopid20\&linkCode=dff\&hvadid=682881027011\&hvpos=\&hvnetw=g\&hvrand=959679585182106901\&hvponet1143272721594\&mcid=5e13db627edd3e64951090cd0674e630\&gad_source=1\&th=1) 122 | - **5V 4A DC Power Adapter**: [AliExpress](https://www.aliexpress.com/item/1005004589869667.html) 123 | - **5V USB to DC Power Cable**: [AliExpress](https://www.aliexpress.com/item/1005007296667037.html) 124 | - **200000mAh Portable Solar Power Bank**: [AliExpress](https://www.aliexpress.com/item/1005006959367711.html), [AliExpress](https://www.aliexpress.com/item/1005007306992861.html) 125 | - **HDMI Cable**: FPV cable HDMI, HDMI-compatible, FPV HDMI ffc HDMI Ribbon Cable 90 Degree Mini/Micro HDMI to Standard HDMI PCB Connector 20pin fpv micro HDMI 15 cm 126 | 127 | ### Hardware Components 128 | - **Servo Motors and Accessories**: 129 | - [AliExpress](https://www.aliexpress.com/item/32914198349.html) 130 | - [ServoCity](https://www.servocity.com/25t-lightweight-hub-horn/) 131 | - [Adafruit 16-Channel 12-bit PWM/Servo Driver](https://www.adafruit.com/product/2327) 132 | - [8Bitdo Zero 2 Bluetooth](https://www.aliexpress.com/item/1005006458561670.html) 133 | - [LewanSoul LD-3015MG Servo](https://www.aliexpress.com/item/32787763122.html) 134 | - [Futaba s3003 Servo](https://www.aliexpress.com/item/32957714272.html) 135 | - [Gobilda Linkage Rod](https://www.gobilda.com/2903-series-nylon-ball-linkage-m4-24-5mm-length-4-pack) 136 | - [Flexor Bolts](https://www.aliexpress.com/item/32969042589.html) 137 | - [Hex Bolts](https://www.aliexpress.com/item/1005003184392748.html) 138 | - [Bearing](https://www.aliexpress.com/item/4000909583668.html) 139 | - [Compression Spring](https://www.aliexpress.com/item/1005005312536098.html) 140 | 141 | ### CPU & Storage 142 | - **MicroSD Card**: [AliExpress](https://www.aliexpress.com/item/1005006693506827.html) 143 | - **Raspberry Pi 3B/3B+**: [Adafruit](https://www.adafruit.com/raspberrypi3bplus) or eBay 144 | - **Elecrow 5 inch Touchscreen**: [AliExpress](https://www.aliexpress.com/item/32889893278.html) 145 | 146 | ### Battery 147 | - **myCharge Hub Mini**: [Target](https://www.target.com/p/mycharge-hub-mini-3350mah-2-4a-output-power-bank-with-integrated-charging-cables-silver/-/A-76625534\#lnk=sametab) 148 | - **Zeee 11.1V 120C 1500mAh 3S**: [Amazon](https://www.amazon.ca/Zeee-Graphene-Quadcopter-Airplane-Helicopter/dp/B08P399N54/) 149 | 150 | ### Extra Features 151 | - **Face Recognition**: [Core Electronics Guide](https://core-electronics.com.au/guides/face-identify-raspberry-pi/) 152 | - **Lidar Detection**: MS200 Lidar Sensor Kit Portable 360° TOF Ranging Scanner 12m Range Support ROS1 and ROS2 For ROS Robot Raspberry Pi Jetson NANO 153 | - **Battery Level**: [SparkFun Tutorial](https://learn.sparkfun.com/tutorials/ltc4150-coulomb-counter-hookup-guide), [Raspberry Pi Forum](https://forums.raspberrypi.com/viewtopic.php?t=173046), [Raspberry Pi Forum](https://forums.raspberrypi.com/viewtopic.php?t=340930) 154 | 155 | ### ChatGPT Integration 156 | - **ChatGPT Tutorial**: [YouTube Tutorial](https://www.youtube.com/watch?v=N0718RfpuWE) 157 | 158 | ## Software Components 159 | 160 | ### Servo Abstractor - Python 161 | This program automates walking functions by combining basic servo movements from the servo controller file. 162 | 163 | ### TARS Runner - Python 164 | This file initializes TARS and handles communication with the Bluetooth remote. Run it in the terminal on your onboard computer. 165 | 166 | ### Servo Controller - Python 167 | This script controls the basic movements of the servos in TARS using an Adafruit PCA9685 servo driver. 168 | 169 | Enjoy building your TarsGPT and exploring the endless possibilities it offers! 170 | -------------------------------------------------------------------------------- /ServoController.py: -------------------------------------------------------------------------------- 1 | from __future__ import division 2 | import time 3 | import Adafruit_PCA9685 4 | from threading import Thread 5 | 6 | pwm = Adafruit_PCA9685.PCA9685() 7 | 8 | # Set frequency to 60hz, good for servos. 9 | pwm.set_pwm_freq(60) 10 | 11 | portMain = 610 12 | starMain = 200 13 | portForarm = 570 14 | starForarm = 200 15 | portHand = 570 16 | starHand = 240 17 | 18 | # Center Lift Servo (0) Values 19 | upHeight = 205 20 | neutralHeight = 275 21 | downHeight = 450 22 | 23 | # Port Drive Servo (1) Values 24 | forwardPort = 440 25 | neutralPort = 375 26 | backPort = 330 27 | 28 | # Starboard Drive Servo (2) Values 29 | forwardStarboard = 292 30 | neutralStarboard = 357 31 | backStarboard = 402 32 | 33 | # moves the torso from a neutral position upwards, allowing the torso to pivot forwards or backwards 34 | def height_neutral_to_up(): 35 | height = neutralHeight 36 | print('setting center servo (0) Neutral --> Up position') 37 | while (height > upHeight): 38 | height = height - 1 39 | pwm.set_pwm(0, 0, height) 40 | time.sleep(0.001) 41 | print('center servo (0) set to: Up position\n ') 42 | 43 | # rotates the torso outwards, enough so that when TARS pivots and lands, the bottom of the torso is 44 | # flush with the ground. Making the torso flush with the ground is an intentional improvement from 45 | # previous programs, where TARS would land and then slide a little on smooth surfaces, which while 46 | # allowing for a simple walking program, inhibited TARS' ability to walk on surfaces with different 47 | # coefficients of friction 48 | def torso_neutral_to_forwards(): 49 | port = neutralPort 50 | starboard = neutralStarboard 51 | print('setting port and starboard servos (1)(2) Neutral --> Forward') 52 | while (port < forwardPort): 53 | port = port + 1 54 | starboard = starboard - 1 55 | pwm.set_pwm(1, 1, port) 56 | pwm.set_pwm(2, 2, starboard) 57 | time.sleep(0.0001) 58 | print('port and starboard servos (1)(2) set to: Forward position\n ') 59 | 60 | def torso_neutral_to_backwards(): 61 | port = neutralPort 62 | starboard = neutralStarboard 63 | print('setting port and starboard servos (1)(2) Neutral --> Forward') 64 | while (port > backPort): 65 | port = port - 1 66 | starboard = starboard + 1 67 | pwm.set_pwm(1, 1, port) 68 | pwm.set_pwm(2, 2, starboard) 69 | time.sleep(0.0001) 70 | print('port and starboard servos (1)(2) set to: Forward position\n ') 71 | 72 | # rapidly shifts the torso height from UP --> DOWN and then returns --> UP, which should cause TARS 73 | # to pivot and land on it's torso 74 | def torso_bump(): 75 | height = upHeight 76 | print('performing a torso bump\nsetting center servo (0) Up --> Down position FAST') 77 | while (height < downHeight): 78 | height = height + 2 79 | pwm.set_pwm(0, 0, height) 80 | time.sleep(0.000001) 81 | print('setting center servo (0) Down --> Up position FAST') 82 | while (height > upHeight): 83 | height = height - 1 84 | pwm.set_pwm(0, 0, height) 85 | time.sleep(0.0001) 86 | print('center servo (0) returned to Up position\n') 87 | 88 | # returns the torso's vertical height and rotation to centered values from up height and forward 89 | # rotation. Activates two external functions so movement in both axes can occur in parallel. 90 | def torso_return(): 91 | t1 = Thread(target = torso_return_rotation) 92 | t2 = Thread(target = torso_return_vertical) 93 | 94 | t1.start() 95 | t2.start() 96 | 97 | # returns torso's rotation to neutral from forward 98 | def torso_return_rotation(): 99 | port = forwardPort 100 | starboard = forwardStarboard 101 | print('setting port and starboard servos (1)(2) Forward --> Neutral position') 102 | while (port > neutralPort): 103 | port = port - 1 104 | starboard = starboard + 1 105 | pwm.set_pwm(1, 1, port) 106 | pwm.set_pwm(2, 2, starboard) 107 | time.sleep(0.005) 108 | print('port and starboard servos (1)(2) set to: Neutral position\n ') 109 | 110 | # returns torso's vertical to neutral from up 111 | def torso_return_vertical(): 112 | height = upHeight 113 | print('setting center servo (0) Up --> Down position') 114 | # moving the torso down to create clearance for the rotation of the legs 115 | while (height < downHeight): 116 | height = height + 1 117 | pwm.set_pwm(0, 0, height) 118 | time.sleep(0.00005) 119 | # moving the torso up from down to neutral 120 | #time.sleep(.2) 121 | while (height > neutralHeight): 122 | height = height - 1 123 | pwm.set_pwm(0, 0, height) 124 | time.sleep(0.00001) 125 | print('center servo (0) set to: Neutral position\n ') 126 | 127 | def torso_return2(): 128 | t1 = Thread(target = torso_return_rotation2) 129 | t2 = Thread(target = torso_return_vertical2) 130 | 131 | t1.start() 132 | t2.start() 133 | 134 | # returns torso's rotation to neutral from forward 135 | def torso_return_rotation2(): 136 | port = backPort 137 | starboard = backStarboard 138 | print('setting port and starboard servos (1)(2) Forward --> Neutral position') 139 | while (port < neutralPort): 140 | port = port + 1 141 | starboard = starboard - 1 142 | pwm.set_pwm(1, 1, port) 143 | pwm.set_pwm(2, 2, starboard) 144 | time.sleep(0.01) 145 | print('port and starboard servos (1)(2) set to: Neutral position\n ') 146 | 147 | # returns torso's vertical to neutral from up 148 | def torso_return_vertical2(): 149 | height = upHeight 150 | print('setting center servo (0) Up --> Down position') 151 | # moving the torso down to create clearance for the rotation of the legs 152 | while (height < downHeight): 153 | height = height + 1 154 | pwm.set_pwm(0, 0, height) 155 | time.sleep(0.001) 156 | # moving the torso up from down to neutral 157 | time.sleep(.25) 158 | while (height > neutralHeight): 159 | height = height - 1 160 | pwm.set_pwm(0, 0, height) 161 | time.sleep(0.001) 162 | print('center servo (0) set to: Neutral position\n ') 163 | 164 | 165 | # moves the torso from neutral position to down 166 | def neutral_to_down(): 167 | height = neutralHeight 168 | print('setting center servo (0) Neutral --> Down position') 169 | while (height < downHeight): 170 | height = height + 1 171 | pwm.set_pwm(0, 0, height) 172 | time.sleep(0.001) 173 | 174 | def down_to_up(): 175 | height = downHeight 176 | print('setting center servo (0) Down --> Neutral position') 177 | while (height > upHeight): 178 | height = height - 1 179 | pwm.set_pwm(0, 0, height) 180 | time.sleep(0.001) 181 | 182 | def down_to_neutral(): 183 | height = downHeight 184 | print('setting center servo (0) Down --> Neutral position') 185 | while (height > neutralHeight): 186 | height = height - 1 187 | pwm.set_pwm(0, 0, height) 188 | time.sleep(0.001) 189 | 190 | def neutral_to_down(): 191 | height = neutralHeight 192 | print('setting center servo (0) Down --> Neutral position') 193 | while (height < downHeight): 194 | height = height + 1 195 | pwm.set_pwm(0, 0, height) 196 | time.sleep(0.001) 197 | 198 | 199 | def turn_right(): 200 | port = neutralPort 201 | starboard = neutralStarboard 202 | while (port < forwardPort): 203 | port = port + 1 204 | starboard = starboard + 1 205 | pwm.set_pwm(1, 1, port) 206 | pwm.set_pwm(2, 2, starboard) 207 | time.sleep(0.001) 208 | 209 | def turn_left(): 210 | port = neutralPort 211 | starboard = neutralStarboard 212 | while (port > backPort): 213 | port = port - 1 214 | starboard = starboard - 1 215 | pwm.set_pwm(1, 1, port) 216 | pwm.set_pwm(2, 2, starboard) 217 | time.sleep(0.001) 218 | 219 | def neutral_from_right(): 220 | port = forwardPort 221 | starboard = backStarboard 222 | while (port > neutralPort): 223 | port = port - 1 224 | starboard = starboard - 1 225 | pwm.set_pwm(1, 1, port) 226 | pwm.set_pwm(2, 2, starboard) 227 | time.sleep(0.005) 228 | pwm.set_pwm(1, 1, neutralPort) 229 | pwm.set_pwm(2, 2, neutralStarboard) 230 | 231 | def neutral_from_left(): 232 | port = backPort 233 | starboard = forwardStarboard 234 | while (port < neutralPort): 235 | port = port + 1 236 | starboard = starboard + 1 237 | pwm.set_pwm(1, 1, port) 238 | pwm.set_pwm(2, 2, starboard) 239 | time.sleep(0.005) 240 | pwm.set_pwm(1, 1, neutralPort) 241 | pwm.set_pwm(2, 2, neutralStarboard) 242 | # Arm shenanigans 243 | # port Main Arm 244 | def portMainPlus(): 245 | global portMain 246 | portMain = portMain - 10 247 | pwm.set_pwm(3, 3, portMain) 248 | time.sleep(0.0001) 249 | print("increase starMain") 250 | print(portMain) 251 | 252 | def portMainMinus(): 253 | global portMain 254 | portMain = portMain + 10 255 | pwm.set_pwm(3, 3, portMain) 256 | time.sleep(0.0001) 257 | print("decrease starMain") 258 | print(portMain) 259 | 260 | # port Forarm 261 | def portForarmPlus(): 262 | global portForarm 263 | portForarm = portForarm - 10 264 | pwm.set_pwm(4, 4, portForarm) 265 | time.sleep(0.0001) 266 | print("increase starForarm") 267 | print(portForarm) 268 | 269 | def portForarmMinus(): 270 | global portForarm 271 | portForarm = portForarm + 10 272 | pwm.set_pwm(4, 4, portForarm) 273 | time.sleep(0.0001) 274 | print("decrease starForarm") 275 | print(portForarm) 276 | 277 | # port Hand 278 | def portHandPlus(): 279 | global portHand 280 | portHand = portHand - 10 281 | pwm.set_pwm(5, 5, portHand) 282 | time.sleep(0.0001) 283 | print("increase starHand") 284 | print(portHand) 285 | 286 | def portHandMinus(): 287 | global portHand 288 | portHand = portHand + 10 289 | pwm.set_pwm(5, 5, portHand) 290 | time.sleep(0.0001) 291 | print("decrease starHand") 292 | print(portHand) 293 | 294 | # starboard Main Arm 295 | def starMainPlus(): 296 | global starMain 297 | starMain = starMain + 10 298 | pwm.set_pwm(6, 6, starMain) 299 | time.sleep(0.0001) 300 | print("increase starMain") 301 | print(starMain) 302 | 303 | def starMainMinus(): 304 | global starMain 305 | starMain = starMain - 10 306 | pwm.set_pwm(6, 6, starMain) 307 | time.sleep(0.0001) 308 | print("decrease starMain") 309 | print(starMain) 310 | 311 | # port Forarm 312 | def starForarmPlus(): 313 | global starForarm 314 | starForarm = starForarm + 10 315 | pwm.set_pwm(7, 7, starForarm) 316 | time.sleep(0.0001) 317 | print("increase starForarm") 318 | print(starForarm) 319 | 320 | def starForarmMinus(): 321 | global starForarm 322 | starForarm = starForarm - 10 323 | pwm.set_pwm(7, 7, starForarm) 324 | time.sleep(0.0001) 325 | print("decrease starForarm") 326 | print(starForarm) 327 | 328 | # port Hand 329 | def starHandPlus(): 330 | global starHand 331 | starHand = starHand + 10 332 | pwm.set_pwm(8, 8, starHand) 333 | time.sleep(0.0001) 334 | print("increase starHand") 335 | print(starHand) 336 | 337 | def starHandMinus(): 338 | global starHand 339 | starHand = starHand - 10 340 | pwm.set_pwm(8, 8, starHand) 341 | time.sleep(0.0001) 342 | print("decrease starHand") 343 | print(starHand) --------------------------------------------------------------------------------