├── Hexapod.pdf ├── picture.jpg ├── picture2.jpg ├── .gitignore ├── README.md ├── src └── Hexapod │ ├── LegServos.h │ ├── Hexapod.ino │ └── LegServos.cpp └── LICENSE /Hexapod.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JustinSDK/Stick-Hexapod/HEAD/Hexapod.pdf -------------------------------------------------------------------------------- /picture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JustinSDK/Stick-Hexapod/HEAD/picture.jpg -------------------------------------------------------------------------------- /picture2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JustinSDK/Stick-Hexapod/HEAD/picture2.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Stick-Hexapod 2 | 3 | 廢材四足機器人 4 | 5 | ![廢材四足機器人](picture2.jpg) 6 | 7 | 用以下材料修修補補成廢材 … 8 | 9 | - 木材部份:飛機木、冰棒棍、竹筷 10 | - 工具部份:斜口鉗、美工刀、剪刀、保麗龍膠 11 | - 電子電路部份 12 | - Arduino Uno x 1 13 | - Tower Pro 9g servos x 12 14 | - HC-SR04 超音波感應器 x 1 15 | - 3.7V 14500可充電鋰電池(三號電池大小) x 2 16 | - 原型擴充板 x 1(如果你要直接把線路焊在一起就不用) 17 | - 一些電線 18 | 19 | [![廢材四足機器人](picture.jpg)](https://www.youtube.com/watch?v=IsQaMRlMKro) 20 | 21 | 製作方式說明: 22 | 23 | - [廢材四足機器人(一)修修補補成廢材](https://openhome.cc/Gossip/CodeData/StickHexapod/StickHexapod1.html) 24 | - [廢材四足機器人(二)電路連接、靜態平行與足態設計](https://openhome.cc/Gossip/CodeData/StickHexapod/StickHexapod2.html) 25 | - [廢材四足機器人(三)一點點的程式設計說明](https://openhome.cc/Gossip/CodeData/StickHexapod/StickHexapod3.html) 26 | 27 | [https://openhome.cc](https://openhome.cc) -------------------------------------------------------------------------------- /src/Hexapod/LegServos.h: -------------------------------------------------------------------------------- 1 | #define MICROSECONDS 250 2 | 3 | void initServos(); 4 | void updateServos(); 5 | void forLoop(int to, void (*fn)(int), int arg); 6 | 7 | // step servo degrees data 8 | 9 | void joint1_1ClkDataStep(int deg); 10 | void joint2_1ClkDataStep(int deg); 11 | void joint3_1ClkDataStep(int deg); 12 | void joint4_1ClkDataStep(int deg); 13 | 14 | void joint1_2DownDataStep(int deg); 15 | void joint2_2DownDataStep(int deg); 16 | void joint3_2DownDataStep(int deg); 17 | void joint4_2DownDataStep(int deg); 18 | 19 | void joint1_3DownDataStep(int deg); 20 | void joint2_3DownDataStep(int deg); 21 | void joint3_3DownDataStep(int deg); 22 | void joint4_3DownDataStep(int deg); 23 | 24 | // basic step action 25 | 26 | void leg1UpStep(int deg); 27 | void leg2UpStep(int deg); 28 | void leg3UpStep(int deg); 29 | void leg4UpStep(int deg); 30 | 31 | void hexapodUpStep(int deg); 32 | 33 | void hexapodClockwiseStep(int deg); 34 | 35 | void joint1_1ClkStep(int deg); 36 | void joint2_1ClkStep(int deg); 37 | void joint3_1ClkStep(int deg); 38 | void joint4_1ClkStep(int deg); 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/Hexapod/Hexapod.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "LegServos.h" 3 | 4 | #define UP 1 5 | #define DOWN -1 6 | #define CLK 1 7 | #define CT_CLK -1 8 | #define BACK 1 9 | 10 | void setup() { 11 | initServos(); 12 | hexapod(UP); 13 | } 14 | 15 | void loop() { 16 | for(int i = 0; i < 3; i++) { 17 | hexapod(DOWN); 18 | hexapod(UP); 19 | } 20 | 21 | hello(); 22 | 23 | hexapodTurn(CLK); 24 | hexapodTurn(CT_CLK); 25 | 26 | for(int i = 0; i < 3; i++) { 27 | moveForward(); 28 | } 29 | } 30 | 31 | // continuous movements 32 | 33 | void hexapod(int dir) { 34 | forLoop(90, hexapodUpStep, dir); 35 | } 36 | 37 | void hello() { 38 | forLoop(60, leg1UpStep, -1); 39 | delay(100); 40 | for(int i = 0; i < 3; i++) { 41 | forLoop(90, joint1_1ClkStep, CT_CLK); 42 | forLoop(90, joint1_1ClkStep, CLK); 43 | } 44 | delay(100); 45 | forLoop(60, leg1UpStep, 1); 46 | } 47 | 48 | void leg1Turn(int dir, int angle) { 49 | forLoop(60, leg1UpStep, -1); 50 | forLoop(angle, joint1_1ClkStep, dir); 51 | forLoop(60, leg1UpStep, 1); 52 | } 53 | 54 | void leg2Turn(int dir, int angle) { 55 | forLoop(60, leg2UpStep, -1); 56 | forLoop(angle, joint2_1ClkStep, dir); 57 | forLoop(60, leg2UpStep, 1); 58 | } 59 | 60 | void leg3Turn(int dir, int angle) { 61 | forLoop(60, leg3UpStep, -1); 62 | forLoop(angle, joint3_1ClkStep, dir); 63 | forLoop(60, leg3UpStep, 1); 64 | } 65 | 66 | void leg4Turn(int dir, int angle) { 67 | forLoop(60, leg4UpStep, -1); 68 | forLoop(angle, joint4_1ClkStep, dir); 69 | forLoop(60, leg4UpStep, 1); 70 | } 71 | 72 | void hexapodTurn(int dir) { 73 | if(dir == CLK) { 74 | leg2Turn(dir, 45); 75 | forLoop(45, hexapodClockwiseStep, dir); 76 | leg2Turn(dir, 45); 77 | leg4Turn(dir, 90); 78 | 79 | leg3Turn(dir, 45); 80 | forLoop(45, hexapodClockwiseStep, dir); 81 | leg3Turn(dir, 45); 82 | leg1Turn(dir, 90); 83 | } else { 84 | leg1Turn(dir, 45); 85 | forLoop(45, hexapodClockwiseStep, dir); 86 | leg1Turn(dir, 45); 87 | leg3Turn(dir, 90); 88 | 89 | leg4Turn(dir, 45); 90 | forLoop(45, hexapodClockwiseStep, dir); 91 | leg4Turn(dir, 45); 92 | leg2Turn(dir, 90); 93 | } 94 | } 95 | 96 | void leg234Push(int dir) { 97 | joint2_1ClkDataStep(dir); 98 | joint3_1ClkDataStep(-dir); 99 | joint4_1ClkDataStep(-dir); 100 | updateServos(); 101 | } 102 | 103 | void leg124Push(int dir) { 104 | joint1_1ClkDataStep(dir); 105 | joint2_1ClkDataStep(dir); 106 | joint4_1ClkDataStep(-dir); 107 | updateServos(); 108 | } 109 | 110 | void moveForward() { 111 | leg1Turn(CT_CLK, 45); 112 | forLoop(45, leg234Push, BACK); 113 | leg4Turn(CLK, 90); 114 | 115 | leg3Turn(CLK, 45); 116 | forLoop(45, leg124Push, BACK); 117 | leg2Turn(CT_CLK, 90); 118 | } 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /src/Hexapod/LegServos.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "LegServos.h" 4 | 5 | Servo servos[4][3]; 6 | 7 | int degOfServo[4][3] = { 8 | {90, 180, 180}, // LEG3 - Servo 1, 2, 3 9 | {90, 180, 180}, // LEG4 - Servo 1, 2, 3 10 | {45, 0, 0}, // LEG2 - Servo 1, 2, 3 11 | {135, 0, 0} // LEG1 - Servo 1, 2, 3 12 | }; 13 | 14 | void initServos() { 15 | for(int i = 0; i < 4; i++) { 16 | for(int j = 0; j < 3; j++) { 17 | servos[i][j].attach(8 + i * 3 + j); 18 | } 19 | } 20 | updateServos(); 21 | } 22 | 23 | void updateServos() { 24 | for(int i = 0; i < 4; i++) { 25 | for(int j = 0; j < 3; j++) { 26 | servos[i][j].write(degOfServo[i][j]); 27 | delayMicroseconds(MICROSECONDS); 28 | } 29 | } 30 | } 31 | 32 | void forLoop(int to, void (*fn)(int), int arg) { 33 | for(int i = 0; i < to; i++) { 34 | fn(arg); 35 | } 36 | } 37 | 38 | // step servo degree data 39 | 40 | void joint1_1ClkDataStep(int deg) { 41 | degOfServo[3][0] += deg; 42 | } 43 | 44 | void joint2_1ClkDataStep(int deg) { 45 | degOfServo[2][0] += deg; 46 | } 47 | 48 | void joint3_1ClkDataStep(int deg) { 49 | degOfServo[0][0] += deg; 50 | } 51 | 52 | void joint4_1ClkDataStep(int deg) { 53 | degOfServo[1][0] += deg; 54 | } 55 | 56 | void joint1_2DownDataStep(int deg) { 57 | degOfServo[3][1] += deg; 58 | } 59 | 60 | void joint2_2DownDataStep(int deg) { 61 | degOfServo[2][1] += deg; 62 | } 63 | 64 | void joint3_2DownDataStep(int deg) { 65 | degOfServo[0][1] -= deg; 66 | } 67 | 68 | void joint4_2DownDataStep(int deg) { 69 | degOfServo[1][1] -= deg; 70 | } 71 | 72 | void joint1_3DownDataStep(int deg) { 73 | degOfServo[3][2] += deg; 74 | } 75 | 76 | void joint2_3DownDataStep(int deg) { 77 | degOfServo[2][2] += deg; 78 | } 79 | 80 | void joint3_3DownDataStep(int deg) { 81 | degOfServo[0][2] -= deg; 82 | } 83 | 84 | void joint4_3DownDataStep(int deg) { 85 | degOfServo[1][2] -= deg; 86 | } 87 | 88 | // basic step actions 89 | 90 | void leg1UpStep(int deg) { 91 | joint1_2DownDataStep(deg); joint1_3DownDataStep(deg); 92 | updateServos(); 93 | } 94 | 95 | void leg2UpStep(int deg) { 96 | joint2_2DownDataStep(deg); joint2_3DownDataStep(deg); 97 | updateServos(); 98 | } 99 | 100 | void leg3UpStep(int deg) { 101 | joint3_2DownDataStep(deg); joint3_3DownDataStep(deg); 102 | updateServos(); 103 | } 104 | 105 | void leg4UpStep(int deg) { 106 | joint4_2DownDataStep(deg); joint4_3DownDataStep(deg); 107 | updateServos(); 108 | } 109 | 110 | void hexapodUpStep(int deg) { 111 | joint1_2DownDataStep(deg); joint2_2DownDataStep(deg); joint3_2DownDataStep(deg); joint4_2DownDataStep(deg); 112 | joint1_3DownDataStep(deg); joint2_3DownDataStep(deg); joint3_3DownDataStep(deg); joint4_3DownDataStep(deg); 113 | updateServos(); 114 | } 115 | 116 | void hexapodClockwiseStep(int deg) { 117 | joint1_1ClkDataStep(-deg); 118 | joint2_1ClkDataStep(-deg); 119 | joint3_1ClkDataStep(-deg); 120 | joint4_1ClkDataStep(-deg); 121 | updateServos(); 122 | } 123 | 124 | void joint1_1ClkStep(int deg) { 125 | joint1_1ClkDataStep(deg); 126 | updateServos(); 127 | } 128 | 129 | void joint2_1ClkStep(int deg) { 130 | joint2_1ClkDataStep(deg); 131 | updateServos(); 132 | } 133 | 134 | void joint3_1ClkStep(int deg) { 135 | joint3_1ClkDataStep(deg); 136 | updateServos(); 137 | } 138 | 139 | void joint4_1ClkStep(int deg) { 140 | joint4_1ClkDataStep(deg); 141 | updateServos(); 142 | } 143 | 144 | 145 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | --------------------------------------------------------------------------------