NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
BigPuppy.cpp
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17  */
18 
29 //This application
30 #include "BigPuppy.h"
31 
32 // This library
33 #include "core/tgModel.h"
34 #include "core/tgSimView.h"
35 #include "core/tgSimViewGraphics.h"
36 #include "core/tgSimulation.h"
37 #include "core/tgWorld.h"
38 #include "core/tgBasicActuator.h"
39 #include "core/tgRod.h"
41 #include "core/tgString.h"
42 #include "tgcreator/tgBuildSpec.h"
44 #include "tgcreator/tgRodInfo.h"
45 #include "tgcreator/tgStructure.h"
47 // The Bullet Physics library
48 #include "LinearMath/btVector3.h"
49 // The C++ Standard Library
50 #include <iostream>
51 #include <stdexcept>
52 
53 BigPuppy::BigPuppy() :
54 tgModel()
55 {
56 }
57 
58 BigPuppy::~BigPuppy()
59 {
60 }
61 
62 void BigPuppy::setup(tgWorld& world)
63 {
64  //Rod and Muscle configuration
65 
66  const double density = 4.2/300.0; //Note: this needs to be high enough or things fly apart...
67  const double radius = 0.5;
68  const double friction = 0.5;
69  const double rollFriction = 0.0;
70  const double restitution = 0.0;
71  const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
72 
73  const double radius2 = 0.15;
74  const double density2 = 1; // Note: This needs to be high enough or things fly apart...
75  const tgRod::Config rodConfig2(radius2, density2);
76 
77  const double stiffness = 1000.0;
78  const double damping = .01*stiffness;
79  const double pretension = 0.0;
80 
81  const tgSpringCableActuator::Config stringConfig(stiffness, damping, pretension, false, 7000, 24);
82 
83 
84  const double passivePretension = 700; // 5 N
85  tgSpringCableActuator::Config muscleConfig(2000, 20, passivePretension);
86 
87  // Calculations for the flemons spine model
88  double v_size = 10.0;
89 
90  //Create basic unit for right leg
91  tgStructure rightLeg;
92 
93  //Right Leg nodes:
94  rightLeg.addNode(0,0,0); //0: Bottom Center of lower leg segment
95  rightLeg.addNode(0,10,0); //1: Center of lower leg segment
96  rightLeg.addNode(10,10,0); //2: Right of lower leg segment
97  rightLeg.addNode(-10,10,0); //3: Left of lower leg segment
98  rightLeg.addNode(0,20,0); //4: Top of lower leg segment
99  rightLeg.addNode(12,2,3); //5: Big toe; was y=0, z=5
100  rightLeg.addNode(12,1.5,-3.5); //6: Little toe; was y=0, z=-5
101  rightLeg.addNode(0,10,5); //7: Outer ankle
102  rightLeg.addNode(0,10,-5); //8: Inner ankle
103 
104  //Adding some extra nodes to stabilize base of leg:
105  rightLeg.addNode(4,0,0); //9
106  rightLeg.addNode(-4,0,0); //10
107  rightLeg.addNode(0,0,4); //11
108  rightLeg.addNode(0,0,-4); //12
109 
110  //Adding a toe extension
111  rightLeg.addNode(15,0,5); //13: Big toe
112  rightLeg.addNode(14,0,-5); //14: Little toe
113 
114  //Add rods for right leg:
115  rightLeg.addPair(0,1,"rod");
116  rightLeg.addPair(1,2,"rod");
117  rightLeg.addPair(1,3,"rod");
118  rightLeg.addPair(1,4,"rod");
119  rightLeg.addPair(5,8,"rod");
120  rightLeg.addPair(6,7,"rod");
121  //Toe extension rod
122  rightLeg.addPair(5,13,"rod");
123  rightLeg.addPair(6,14,"rod");
124 
125  rightLeg.addPair(0,9,"rod");
126  rightLeg.addPair(0,10,"rod");
127  rightLeg.addPair(0,11,"rod");
128  rightLeg.addPair(0,12,"rod");
129 
130  //Create basic unit for left leg
131  tgStructure leftLeg;
132 
133  //Left Leg nodes:
134  leftLeg.addNode(0,0,0); //0: Bottom Center of lower leg segment
135  leftLeg.addNode(0,10,0); //1: Center of lower leg segment
136  leftLeg.addNode(10,10,0); //2: Right of lower leg segment
137  leftLeg.addNode(-10,10,0); //3: Left of lower leg segment
138  leftLeg.addNode(0,20,0); //4: Top of lower leg segment
139  leftLeg.addNode(12,2,3); //5: Little toe; was y=0, z=5
140  leftLeg.addNode(12,1.5,-3.5); //6: Big toe; was y=0, z=-5
141  leftLeg.addNode(0,10,5); //7: Inner ankle
142  leftLeg.addNode(0,10,-5); //8: Outer ankle
143 
144  //Adding some extra nodes to stabilize base of leg:
145  leftLeg.addNode(4,0,0); //9
146  leftLeg.addNode(-4,0,0); //10
147  leftLeg.addNode(0,0,4); //11
148  leftLeg.addNode(0,0,-4); //12
149 
150  //Adding a toe extension
151  leftLeg.addNode(15,0,5); //13: Little toe
152  leftLeg.addNode(14,0,-5); //14: Big toe
153 
154  //Add rods for left leg:
155  leftLeg.addPair(0,1,"rod");
156  leftLeg.addPair(1,2,"rod");
157  leftLeg.addPair(1,3,"rod");
158  leftLeg.addPair(1,4,"rod");
159  leftLeg.addPair(5,8,"rod");
160  leftLeg.addPair(6,7,"rod");
161  //Toe extension rod
162  leftLeg.addPair(5,13,"rod");
163  leftLeg.addPair(6,14,"rod");
164 
165  leftLeg.addPair(0,9,"rod");
166  leftLeg.addPair(0,10,"rod");
167  leftLeg.addPair(0,11,"rod");
168  leftLeg.addPair(0,12,"rod");
169 
170  //Create the basic unit of the spine
171  tgStructure tetra;
172 
173 
174  //Add the nodes
175  tetra.addNode(0,0,0); //Node 0
176  tetra.addNode(v_size, 0, v_size); //Node 1
177  tetra.addNode(v_size, 0, -v_size); //Node 2
178  tetra.addNode(-v_size, 0, -v_size); //Node 3
179  tetra.addNode(-v_size, 0, v_size); //Node 4
180 
181  tetra.addPair(0,1,"rod");
182  tetra.addPair(0,2,"rod");
183  tetra.addPair(0,3,"rod");
184  tetra.addPair(0,4,"rod");
185 
186  //Create the basic unit for the hips/shoulders:
187  tgStructure lHip;
188 
189  lHip.addNode(0,0,0); //Node 0
190  lHip.addNode(0, v_size, v_size); //Node 1
191  lHip.addNode(0, -v_size, -v_size); //Node 2
192  lHip.addNode(0, -v_size, v_size); //Node 3
193 
194  lHip.addPair(0,1,"rod");
195  lHip.addPair(0,2,"rod");
196  lHip.addPair(0,3,"rod");
197 
198  tgStructure rHip;
199 
200  rHip.addNode(0,0,0); //Node 0
201  rHip.addNode(0, v_size, -v_size); //Node 1
202  rHip.addNode(0, -v_size, -v_size); //Node 2
203  rHip.addNode(0, -v_size, v_size); //Node 3
204 
205  rHip.addPair(0,1,"rod");
206  rHip.addPair(0,2,"rod");
207  rHip.addPair(0,3,"rod");
208 
209  //Build the spine
210  tgStructure spine;
211  const double offsetDist = v_size + 1; //So rod ends don't touch, may need to adjust
212  const double offsetDist2 = v_size*5 + 5 + 3.3;
213  const double offsetDist3 = v_size*6;
214  std::size_t m_segments = 6;
215  std::size_t m_hips = 4;
216  std::size_t m_legs = 4;
217  btVector3 offset(offsetDist,0.0,0);
218  btVector3 offset1(offsetDist*2,0.0,offsetDist);
219  btVector3 offset2(offsetDist2,0.0,offsetDist);
220  btVector3 offset3(offsetDist*2,0.0,-offsetDist);
221  btVector3 offset4(offsetDist2,0.0,-offsetDist);
222  btVector3 offset5(offsetDist3,-21.0,offsetDist);
223  btVector3 offset6(offsetDist3,-21.0,-offsetDist);
224  btVector3 offset7(v_size*2,-21.0,offsetDist);
225  btVector3 offset8(v_size*2,-21.0,-offsetDist);
226 
227  for(std::size_t i = 0; i < m_segments; i++) { //Connect segments for spine
228  tgStructure* t = new tgStructure (tetra);
229  t->addTags(tgString("segment num", i + 1));
230  t->move((i + 1)*offset);
231 
232  if (i % 2 == 1){
233 
234  t->addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0);
235 
236  }
237  else{
238 
239  t->addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0);
240 
241  }
242 
243  spine.addChild(t); //Add a segment to the spine
244  }
245 
246  for(std::size_t i = m_segments; i < (m_segments + 2); i++) {//deal with right hip and shoulder first
247  tgStructure* t = new tgStructure (rHip);
248  t->addTags(tgString("segment num", i + 1));
249 
250  if(i % 2 == 0){
251  t->move(offset1);
252  t->addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(1, 0, 0), 0.0);
253  }
254  else{
255  t->move(offset2);
256  t->addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 0, 1), M_PI*1/8);
257  }
258 
259  spine.addChild(t); //Add a segment to the spine
260  }
261 
262  for(std::size_t i = (m_segments + 2); i < (m_segments + m_hips); i++) {//deal with left hip and shoulder now
263  tgStructure* t = new tgStructure (lHip);
264  t->addTags(tgString("segment num", i + 1));
265 
266  if(i % 2 == 0){
267  t->move(offset3);
268  t->addRotation(btVector3(offsetDist*2, 0.0, -offsetDist), btVector3(1, 0, 0), 0.0);
269  }
270  else{
271  t->move(offset4);
272  t->addRotation(btVector3(offsetDist2, 0.0, -offsetDist), btVector3(0, 0, 1), M_PI*1/8);
273  }
274 
275  spine.addChild(t); //Add a segment to the spine
276 
277  }
278 
279  for(std::size_t i = (m_segments + m_hips); i < (m_segments + m_hips + 2); i++) {//right front and back legs
280  tgStructure* t = new tgStructure (rightLeg);
281  t->addTags(tgString("segment num", i + 1));
282 
283  if(i % 2 == 0){
284  t->move(offset7);
285  t->addRotation(btVector3(v_size*2, -21.0, offsetDist), btVector3(0, 1, 0), M_PI);
286  }
287  else{
288  t->move(offset5);
289  t->addRotation(btVector3(offsetDist3, -21.0, offsetDist), btVector3(0, 1, 0), M_PI);
290  }
291 
292  spine.addChild(t); //Add a segment to the spine
293  }
294 
295  for(std::size_t i = (m_segments + m_hips + 2); i < (m_segments + m_hips + m_legs); i++) {//left front and back legs
296  tgStructure* t = new tgStructure (leftLeg);
297  t->addTags(tgString("segment num", i + 1));
298 
299  if(i % 2 == 0){
300  t->move(offset8);
301  t->addRotation(btVector3(v_size*2, -21.0, -offsetDist), btVector3(0, 1, 0), M_PI);
302  }
303  else{
304  t->move(offset6);
305  t->addRotation(btVector3(offsetDist3, -21.0, -offsetDist), btVector3(0, 1, 0), M_PI);
306  }
307 
308  spine.addChild(t); //Add a segment to the spine
309  }
310 
311  spine.move(btVector3(0.0,21.0,0.0));
312 
313 
314  std::vector<tgStructure*> children = spine.getChildren();
315  for(std::size_t i = 2; i < (children.size() - (m_hips + m_legs)); i++) {
316 
317  tgNodes n0 = children[i-2]->getNodes();
318  tgNodes n1 = children[i-1]->getNodes();
319  tgNodes n2 = children[i]->getNodes();
320 
321 
322  if(i==2){
323  //Extra muscles, to keep front vertebra from swinging.
324  spine.addPair(n0[3], n1[3], tgString("spine front upper right muscle seg", i-2) + tgString(" seg", i-1));
325  spine.addPair(n0[3], n1[4], tgString("spine front upper left muscle seg", i-2) + tgString(" seg", i-1));
326 
327 
328  }
329 
330  //Add muscles to the spine
331  if(i < 3){
332  if(i % 2 == 0){ //front
333  spine.addPair(n0[1], n1[3], tgString("spine front lower right muscle seg", i-2) + tgString(" seg", i-1));
334  spine.addPair(n0[1], n1[4], tgString("spine front lower left muscle seg", i-2) + tgString(" seg", i-1));
335  spine.addPair(n0[2], n1[3], tgString("spine front upper right muscle seg", i-2) + tgString(" seg", i-1));
336  spine.addPair(n0[2], n1[4], tgString("spine front upper left muscle seg", i-2) + tgString(" seg", i-1));
337  }
338  else{ //rear
339  spine.addPair(n0[1], n1[3], tgString("spine rear upper left muscle seg", i-2) + tgString(" seg", i-1));
340  spine.addPair(n0[1], n1[4], tgString("spine rear lower left muscle seg", i-2) + tgString(" seg", i-1));
341  spine.addPair(n0[2], n1[3], tgString("spine rear upper right muscle seg", i-2) + tgString(" seg", i-1));
342  spine.addPair(n0[2], n1[4], tgString("spine rear lower right muscle seg", i-2) + tgString(" seg", i-1));
343  }
344  }
345  if(i < 6){
346  if(i % 2 == 0){
347  spine.addPair(n0[1], n2[4], tgString("spine bottom muscle seg", i-2) + tgString(" seg", i-1));
348  spine.addPair(n0[2], n2[3], tgString("spine top muscle seg", i-2) + tgString(" seg", i-1));
349  }
350  else{
351  spine.addPair(n0[1], n2[4], tgString("spine lateral left muscle seg", i-2) + tgString(" seg", i-1));
352  spine.addPair(n0[2], n2[3], tgString("spine lateral right muscle seg", i-2) + tgString(" seg", i-1));
353 
354  }
355  }
356  if(i > 0 && i < 5){
357  if(i % 2 == 0){//rear
358  spine.addPair(n1[1], n2[3], tgString("spine rear upper left muscle seg", i-1) + tgString(" seg", i));
359  spine.addPair(n1[1], n2[4], tgString("spine rear lower left muscle seg", i-1) + tgString(" seg", i));
360  spine.addPair(n1[2], n2[3], tgString("spine rear upper right muscle seg", i-1) + tgString(" seg", i));
361  spine.addPair(n1[2], n2[4], tgString("spine rear lower right muscle seg", i-1) + tgString(" seg", i));
362  }
363  else{//front
364 
365  spine.addPair(n1[1], n2[3], tgString("spine front lower right muscle seg", i-1) + tgString(" seg", i));
366  spine.addPair(n1[1], n2[4], tgString("spine front lower left muscle seg", i-1) + tgString(" seg", i));
367  spine.addPair(n1[2], n2[3], tgString("spine front upper right muscle seg", i-1) + tgString(" seg", i));
368  spine.addPair(n1[2], n2[4], tgString("spine front upper left muscle seg", i-1) + tgString(" seg", i));
369  }
370  }
371  if(i == 5){
372  //rear
373  spine.addPair(n1[1], n2[1], tgString("spine rear lower left muscle seg", i-1) + tgString(" seg", i));
374  spine.addPair(n1[1], n2[2], tgString("spine rear lower right muscle seg", i-1) + tgString(" seg", i));
375  spine.addPair(n1[2], n2[1], tgString("spine rear upper left muscle seg", i-1) + tgString(" seg", i));
376  spine.addPair(n1[2], n2[2], tgString("spine rear upper right muscle seg", i-1) + tgString(" seg", i));
377  //front
378  spine.addPair(n1[1], n2[3], tgString("spine front lower right muscle seg", i-1) + tgString(" seg", i));
379  spine.addPair(n1[1], n2[4], tgString("spine front lower left muscle seg", i-1) + tgString(" seg", i));
380  spine.addPair(n1[2], n2[3], tgString("spine front upper right muscle seg", i-1) + tgString(" seg", i));
381  spine.addPair(n1[2], n2[4], tgString("spine front upper left muscle seg", i-1) + tgString(" seg", i));
382 
383  }
384 
385  }
386 
387 
388  //Now add muscles to hips....
389  tgNodes n0 = children[0]->getNodes();
390  tgNodes n1 = children[1]->getNodes();
391  tgNodes n2 = children[2]->getNodes();
392  tgNodes n3 = children[3]->getNodes();
393  tgNodes n4 = children[4]->getNodes();
394  tgNodes n5 = children[5]->getNodes();
395  tgNodes n6 = children[6]->getNodes();
396  tgNodes n7 = children[7]->getNodes();
397  tgNodes n8 = children[8]->getNodes();
398  tgNodes n9 = children[9]->getNodes();
399  tgNodes n10 = children[10]->getNodes();
400  tgNodes n11 = children[11]->getNodes();
401  tgNodes n12 = children[12]->getNodes();
402  tgNodes n13 = children[13]->getNodes();
403 
404  //Left shoulder muscles
405  spine.addPair(n6[1], n1[1], tgString("left shoulder rear upper muscle seg", 6) + tgString(" seg", 1));
406  spine.addPair(n6[1], n1[4], tgString("left shoulder front upper muscle seg", 6) + tgString(" seg", 1));
407  spine.addPair(n6[1], n0[2], tgString("left shoulder front top muscle seg", 6) + tgString(" seg", 0));
408  spine.addPair(n6[1], n2[3], tgString("left shoulder rear top muscle seg", 6) + tgString(" seg", 2));
409 
410  spine.addPair(n6[2], n1[1], tgString("left shoulder rear lower muscle seg", 6) + tgString(" seg", 1));
411  spine.addPair(n6[2], n1[4], tgString("left shoulder front lower muscle seg", 6) + tgString(" seg", 1));
412  spine.addPair(n6[2], n0[1], tgString("left shoulder front bottom muscle seg", 6) + tgString(" seg", 0));
413  spine.addPair(n6[2], n2[4], tgString("left shoulder rear bottom muscle seg", 6) + tgString(" seg", 2));
414 
415  //Extra muscles, to move left shoulder forward and back:
416  spine.addPair(n6[0], n1[1], tgString("left shoulder rear mid muscle seg", 6) + tgString(" seg", 1));
417  spine.addPair(n6[0], n1[4], tgString("left shoulder front mid muscle seg", 6) + tgString(" seg", 1));
418 
419  //Left hip muscles
420  spine.addPair(n7[1], n5[1], tgString("left hip rear upper muscle seg", 7) + tgString(" seg", 5));
421  spine.addPair(n7[1], n5[4], tgString("left hip front upper muscle seg", 7) + tgString(" seg", 5));
422  spine.addPair(n7[1], n4[2], tgString("left hip rear top muscle seg", 7) + tgString(" seg", 4));
423  spine.addPair(n7[1], n4[3], tgString("left hip front top muscle seg", 7) + tgString(" seg", 4));
424 
425  spine.addPair(n7[2], n5[1], tgString("left hip rear lower muscle seg", 7) + tgString(" seg", 5));
426  spine.addPair(n7[2], n5[4], tgString("left hip front lower muscle seg", 7) + tgString(" seg", 5));
427  spine.addPair(n7[2], n4[1], tgString("left hip bottom muscle seg", 7) + tgString(" seg", 4));
428 
429  //Extra muscles, to move left hip forward and back:
430  spine.addPair(n7[0], n3[1], tgString("left hip rear mid muscle seg", 7) + tgString(" seg", 3)); //could also be n3[3]
431  spine.addPair(n7[0], n5[4], tgString("left hip front mid muscle seg", 7) + tgString(" seg", 5));
432 
433  //Inter-hip connector muscle
434  spine.addPair(n7[2], n9[3], tgString("inter-hip bottom muscle seg", 7) + tgString(" seg", 9)); //inter-hip bottom muscle
435 
436  //Right shoulder muscles
437  spine.addPair(n8[1], n1[2], tgString("right shoulder rear upper muscle seg", 8) + tgString(" seg", 1));
438  spine.addPair(n8[1], n1[3], tgString("right shoulder front upper muscle seg", 8) + tgString(" seg", 1));
439  spine.addPair(n8[1], n0[2], tgString("right shoulder front top muscle seg", 8) + tgString(" seg", 0));
440  spine.addPair(n8[1], n2[3], tgString("right shoulder rear top muscle seg", 8) + tgString(" seg", 2));
441 
442  spine.addPair(n8[3], n1[2], tgString("right shoulder rear lower muscle seg", 8) + tgString(" seg", 1));
443  spine.addPair(n8[3], n1[3], tgString("right shoulder front lower muscle seg", 8) + tgString(" seg", 1));
444  spine.addPair(n8[3], n0[1], tgString("right shoulder front bottom muscle seg", 8) + tgString(" seg", 0));
445  spine.addPair(n8[3], n2[4], tgString("right shoulder rear bottom muscle seg", 8) + tgString(" seg", 2));
446 
447  //Extra muscles, to move right shoulder forward and back:
448  spine.addPair(n8[0], n1[2], tgString("right shoulder rear mid muscle seg", 8) + tgString(" seg", 1));
449  spine.addPair(n8[0], n1[3], tgString("right shoulder front mid muscle seg", 8) + tgString(" seg", 1));
450 
451  //Right hip muscles
452  spine.addPair(n9[1], n5[2], tgString("right hip rear upper muscle seg", 9) + tgString(" seg", 5));
453  spine.addPair(n9[1], n5[3], tgString("right hip front upper muscle seg", 9) + tgString(" seg", 5));
454  spine.addPair(n9[1], n4[2], tgString("right hip rear top muscle seg", 9) + tgString(" seg", 4));
455  spine.addPair(n9[1], n4[3], tgString("right hip front top muscle seg", 9) + tgString(" seg", 4));
456 
457  spine.addPair(n9[3], n5[2], tgString("right hip rear lower muscle seg", 9) + tgString(" seg", 5));
458  spine.addPair(n9[3], n5[3], tgString("right hip front lower muscle seg", 9) + tgString(" seg", 5));
459  spine.addPair(n9[3], n4[1], tgString("right hip bottom muscle seg", 9) + tgString(" seg", 4));
460 
461  //Extra muscles, to move right hip forward and back:
462  spine.addPair(n9[0], n3[2], tgString("right hip rear mid muscle seg", 9) + tgString(" seg", 3)); //could also be n3[3]
463  spine.addPair(n9[0], n5[3], tgString("right hip front mid muscle seg", 9) + tgString(" seg", 5));
464 
465  //Leg/hip connections:
466 
467  //Right front leg/shoulder
468  spine.addPair(n10[4], n6[2], tgString("right outer bicep muscle seg", 10) + tgString(" seg", 6));
469  spine.addPair(n10[4], n6[3], tgString("right inner bicep muscle seg", 10) + tgString(" seg", 6));
470  //spine.addPair(n10[4], n1[1], tgString("right front abdomen connection muscle seg", 10) + tgString(" seg", 1));
471 
472  spine.addPair(n10[3], n6[2], tgString("right outer tricep muscle seg", 10) + tgString(" seg", 6));
473  spine.addPair(n10[3], n6[3], tgString("right inner tricep muscle seg", 10) + tgString(" seg", 6));
474 
475  spine.addPair(n10[2], n6[2], tgString("right outer front tricep muscle seg", 10) + tgString(" seg", 6));
476  spine.addPair(n10[2], n6[3], tgString("right inner front tricep muscle seg", 10) + tgString(" seg", 6));
477 
478  //Adding muscle to pull up on right front leg:
479  spine.addPair(n10[4], n6[1], tgString("right mid bicep muscle seg", 10) + tgString(" seg", 6));
480 
481  //Left front leg/shoulder
482  spine.addPair(n12[4], n8[2], tgString("left inner bicep muscle seg", 12) + tgString(" seg", 8));
483  spine.addPair(n12[4], n8[3], tgString("left outer bicep muscle seg", 12) + tgString(" seg", 8));
484  //spine.addPair(n12[4], n1[2], tgString("left front abdomen connection muscle seg", 12) + tgString(" seg", 1)); //Was n1[2]
485 
486  spine.addPair(n12[3], n8[2], tgString("left inner tricep muscle seg", 12) + tgString(" seg", 8));
487  spine.addPair(n12[3], n8[3], tgString("left outer tricep muscle seg", 12) + tgString(" seg", 8));
488 
489  spine.addPair(n12[2], n8[2], tgString("left inner front tricep muscle seg", 12) + tgString(" seg", 8));
490  spine.addPair(n12[2], n8[3], tgString("left outer front tricep muscle seg", 12) + tgString(" seg", 8));
491 
492  //Adding muscle to pull up on left front leg:
493  spine.addPair(n12[4], n8[1], tgString("left mid bicep muscle seg", 12) + tgString(" seg", 8));
494 
495  //Right rear leg/hip
496  spine.addPair(n11[4], n7[2], tgString("right outer thigh muscle seg", 11) + tgString(" seg", 7));
497  spine.addPair(n11[4], n7[3], tgString("right inner thigh muscle seg", 11) + tgString(" seg", 7));
498  //spine.addPair(n11[4], n3[1],tgString("right rear abdomen connection muscle seg", 11) + tgString(" seg", 4));
499 
500  spine.addPair(n11[3], n7[2], tgString("right outer calf muscle seg", 11) + tgString(" seg", 7));
501  spine.addPair(n11[3], n7[3], tgString("right inner calf muscle seg", 11) + tgString(" seg", 7));
502 
503  spine.addPair(n11[2], n7[2], tgString("right outer front calf muscle seg", 11) + tgString(" seg", 7));
504  spine.addPair(n11[2], n7[3], tgString("right inner front calf muscle seg", 11) + tgString(" seg", 7));
505 
506  //Adding muscle to pull rear right leg up:
507  spine.addPair(n11[4], n7[1], tgString("right central thigh muscle seg", 11) + tgString(" seg", 7));
508 
509  //Left rear leg/hip
510  spine.addPair(n13[4], n9[2], tgString("left inner thigh muscle seg", 13) + tgString(" seg", 9));
511  spine.addPair(n13[4], n9[3], tgString("left outer thigh muscle seg", 13) + tgString(" seg", 9));
512  //spine.addPair(n13[4], n3[2], tgString("left rear abdomen connection muscle seg", 13) + tgString(" seg", 4));
513 
514  spine.addPair(n13[3], n9[2], tgString("left inner calf muscle seg", 13) + tgString(" seg", 9));
515  spine.addPair(n13[3], n9[3], tgString("left outer calf muscle seg", 13) + tgString(" seg", 9));
516 
517  spine.addPair(n13[2], n9[2], tgString("left inner front calf muscle seg", 13) + tgString(" seg", 9));
518  spine.addPair(n13[2], n9[3], tgString("left outer front calf muscle seg", 13) + tgString(" seg", 9));
519 
520  //Adding muscle to pull rear left leg up:
521  spine.addPair(n13[4], n9[1], tgString("left central thigh muscle seg", 13) + tgString(" seg", 9));
522 
523  //Populate Legs with muscles
524  for(std::size_t i = (m_segments + m_hips); i < children.size(); i++) {
525 
526  tgNodes ni = children[i]->getNodes();
527 
528  if(i < (m_segments + m_legs + 2)){
529 
530  spine.addPair(ni[5], ni[7], tgString("right leg big outer muscle seg", i));
531  spine.addPair(ni[6], ni[8], tgString("right leg little inner muscle seg", i));
532  spine.addPair(ni[5], ni[6], tgString("right leg big little muscle seg", i));
533  spine.addPair(ni[0], ni[7], tgString("right leg lower outer muscle seg", i));
534  spine.addPair(ni[0], ni[8], tgString("right leg lower inner muscle seg", i));
535  spine.addPair(ni[2], ni[7], tgString("right leg front outer muscle seg", i));
536  spine.addPair(ni[2], ni[8], tgString("right leg front inner muscle seg", i));
537  spine.addPair(ni[3], ni[7], tgString("right leg heel outer muscle seg", i));
538  spine.addPair(ni[3], ni[8], tgString("right leg heel inner muscle seg", i));
539  spine.addPair(ni[4], ni[7], tgString("right leg upper outer muscle seg", i));
540  spine.addPair(ni[4], ni[8], tgString("right leg upper inner muscle seg", i));
541 
542  }
543  else{
544 
545  spine.addPair(ni[5], ni[7], tgString("left leg litte inner muscle seg", i));
546  spine.addPair(ni[6], ni[8], tgString("left leg big outer muscle seg", i));
547  spine.addPair(ni[5], ni[6], tgString("left leg big little muscle seg", i));
548  spine.addPair(ni[0], ni[7], tgString("left leg lower inner muscle seg", i));
549  spine.addPair(ni[0], ni[8], tgString("left leg lower outer muscle seg", i));
550  spine.addPair(ni[2], ni[7], tgString("left leg front inner muscle seg", i));
551  spine.addPair(ni[2], ni[8], tgString("left leg front outer muscle seg", i));
552  spine.addPair(ni[3], ni[7], tgString("left leg heel inner muscle seg", i));
553  spine.addPair(ni[3], ni[8], tgString("left leg heel outer muscle seg", i));
554  spine.addPair(ni[4], ni[7], tgString("left leg upper inner muscle seg", i));
555  spine.addPair(ni[4], ni[8], tgString("left leg upper outer muscle seg", i));
556 
557  }
558 
559  }
560 
561  // Create the build spec that uses tags to turn the structure into a real model
562  tgBuildSpec spec;
563  spec.addBuilder("rod", new tgRodInfo(rodConfig));
564  spec.addBuilder("muscle", new tgBasicActuatorInfo(muscleConfig));
565 
566  // Create your structureInfo
567  tgStructureInfo structureInfo(spine, spec);
568 
569  // Use the structureInfo to build ourselves
570  structureInfo.buildInto(*this, world);
571 
572  // We could now use tgCast::filter or similar to pull out the
573  // models (e.g. muscles) that we want to control.
574  allActuators = tgCast::filter<tgModel, tgSpringCableActuator> (getDescendants());
575 
576  // Notify controllers that setup has finished.
577  notifySetup();
578 
579  // Actually setup the children
580  tgModel::setup(world);
581 
582  children.clear();
583 }
584 
585 void BigPuppy::step(double dt)
586 {
587  // Precondition
588  if (dt <= 0.0)
589  {
590  throw std::invalid_argument("dt is not positive");
591  }
592  else
593  {
594  // Notify observers (controllers) of the step so that they can take action
595  notifyStep(dt);
596  tgModel::step(dt); // Step any children
597  }
598 }
599 
600 const std::vector<tgSpringCableActuator*>& BigPuppy::getAllActuators() const
601 {
602  return allActuators;
603 }
604 
605 void BigPuppy::teardown()
606 {
607  notifyTeardown();
609 }
const std::vector< tgStructure * > & getChildren() const
Definition: tgStructure.h:184
virtual void teardown()
Definition: tgModel.cpp:68
virtual void setup(tgWorld &world)
Definition: tgModel.cpp:57
void addChild(tgStructure *child)
Definition of class tgRodInfo.
virtual void step(double dt)
Definition: BigPuppy.cpp:677
const std::vector< tgSpringCableActuator * > & getAllActuators() const
Definition: BigPuppy.cpp:692
Convenience function for combining strings with ints, mostly for naming structures.
virtual void step(double dt)
Definition: tgModel.cpp:84
virtual void teardown()
Definition: BigPuppy.cpp:697
Definition of class tgBasicActuatorInfo.
Contains the definition of class tgSimulation.
Contains the definition of class tgModel.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Definition: tgStructure.cpp:80
Contains the definition of class tgSimViewGraphics.
Contains the definition of abstract base class tgSpringCableActuator. Assumes that the string is line...
void addRotation(const btVector3 &fixedPoint, const btVector3 &axis, double angle)
Contains the definition of class tgBasicActuator.
std::string tgString(std::string s, int i)
Definition: tgString.h:33
Contains the definition of class tgWorld $Id$.
Definition of class tgStructure.
Definition of class tgStructureInfo.
Contains the definition of class tgSimView.
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
void notifyStep(double dt)
virtual void setup(tgWorld &world)
Definition: BigPuppy.cpp:62
std::vector< tgModel * > getDescendants() const
Definition: tgModel.cpp:170
void addNode(double x, double y, double z, std::string tags="")
Definition: tgStructure.cpp:70