Introduce the gait of RaspClaws Robot
Components used in this course
l For the hexapod robot, the gait generation method is almost the most complicated part of the program, because it needs to coordinate dozens of servos to move at the same time, and keeps every moment when walking forward and backward there must be at least three legs on the ground, which means that only three legs can be in the swing pair at least at any moment, and at least three legs should be in the support pair.
l In order to make it more intuitive, we represent the position of each leg of the robot as 1, 2, 3, 4 respectively and divide the robot legs into two groups. Taking forward heading of the robot as forward direction, we name `I` including the left front leg, the left back leg, and the right middle leg; `II` including the right front leg, the right back leg, and the left middle leg.
Code/Global Gait | 1 | 2 | 3 | 4 |
I | 1 | 2 | 3 | 4 |
II | 3 | 4 | 1 | 2 |
l For example, when the first group of legs in the global gait is in the `1` position, the second group of legs is in the `3` position.
l When the global gait changes to a cycle of 1, 2, 3, 4, 1, 2, ..., the robot moves forward in a diagonal gait.
l When the global gait changes to a cycle of 4, 3, 2, 1, 4, 3, ..., the robot walks backward in a diagonal gait.
l When the three legs on the right side of the robot walk forward and the two legs on the left side walk backward, the robot turns to the left.
l When the left three legs of the robot walk forward and the left two legs walk backward, the robot turns to the right.
Introduction of program of gait generation
The code of this course is in move.py. This chapter only introduces the program structure. These codes need to rely on other functions and parameters in move.py to run.
1. #Fast gait 2. def move(step_input, speed, command): 3. step_I = step_input 4. step_II = step_input + 2 5. 6. if step_II > 4: 7. step_II = step_II - 4 8. if speed == 0: 9. return 10. 11. if command == 'no': 12. ''''' 13. When the speed is positive, the robot moves forward. When the speed is negative, the robot moves backward. 14. ''' 15. right_I(step_I, speed, 0) 16. left_II(step_I, speed, 0) 17. right_III(step_I, speed, 0) 18. 19. left_I(step_II, speed, 0) 20. right_II(step_II, speed, 0) 21. left_III(step_II, speed, 0) 22. elif command == 'left': 23. right_I(step_I, speed, 0) 24. left_II(step_I, -speed, 0) 25. right_III(step_I, speed, 0) 26. 27. left_I(step_II, -speed, 0) 28. right_II(step_II, speed, 0) 29. left_III(step_II, -speed, 0) 30. elif command == 'right': 31. right_I(step_I, -speed, 0) 32. left_II(step_I, speed, 0) 33. right_III(step_I, -speed, 0) 34. 35. left_I(step_II, speed, 0) 36. right_II(step_II, -speed, 0) 37. left_III(step_II, speed, 0) 38. #Slow gait 39. def dove(step_input, speed, timeLast, dpi, command): 40. step_I = step_input 41. step_II = step_input + 2 42. 43. if step_II > 4: 44. step_II = step_II - 4 45. 46. if speed > 0: 47. if step_input == 1: 48. for speed_I in range(0, (speed+int(speed/dpi)), int(speed/dpi)): 49. if move_stu and command == 'no': 50. speed_II = speed_I 51. speed_I = speed - speed_I 52. dove_Left_I(-speed_I, 3*speed_II) 53. dove_Right_II(-speed_I, 3*speed_II) 54. dove_Left_III(-speed_I, 3*speed_II) 55. 56. dove_Right_I(speed_I, -10) 57. dove_Left_II(speed_I, -10) 58. dove_Right_III(speed_I, -10) 59. time.sleep(timeLast/dpi) 60. else: 61. pass 62. 63. if command == 'left': 64. speed_II = speed_I 65. speed_I = speed - speed_I 66. dove_Left_I(speed_I, 3*speed_II) 67. dove_Right_II(-speed_I, 3*speed_II) 68. dove_Left_III(speed_I, 3*speed_II) 69. 70. dove_Right_I(speed_I, -10) 71. dove_Left_II(-speed_I, -10) 72. dove_Right_III(speed_I, -10) 73. time.sleep(timeLast/dpi) 74. elif command == 'right': 75. speed_II = speed_I 76. speed_I = speed - speed_I 77. dove_Left_I(-speed_I, 3*speed_II) 78. dove_Right_II(speed_I, 3*speed_II) 79. dove_Left_III(-speed_I, 3*speed_II) 80. dove_Right_I(-speed_I, -10) 81. dove_Left_II(speed_I, -10) 82. dove_Right_III(-speed_I, -10) 83. time.sleep(timeLast/dpi) 84. else: 85. pass 86. 87. if move_stu == 0 and command == 'no': 88. break 89. 90. elif step_input == 2: 91. for speed_I in range(0, (speed+int(speed/dpi)), int(speed/dpi)): 92. if move_stu and command == 'no': 93. speed_II = speed_I 94. speed_I = speed - speed_I 95. dove_Left_I(speed_II, 3*(speed-speed_II)) 96. dove_Right_II(speed_II, 3*(speed-speed_II)) 97. dove_Left_III(speed_II, 3*(speed-speed_II)) 98. dove_Right_I(-speed_II, -10) 99. dove_Left_II(-speed_II, -10) 100. dove_Right_III(-speed_II, -10) 101. time.sleep(timeLast/dpi) 102. else: 103. pass 104. 105. if command == 'left': 106. speed_II = speed_I 107. speed_I = speed - speed_I 108. dove_Left_I(-speed_II, 3*(speed-speed_II)) 109. dove_Right_II(speed_II, 3*(speed-speed_II)) 110. dove_Left_III(-speed_II, 3*(speed-speed_II)) 111. dove_Right_I(-speed_II, -10) 112. dove_Left_II(speed_II, -10) 113. dove_Right_III(-speed_II, -10) 114. time.sleep(timeLast/dpi) 115. elif command == 'right': 116. speed_II = speed_I 117. speed_I = speed - speed_I 118. dove_Left_I(speed_II, 3*(speed-speed_II)) 119. dove_Right_II(-speed_II, 3*(speed-speed_II)) 120. dove_Left_III(speed_II, 3*(speed-speed_II)) 121. dove_Right_I(speed_II, -10) 122. dove_Left_II(-speed_II, -10) 123. dove_Right_III(speed_II, -10) 124. time.sleep(timeLast/dpi) 125. else: 126. pass 127. 128. if move_stu == 0 and command == 'no': 129. break 130. elif step_input == 3: 131. for speed_I in range(0, (speed+int(speed/dpi)), int(speed/dpi)): 132. if move_stu and command == 'no': 133. speed_II = speed_I 134. speed_I = speed - speed_I 135. dove_Left_I(speed_I, -10) 136. dove_Right_II(speed_I, -10) 137. dove_Left_III(speed_I, -10) 138. dove_Right_I(-speed_I, 3*speed_II) 139. dove_Left_II(-speed_I, 3*speed_II) 140. dove_Right_III(-speed_I, 3*speed_II) 141. time.sleep(timeLast/dpi) 142. else: 143. pass 144. 145. if command == 'left': 146. speed_II = speed_I 147. speed_I = speed - speed_I 148. dove_Left_I(-speed_I, -10) 149. dove_Right_II(speed_I, -10) 150. dove_Left_III(-speed_I, -10) 151. dove_Right_I(-speed_I, 3*speed_II) 152. dove_Left_II(speed_I, 3*speed_II) 153. dove_Right_III(-speed_I, 3*speed_II) 154. time.sleep(timeLast/dpi) 155. elif command == 'right': 156. speed_II = speed_I 157. speed_I = speed - speed_I 158. dove_Left_I(speed_I, -10) 159. dove_Right_II(-speed_I, -10) 160. dove_Left_III(speed_I, -10) 161. dove_Right_I(speed_I, 3*speed_II) 162. dove_Left_II(-speed_I, 3*speed_II) 163. dove_Right_III(speed_I, 3*speed_II) 164. time.sleep(timeLast/dpi) 165. else: 166. pass 167. 168. if move_stu == 0 and command == 'no': 169. break 170. elif step_input == 4: 171. for speed_I in range(0, (speed+int(speed/dpi)), int(speed/dpi)): 172. if move_stu and command == 'no': 173. speed_II = speed_I 174. speed_I = speed - speed_I 175. dove_Left_I(-speed_II, -10) 176. dove_Right_II(-speed_II, -10) 177. dove_Left_III(-speed_II, -10) 178. dove_Right_I(speed_II, 3*(speed-speed_II)) 179. dove_Left_II(speed_II, 3*(speed-speed_II)) 180. dove_Right_III(speed_II, 3*(speed-speed_II)) 181. time.sleep(timeLast/dpi) 182. else: 183. pass 184. 185. if command == 'left': 186. speed_II = speed_I 187. speed_I = speed - speed_I 188. dove_Left_I(speed_II, -10) 189. dove_Right_II(-speed_II, -10) 190. dove_Left_III(speed_II, -10) 191. dove_Right_I(speed_II, 3*(speed-speed_II)) 192. dove_Left_II(-speed_II, 3*(speed-speed_II)) 193. dove_Right_III(speed_II, 3*(speed-speed_II)) 194. time.sleep(timeLast/dpi) 195. elif command == 'right': 196. speed_II = speed_I 197. speed_I = speed - speed_I 198. dove_Left_I(-speed_II, -10) 199. dove_Right_II(speed_II, -10) 200. dove_Left_III(-speed_II, -10) 201. dove_Right_I(-speed_II, 3*(speed-speed_II)) 202. dove_Left_II(speed_II, 3*(speed-speed_II)) 203. dove_Right_III(-speed_II, 3*(speed-speed_II)) 204. time.sleep(timeLast/dpi) 205. else: 206. pass 207. 208. if move_stu == 0 and command == 'no': 209. break 210. else: 211. speed = -speed 212. if step_input == 1: 213. for speed_I in range(0, (speed+int(speed/dpi)), int(speed/dpi)): 214. if move_stu and command == 'no': 215. speed_II = speed_I 216. speed_I = speed - speed_I 217. dove_Left_I(speed_I, 3*speed_II) 218. dove_Right_II(speed_I, 3*speed_II) 219. dove_Left_III(speed_I, 3*speed_II) 220. dove_Right_I(-speed_I, -10) 221. dove_Left_II(-speed_I, -10) 222. dove_Right_III(-speed_I, -10) 223. time.sleep(timeLast/dpi) 224. else: 225. pass 226. elif step_input == 2: 227. for speed_I in range(0, (speed+int(speed/dpi)), int(speed/dpi)): 228. if move_stu and command == 'no': 229. speed_II = speed_I 230. speed_I = speed - speed_I 231. dove_Left_I(-speed_II, 3*(speed-speed_II)) 232. dove_Right_II(-speed_II, 3*(speed-speed_II)) 233. dove_Left_III(-speed_II, 3*(speed-speed_II)) 234. dove_Right_I(speed_II, -10) 235. dove_Left_II(speed_II, -10) 236. dove_Right_III(speed_II, -10) 237. time.sleep(timeLast/dpi) 238. else: 239. pass 240. elif step_input == 3: 241. for speed_I in range(0, (speed+int(speed/dpi)), int(speed/dpi)): 242. if move_stu and command == 'no': 243. speed_II = speed_I 244. speed_I = speed - speed_I 245. dove_Left_I(-speed_I, -10) 246. dove_Right_II(-speed_I, -10) 247. dove_Left_III(-speed_I, -10) 248. dove_Right_I(speed_I, 3*speed_II) 249. dove_Left_II(speed_I, 3*speed_II) 250. dove_Right_III(speed_I, 3*speed_II) 251. time.sleep(timeLast/dpi) 252. else: 253. pass 254. elif step_input == 4: 255. for speed_I in range(0, (speed+int(speed/dpi)), int(speed/dpi)): 256. if move_stu and command == 'no': 257. speed_II = speed_I 258. speed_I = speed - speed_I 259. dove_Left_I(speed_II, -10) 260. dove_Right_II(speed_II, -10) 261. dove_Left_III(speed_II, -10) 262. dove_Right_I(-speed_II, 3*(speed-speed_II)) 263. dove_Left_II(-speed_II, 3*(speed-speed_II)) 264. dove_Right_III(-speed_II, 3*(speed-speed_II)) 265. time.sleep(timeLast/dpi) 266. else: 267. Pass |