NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
BigPuppyNoFeet.cpp
Go to the documentation of this file.
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 "BigPuppyNoFeet.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"
41 #include "core/tgRod.h"
43 #include "core/tgString.h"
44 #include "tgcreator/tgBuildSpec.h"
46 #include "tgcreator/tgRodInfo.h"
47 #include "tgcreator/tgStructure.h"
49 // The Bullet Physics library
50 #include "LinearMath/btVector3.h"
51 // The C++ Standard Library
52 #include <iostream>
53 #include <stdexcept>
54 
55 //#define USE_KINEMATIC
56 #define PASSIVE_STRUCTURE
57 
58 BigPuppyNoFeet::BigPuppyNoFeet(int segments, int hips, int legs, int feet) :
59 BaseSpineModelLearning(segments),
60 m_hips(hips),
61 m_legs(legs),
62 m_feet(feet)
63 {
64 }
65 
66 BigPuppyNoFeet::~BigPuppyNoFeet()
67 {
68 }
69 
70 void BigPuppyNoFeet::addNodesFoot(tgStructure& s, double r1, double r2){
71  s.addNode(r2,0,r2);//0
72  s.addNode(r2,0,-r2);//1
73  s.addNode(-r2,0,-r2);//2
74  s.addNode(-r2,0,r2);//3
75  s.addNode(r2/2,r1/2,0);//4
76  s.addNode(0,r1/2,-r2/2);//5
77  s.addNode(-r2/2,r1/2,0);//6
78  s.addNode(0,r1/2,r2/2);//7
79 }
80 
81 void BigPuppyNoFeet::addRodsFoot(tgStructure& s){
82  s.addPair(0,6,"rod");
83  s.addPair(1,7,"rod");
84  s.addPair(2,4,"rod");
85  s.addPair(3,5,"rod");
86 }
87 
88 void BigPuppyNoFeet::addNodesLeg(tgStructure& s, double r){
89  s.addNode(0,0,0); //0: Bottom Center of lower leg segment
90  s.addNode(0,r,0); //1: Center of lower leg segment
91  s.addNode(r,r,0); //2: Right of lower leg segment
92  s.addNode(-r,r,0); //3: Left of lower leg segment
93  s.addNode(0,2*r,0); //4: Top of lower leg segment
94  s.addNode(0,-r/2,0); //5: Leg segment extension for connections to foot.
95 }
96 
97 void BigPuppyNoFeet::addRodsLeg(tgStructure& s){
98  s.addPair(0,1,"rod");
99  s.addPair(1,2,"rod");
100  s.addPair(1,3,"rod");
101  s.addPair(1,4,"rod");
102  s.addPair(0,5,"rod");
103 }
104 
105 void BigPuppyNoFeet::addNodesHip(tgStructure& s, double r){
106  s.addNode(0,0,0); //Node 0
107  s.addNode(0,r,r); //Node 1
108  s.addNode(0,-r,-r); //Node 2
109  s.addNode(0,-r,r); //Node 3
110 }
111 
112 void BigPuppyNoFeet::addRodsHip(tgStructure& s){
113  s.addPair(0,1,"rod");
114  s.addPair(0,2,"rod");
115  s.addPair(0,3,"rod");
116 }
117 
118 void BigPuppyNoFeet::addNodesVertebra(tgStructure& s, double r){
119  s.addNode(0,0,0); //Node 0
120  s.addNode(r,0,r); //Node 1
121  s.addNode(r,0,-r); //Node 2
122  s.addNode(-r,0,-r); //Node 3
123  s.addNode(-r,0,r); //Node 4
124 }
125 
126 void BigPuppyNoFeet::addRodsVertebra(tgStructure& s){
127  s.addPair(0,1,"rod");
128  s.addPair(0,2,"rod");
129  s.addPair(0,3,"rod");
130  s.addPair(0,4,"rod");
131 }
132 
133 void BigPuppyNoFeet::addSegments(tgStructure& puppy, tgStructure& vertebra, tgStructure& hip, tgStructure& leg,
134  double r){
135  const double offsetDist = r+1;
136  const double offsetDist2 = offsetDist*6;
137  const double offsetDist3 = offsetDist2+2;
138  const double yOffset_leg = -(2*r+1);
139  const double yOffset_foot = -(2*r+6);
140 
141  //Vertebrae
142  btVector3 offset(offsetDist,0.0,0);
143  //Hips
144  btVector3 offset1(offsetDist*2,0.0,offsetDist);
145  btVector3 offset2(offsetDist2,0.0,offsetDist);
146  btVector3 offset3(offsetDist*2,0.0,-offsetDist);
147  btVector3 offset4(offsetDist2,0.0,-offsetDist);
148  //Lower legs
149  btVector3 offset5(offsetDist3,yOffset_leg,offsetDist);
150  btVector3 offset6(offsetDist3,yOffset_leg,-offsetDist);
151  btVector3 offset7(r*2,yOffset_leg,offsetDist);
152  btVector3 offset8(r*2,yOffset_leg,-offsetDist);
153  //Feet
154  btVector3 offset9(offsetDist3+1,yOffset_foot,offsetDist);
155  btVector3 offset10(offsetDist3+1,yOffset_foot,-offsetDist);
156  btVector3 offset11(r*2+1,yOffset_foot,offsetDist);
157  btVector3 offset12(r*2+1,yOffset_foot,-offsetDist);
158 
159  for(std::size_t i = 0; i < m_segments; i++) { //Connect segments for spine of puppy
160  tgStructure* t = new tgStructure (vertebra);
161  t->addTags(tgString("spine segment num", i + 1));
162  t->move((i + 1)*offset);
163 
164  if (i % 2 == 1){
165 
166  t->addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), 0.0);
167 
168  }
169  else{
170 
171  t->addRotation(btVector3((i + 1) * offsetDist, 0.0, 0.0), btVector3(1, 0, 0), M_PI/2.0);
172 
173  }
174 
175  puppy.addChild(t); //Add a segment to the puppy
176  }
177 
178  for(std::size_t i = m_segments; i < (m_segments + 2); i++) {//deal with right hip and shoulder first
179  tgStructure* t = new tgStructure (hip);
180  t->addTags(tgString("segment num", i + 1));
181 
182  if(i % 2 == 0){
183  t->move(offset2);
184  t->addRotation(btVector3(offsetDist2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
185 
186  }
187  else{
188  t->move(offset1);
189  t->addRotation(btVector3(offsetDist*2, 0.0, offsetDist), btVector3(0, 1, 0), M_PI);
190  }
191 
192  puppy.addChild(t); //Add a segment to the puppy
193  }
194 
195  for(std::size_t i = (m_segments + 2); i < (m_segments + m_hips); i++) {//deal with left hip and shoulder now
196  tgStructure* t = new tgStructure (hip);
197  t->addTags(tgString("segment num", i + 1));
198 
199  if(i % 2 == 0){
200  t->move(offset4);
201  }
202  else{
203  t->move(offset3);
204  }
205 
206  puppy.addChild(t); //Add a segment to the puppy
207 
208  }
209 
210  for(std::size_t i = (m_segments + m_hips); i < (m_segments + m_hips + 2); i++) {//right front and back legs
211  tgStructure* t = new tgStructure (leg);
212  t->addTags(tgString("segment num", i + 1));
213 
214  if(i % 2 == 0){
215  t->move(offset5);
216  t->addRotation(btVector3(offsetDist3, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
217 
218  }
219  else{
220  t->move(offset7);
221  t->addRotation(btVector3(r*2, yOffset_leg, offsetDist), btVector3(0, 1, 0), M_PI);
222  //the rotations for the legs are a remnant of the earlier design. Removing them now
223  //would mean changing all my muscle attachments. I will do this someday.
224 
225  }
226 
227  puppy.addChild(t); //Add a segment to the puppy
228  }
229 
230  for(std::size_t i = (m_segments + m_hips + 2); i < (m_segments + m_hips + m_legs); i++) {//left front and back legs
231  tgStructure* t = new tgStructure (leg);
232  t->addTags(tgString("segment num", i + 1));
233 
234  if(i % 2 == 0){
235  t->move(offset6);
236  t->addRotation(btVector3(offsetDist3, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
237 
238  }
239  else{
240  t->move(offset8);
241  t->addRotation(btVector3(r*2, yOffset_leg, -offsetDist), btVector3(0, 1, 0), M_PI);
242  }
243 
244  puppy.addChild(t); //Add a segment to the puppy
245  }
246 
247  /*for(std::size_t i = (m_segments + m_hips + m_legs); i < (m_segments + m_hips + m_legs + 2); i++) {//right front and back feet
248  tgStructure* t = new tgStructure (foot);
249  t->addTags(tgString("segment num", i + 1));
250 
251  if(i % 2 == 0){
252  t->move(offset9);
253  t->addRotation(btVector3(offsetDist3+1, yOffset_foot, offsetDist), btVector3(0, 1, 0), 0.0);
254 
255  }
256  else{
257  t->move(offset11);
258  t->addRotation(btVector3(r*2+1, yOffset_foot, offsetDist), btVector3(0, 1, 0), 0.0);
259  }
260 
261  puppy.addChild(t); //Add a segment to the puppy
262  }
263 
264  for(std::size_t i = (m_segments + m_hips + m_legs + 2); i < (m_segments + m_hips + m_legs + m_feet); i++) {//left front and back feet
265  tgStructure* t = new tgStructure (foot);
266  t->addTags(tgString("segment num", i + 1));
267 
268  if(i % 2 == 0){
269  t->move(offset10);
270  t->addRotation(btVector3(offsetDist3+1, yOffset_foot, -offsetDist), btVector3(0, 1, 0), 0.0);
271 
272  }
273  else{
274  t->move(offset12);
275  t->addRotation(btVector3(r*2+1, yOffset_foot, -offsetDist), btVector3(0, 1, 0), 0.0);
276  }
277 
278  puppy.addChild(t); //Add a segment to the puppy
279  }*/
280 }
281 
282 void BigPuppyNoFeet::addMuscles(tgStructure& puppy){
283  //Time to add the muscles to the structure. Todo: try to clean this up some more.
284  std::vector<tgStructure*> children = puppy.getChildren();
285  for(std::size_t i = 2; i < (children.size() - (m_hips + m_legs)); i++) {
286 
287  tgNodes n0 = children[i-2]->getNodes();
288  tgNodes n1 = children[i-1]->getNodes();
289  tgNodes n2 = children[i]->getNodes();
290 
291 
292  if(i==2){
293  //Extra muscles, to keep front vertebra from swinging.
294  puppy.addPair(n0[3], n1[3], tgString("spine front upper right muscleAct seg", i-2) + tgString(" seg", i-1));
295  puppy.addPair(n0[3], n1[4], tgString("spine front upper left muscleAct seg", i-2) + tgString(" seg", i-1));
296 
297  puppy.addPair(n0[4], n1[3], tgString("spine front lower right muscleAct seg", i-2) + tgString(" seg", i-1));
298  puppy.addPair(n0[4], n1[4], tgString("spine front lower left muscleAct seg", i-2) + tgString(" seg", i-1));
299 
300 
301  }
302 
303  //Add muscles to the puppy
304  if(i < 3){
305  if(i % 2 == 0){ //front
306  puppy.addPair(n0[1], n1[3], tgString("spine front lower right muscleAct seg", i-2) + tgString(" seg", i-1));
307  puppy.addPair(n0[1], n1[4], tgString("spine front lower left muscleAct seg", i-2) + tgString(" seg", i-1));
308  puppy.addPair(n0[2], n1[3], tgString("spine front upper right muscleAct seg", i-2) + tgString(" seg", i-1));
309  puppy.addPair(n0[2], n1[4], tgString("spine front upper left muscleAct seg", i-2) + tgString(" seg", i-1));
310  }
311  else{ //rear
312  puppy.addPair(n0[1], n1[3], tgString("spine rear upper left muscleAct seg", i-2) + tgString(" seg", i-1));
313  puppy.addPair(n0[1], n1[4], tgString("spine rear lower left muscleAct seg", i-2) + tgString(" seg", i-1));
314  puppy.addPair(n0[2], n1[3], tgString("spine rear upper right muscleAct seg", i-2) + tgString(" seg", i-1));
315  puppy.addPair(n0[2], n1[4], tgString("spine rear lower right muscleAct seg", i-2) + tgString(" seg", i-1));
316  }
317  }
318  if(i < 7){//Was 6
319  if(i % 2 == 0){
320  puppy.addPair(n0[1], n2[4], tgString("spine2 bottom muscleAct seg", i-2) + tgString(" seg", i-1));
321  puppy.addPair(n0[2], n2[3], tgString("spine2 top muscleAct seg", i-2) + tgString(" seg", i-1));
322  }
323  else{
324  puppy.addPair(n0[1], n2[4], tgString("spine2 lateral left muscleAct seg", i-2) + tgString(" seg", i-1));
325  puppy.addPair(n0[2], n2[3], tgString("spine2 lateral right muscleAct seg", i-2) + tgString(" seg", i-1));
326 
327  }
328  }
329  if(i > 0 && i < 7){
330  if(i % 2 == 0){//rear
331  puppy.addPair(n1[1], n2[3], tgString("spine rear upper left muscleAct seg", i-1) + tgString(" seg", i));
332  puppy.addPair(n1[1], n2[4], tgString("spine rear lower left muscleAct seg", i-1) + tgString(" seg", i));
333  puppy.addPair(n1[2], n2[3], tgString("spine rear upper right muscleAct seg", i-1) + tgString(" seg", i));
334  puppy.addPair(n1[2], n2[4], tgString("spine rear lower right muscleAct seg", i-1) + tgString(" seg", i));
335  }
336  else{//front
337 
338  puppy.addPair(n1[1], n2[3], tgString("spine front lower right muscleAct seg", i-1) + tgString(" seg", i));
339  puppy.addPair(n1[1], n2[4], tgString("spine front lower left muscleAct seg", i-1) + tgString(" seg", i));
340  puppy.addPair(n1[2], n2[3], tgString("spine front upper right muscleAct seg", i-1) + tgString(" seg", i));
341  puppy.addPair(n1[2], n2[4], tgString("spine front upper left muscleAct seg", i-1) + tgString(" seg", i));
342  }
343  }
344  if(i == 6){
345  //rear
346  puppy.addPair(n1[1], n2[2], tgString("spine rear lower left muscleAct seg", i-1) + tgString(" seg", i));
347  puppy.addPair(n1[2], n2[2], tgString("spine rear lower right muscleAct seg", i-1) + tgString(" seg", i));
348  puppy.addPair(n1[1], n2[1], tgString("spine rear upper left muscleAct seg", i-1) + tgString(" seg", i));
349  puppy.addPair(n1[2], n2[1], tgString("spine rear upper right muscleAct seg", i-1) + tgString(" seg", i));
350  }
351 
352  }
353 
354 
355  //Now add muscles to hips....
356  tgNodes n0 = children[0]->getNodes();
357  tgNodes n1 = children[1]->getNodes();
358  tgNodes n2 = children[2]->getNodes();
359  tgNodes n3 = children[3]->getNodes();
360  tgNodes n4 = children[4]->getNodes();
361  tgNodes n5 = children[5]->getNodes();
362  tgNodes n6 = children[6]->getNodes();
363  tgNodes n7 = children[7]->getNodes();
364  tgNodes n8 = children[8]->getNodes();
365  tgNodes n9 = children[9]->getNodes();
366  tgNodes n10 = children[10]->getNodes();
367  tgNodes n11 = children[11]->getNodes();
368  tgNodes n12 = children[12]->getNodes();
369  tgNodes n13 = children[13]->getNodes();
370  tgNodes n14 = children[14]->getNodes();
371 
372  //Left shoulder muscles
373  puppy.addPair(n7[1], n1[1], tgString("left shoulder rear upper muscleAct seg", 6) + tgString(" seg", 1));
374  puppy.addPair(n7[1], n1[4], tgString("left shoulder front upper muscleAct seg", 6) + tgString(" seg", 1));
375  puppy.addPair(n7[1], n0[2], tgString("left shoulder front top muscleAct seg", 6) + tgString(" seg", 0));
376  puppy.addPair(n7[1], n2[3], tgString("left shoulder rear top muscleAct seg", 6) + tgString(" seg", 2));
377 
378  puppy.addPair(n7[3], n1[1], tgString("left shoulder rear lower muscleAct seg", 6) + tgString(" seg", 1));
379  puppy.addPair(n7[3], n1[4], tgString("left shoulder front lower muscleAct seg", 6) + tgString(" seg", 1));
380  puppy.addPair(n7[3], n0[1], tgString("left shoulder front bottom muscleAct seg", 6) + tgString(" seg", 0));
381  puppy.addPair(n7[3], n2[4], tgString("left shoulder rear bottom muscleAct seg", 6) + tgString(" seg", 2));
382 
383  //Extra muscles, to move left shoulder forward and back:
384  puppy.addPair(n7[0], n1[1], tgString("left shoulder rear mid muscleAct seg", 6) + tgString(" seg", 1));
385  puppy.addPair(n7[0], n1[4], tgString("left shoulder front mid muscleAct seg", 6) + tgString(" seg", 1));
386 
387  //Left hip muscles
388  puppy.addPair(n8[1], n5[1], tgString("left hip rear upper muscleAct seg", 7) + tgString(" seg", 5));
389  puppy.addPair(n8[1], n5[4], tgString("left hip front upper muscleAct seg", 7) + tgString(" seg", 5));
390  puppy.addPair(n8[1], n4[2], tgString("left hip front top muscleAct seg", 7) + tgString(" seg", 4));
391  puppy.addPair(n8[1], n6[3], tgString("left hip rear top muscleAct seg", 7) + tgString(" seg", 4));
392 
393  puppy.addPair(n8[3], n5[1], tgString("left hip rear lower muscleAct seg", 7) + tgString(" seg", 5));
394  puppy.addPair(n8[3], n5[4], tgString("left hip front lower muscleAct seg", 7) + tgString(" seg", 5));
395  puppy.addPair(n8[3], n4[1], tgString("left hip front bottom muscleAct seg", 7) + tgString(" seg", 4));
396  puppy.addPair(n8[3], n6[4], tgString("left hip front bottom muscleAct seg", 7) + tgString(" seg", 6));
397 
398  //Extra muscles, to move left hip forward and back:
399  puppy.addPair(n8[0], n5[1], tgString("left hip rear mid muscleAct seg", 7) + tgString(" seg", 3)); //could also be n3[3]
400  puppy.addPair(n8[0], n5[4], tgString("left hip front mid muscleAct seg", 7) + tgString(" seg", 5));
401 
402  //Right shoulder muscles
403  puppy.addPair(n9[1], n1[2], tgString("right shoulder rear upper muscleAct seg", 8) + tgString(" seg", 1));
404  puppy.addPair(n9[1], n1[3], tgString("right shoulder front upper muscleAct seg", 8) + tgString(" seg", 1));
405  puppy.addPair(n9[1], n0[2], tgString("right shoulder front top muscleAct seg", 8) + tgString(" seg", 0));
406  puppy.addPair(n9[1], n2[3], tgString("right shoulder rear top muscleAct seg", 8) + tgString(" seg", 2));
407 
408  puppy.addPair(n9[3], n1[2], tgString("right shoulder rear lower muscleAct seg", 8) + tgString(" seg", 1));
409  puppy.addPair(n9[3], n1[3], tgString("right shoulder front lower muscleAct seg", 8) + tgString(" seg", 1));
410  puppy.addPair(n9[3], n0[1], tgString("right shoulder front bottom muscleAct seg", 8) + tgString(" seg", 0));
411  puppy.addPair(n9[3], n2[4], tgString("right shoulder rear bottom muscleAct seg", 8) + tgString(" seg", 2));
412 
413  //Extra muscles, to move right shoulder forward and back:
414  puppy.addPair(n9[0], n1[2], tgString("right shoulder rear mid muscleAct seg", 8) + tgString(" seg", 1));
415  puppy.addPair(n9[0], n1[3], tgString("right shoulder front mid muscleAct seg", 8) + tgString(" seg", 1));
416 
417  //Right hip muscles
418  puppy.addPair(n10[1], n5[2], tgString("right hip rear upper muscleAct seg", 9) + tgString(" seg", 5));
419  puppy.addPair(n10[1], n5[3], tgString("right hip front upper muscleAct seg", 9) + tgString(" seg", 5));
420  puppy.addPair(n10[1], n4[2], tgString("right hip front top muscleAct seg", 9) + tgString(" seg", 4));
421  puppy.addPair(n10[1], n6[3], tgString("right hip rear top muscleAct seg", 9) + tgString(" seg", 4));
422 
423  puppy.addPair(n10[3], n5[2], tgString("right hip rear lower muscleAct seg", 9) + tgString(" seg", 5));
424  puppy.addPair(n10[3], n5[3], tgString("right hip front lower muscleAct seg", 9) + tgString(" seg", 5));
425  puppy.addPair(n10[3], n4[1], tgString("right hip bottom muscleAct seg", 9) + tgString(" seg", 4));
426  puppy.addPair(n10[3], n6[4], tgString("right hip bottom muscleAct seg", 9) + tgString(" seg", 6));
427 
428  //Extra muscles, to move right hip forward and back:
429  puppy.addPair(n10[0], n5[2], tgString("right hip rear mid muscleAct seg", 9) + tgString(" seg", 3)); //could also be n3[3]
430  puppy.addPair(n10[0], n5[3], tgString("right hip front mid muscleAct seg", 9) + tgString(" seg", 5));
431 
432  //Leg/hip connections:
433 
434  //Left front leg/shoulder
435  puppy.addPair(n11[4], n7[3], tgString("right outer bicep muscle seg", 10) + tgString(" seg", 6));
436  puppy.addPair(n11[4], n7[2], tgString("right inner bicep muscle seg", 10) + tgString(" seg", 6));
437  puppy.addPair(n11[4], n1[4], tgString("right front abdomen connection muscle seg", 10) + tgString(" seg", 1));
438 
439  puppy.addPair(n11[3], n7[3], tgString("right outer tricep muscle seg", 10) + tgString(" seg", 6));
440  puppy.addPair(n11[3], n7[2], tgString("right inner tricep muscle seg", 10) + tgString(" seg", 6));
441 
442  puppy.addPair(n11[2], n7[3], tgString("right outer front tricep muscle seg", 10) + tgString(" seg", 6));
443  puppy.addPair(n11[2], n7[2], tgString("right inner front tricep muscle seg", 10) + tgString(" seg", 6));
444 
445  //Adding muscle to pull up on right front leg:
446  puppy.addPair(n11[4], n7[1], tgString("right mid bicep muscle3 seg", 10) + tgString(" seg", 6));
447 
448  //Right front leg/shoulder
449  puppy.addPair(n13[4], n9[2], tgString("left inner bicep muscle seg", 12) + tgString(" seg", 8));
450  puppy.addPair(n13[4], n9[3], tgString("left outer bicep muscle seg", 12) + tgString(" seg", 8));
451  puppy.addPair(n13[4], n1[3], tgString("left front abdomen connection muscle seg", 12) + tgString(" seg", 1)); //Was n1[2]
452 
453  puppy.addPair(n13[3], n9[2], tgString("left inner tricep muscle seg", 12) + tgString(" seg", 8));
454  puppy.addPair(n13[3], n9[3], tgString("left outer tricep muscle seg", 12) + tgString(" seg", 8));
455 
456  puppy.addPair(n13[2], n9[2], tgString("left inner front tricep muscle seg", 12) + tgString(" seg", 8));
457  puppy.addPair(n13[2], n9[3], tgString("left outer front tricep muscle seg", 12) + tgString(" seg", 8));
458 
459  //Adding muscle to pull up on left front leg:
460  puppy.addPair(n13[4], n9[1], tgString("left mid bicep muscle3 seg", 12) + tgString(" seg", 8));
461 
462  //Left rear leg/hip
463  puppy.addPair(n12[4], n8[3], tgString("right outer thigh muscle seg", 11) + tgString(" seg", 7));
464  puppy.addPair(n12[4], n8[2], tgString("right inner thigh muscle seg", 11) + tgString(" seg", 7));
465 
466  puppy.addPair(n12[4], n3[1],tgString("right rear abdomen connection muscle seg", 11) + tgString(" seg", 3));
467  puppy.addPair(n12[3], n5[1],tgString("right rear abdomen connection muscle seg", 11) + tgString(" seg", 5));
468 
469  puppy.addPair(n12[3], n8[3], tgString("right outer calf muscle seg", 11) + tgString(" seg", 7));
470  puppy.addPair(n12[3], n8[2], tgString("right inner calf muscle seg", 11) + tgString(" seg", 7));
471 
472  puppy.addPair(n12[2], n8[3], tgString("right outer front calf muscle seg", 11) + tgString(" seg", 7));
473  puppy.addPair(n12[2], n8[2], tgString("right inner front calf muscle seg", 11) + tgString(" seg", 7));
474 
475  //Adding muscle to pull rear right leg up:
476  puppy.addPair(n12[4], n8[1], tgString("right central thigh muscle3 seg", 11) + tgString(" seg", 7));
477 
478  //Right rear leg/hip
479  puppy.addPair(n14[4], n10[2], tgString("left inner thigh muscle seg", 13) + tgString(" seg", 9));
480  puppy.addPair(n14[4], n10[3], tgString("left outer thigh muscle seg", 13) + tgString(" seg", 9));
481 
482  puppy.addPair(n14[4], n3[2], tgString("left rear abdomen connection muscle seg", 13) + tgString(" seg", 3));
483  puppy.addPair(n14[3], n5[2], tgString("left rear abdomen connection muscle seg", 13) + tgString(" seg", 5));
484 
485  puppy.addPair(n14[3], n10[2], tgString("left inner calf muscle seg", 13) + tgString(" seg", 9));
486  puppy.addPair(n14[3], n10[3], tgString("left outer calf muscle seg", 13) + tgString(" seg", 9));
487 
488  puppy.addPair(n14[2], n10[2], tgString("left inner front calf muscle seg", 13) + tgString(" seg", 9));
489  puppy.addPair(n14[2], n10[3], tgString("left outer front calf muscle seg", 13) + tgString(" seg", 9));
490 
491  //Adding muscle to pull rear left leg up:
492  puppy.addPair(n14[4], n10[1], tgString("left central thigh muscle3 seg", 13) + tgString(" seg", 9));
493 
494  //Populate feet with muscles. Todo: think up names to differentiate each!
495  /*for(std::size_t i = (m_segments + m_hips + m_legs); i < children.size(); i++) {
496  tgNodes ni = children[i]->getNodes();
497  tgNodes ni4 = children[i-4]->getNodes();
498 
499  puppy.addPair(ni[0],ni[1],tgString("foot muscle seg", i));
500  puppy.addPair(ni[0],ni[3],tgString("foot muscle seg", i));
501  puppy.addPair(ni[1],ni[2],tgString("foot muscle seg", i));
502  puppy.addPair(ni[2],ni[3],tgString("foot muscle seg", i));
503  puppy.addPair(ni[0],ni[7],tgString("foot muscle2 seg", i));
504  puppy.addPair(ni[1],ni[4],tgString("foot muscle2 seg", i));
505  puppy.addPair(ni[2],ni[5],tgString("foot muscle2 seg", i));
506  puppy.addPair(ni[3],ni[6],tgString("foot muscle2 seg", i));
507  puppy.addPair(ni[4],ni[5],tgString("foot muscle2 seg", i));
508  puppy.addPair(ni[4],ni[7],tgString("foot muscle2 seg", i));
509  puppy.addPair(ni[5],ni[6],tgString("foot muscle2 seg", i));
510  puppy.addPair(ni[6],ni[7],tgString("foot muscle2 seg", i));
511 
512  //Connect feet to legs:
513  puppy.addPair(ni4[5],ni[0],tgString("foot muscle2 seg", i) + tgString(" seg", i-4));
514  puppy.addPair(ni4[5],ni[1],tgString("foot muscle2 seg", i) + tgString(" seg", i-4));
515  puppy.addPair(ni4[5],ni[2],tgString("foot muscle2 seg", i) + tgString(" seg", i-4));
516  puppy.addPair(ni4[5],ni[3],tgString("foot muscle2 seg", i) + tgString(" seg", i-4));
517 
518  puppy.addPair(ni4[0],ni[4],tgString("foot muscle2 seg", i) + tgString(" seg", i-4));
519  puppy.addPair(ni4[0],ni[5],tgString("foot muscle2 seg", i) + tgString(" seg", i-4));
520  puppy.addPair(ni4[0],ni[6],tgString("foot muscle2 seg", i) + tgString(" seg", i-4));
521  puppy.addPair(ni4[0],ni[7],tgString("foot muscle2 seg", i) + tgString(" seg", i-4));
522 
523  }*/
524 
525 }
526 
528 {
529  //Rod and Muscle configuration.
530  const double density = 4.2/300.0; //Note: this needs to be high enough or things fly apart...
531  const double radius = 0.5;
532  const double rod_space = 10.0;
533  const double rod_space2 = 8.0;
534  const double friction = 0.5;
535  const double rollFriction = 0.0;
536  const double restitution = 0.0;
537 
538  const tgRod::Config rodConfig(radius, density, friction, rollFriction, restitution);
539 
540  const double stiffness = 1000.0;
541  const double stiffnessPassive = 3000.0;
542  const double damping = .01*stiffness;
543  const double pretension = 0.0;
544  const bool history = true;
545  const double maxTens = 7000.0;
546  const double maxSpeed = 12.0;
547 
548  const double passivePretension = 1000;
549  const double passivePretension2 = 2500;
550  const double passivePretension3 = 2500;
551 
552 #ifdef USE_KINEMATIC
553 
554  const double mRad = 1.0;
555  const double motorFriction = 10.0;
556  const double motorInertia = 1.0;
557  const bool backDrivable = false;
558  #ifdef PASSIVE_STRUCTURE
559  tgKinematicActuator::Config motorConfig(2000, 20, passivePretension,
560  mRad, motorFriction, motorInertia, backDrivable,
561  history, maxTens, maxSpeed);
562 
563  tgKinematicActuator::Config motorConfigOther(stiffnessPassive, damping, passivePretension2,
564  mRad, motorFriction, motorInertia, backDrivable,
565  history, maxTens, maxSpeed);
566 
567  tgKinematicActuator::Config motorConfigFeet(stiffnessPassive, damping, passivePretension,
568  mRad, motorFriction, motorInertia, backDrivable,
569  history, maxTens, maxSpeed);
570  tgKinematicActuator::Config motorConfigLegs(stiffnessPassive, 20, passivePretension3,
571  mRad, motorFriction, motorInertia, backDrivable,
572  history, maxTens, maxSpeed);
573 
574  #else
575  tgKinematicActuator::Config motorConfigSpine(stiffness, damping, pretension,
576  mRad, motorFriction, motorInertia, backDrivable,
577  history, maxTens, maxSpeed);
578 
579  tgKinematicActuator::Config motorConfigOther(stiffnessPassive, damping, passivePretension2,
580  mRad, motorFriction, motorInertia, backDrivable,
581  history, maxTens, maxSpeed);
582 
583  tgKinematicActuator::Config motorConfigFeet(stiffnessPassive, damping, passivePretension,
584  mRad, motorFriction, motorInertia, backDrivable,
585  history, maxTens, maxSpeed);
586  tgKinematicActuator::Config motorConfigLegs(stiffnessPassive, damping, passivePretension3,
587  mRad, motorFriction, motorInertia, backDrivable,
588  history, maxTens, maxSpeed);
589  #endif
590 
591 #else
592 
593  #ifdef PASSIVE_STRUCTURE
594  tgSpringCableActuator::Config muscleConfig(2000, 20, passivePretension);
595  tgSpringCableActuator::Config muscleConfigOther(stiffnessPassive, damping, passivePretension2);
596  tgSpringCableActuator::Config muscleConfigFeet(stiffnessPassive, damping, passivePretension);
597  tgSpringCableActuator::Config muscleConfigLegs(stiffnessPassive, damping, passivePretension3);
598 
599  #else
600  tgSpringCableActuator::Config muscleConfigSpine(stiffness, damping, pretension, history, maxTens, 2*maxSpeed);
601  tgSpringCableActuator::Config muscleConfigOther(stiffnessPassive, damping, passivePretension2);
602  tgSpringCableActuator::Config muscleConfigFeet(stiffnessPassive, damping, passivePretension);
603  tgSpringCableActuator::Config muscleConfigLegs(stiffnessPassive, damping, passivePretension3);
604  #endif
605 
606 #endif
607 
608  //Foot:
609  //tgStructure foot;
610  //addNodesFoot(foot,rod_space,rod_space2);
611  //addRodsFoot(foot);
612 
613  //Leg:
614  tgStructure leg;
615  addNodesLeg(leg,rod_space);
616  addRodsLeg(leg);
617 
618  //Create the basic unit of the puppy
619  tgStructure vertebra;
620  addNodesVertebra(vertebra,rod_space);
621  addRodsVertebra(vertebra);
622 
623  //Create the basic unit for the hips/shoulders.
624  tgStructure hip;
625  addNodesHip(hip,rod_space);
626  addRodsHip(hip);
627 
628  //Build the puppy
629  tgStructure puppy;
630 
631  const double yOffset_foot = -(2*rod_space+6);
632 
633  addSegments(puppy,vertebra,hip,leg,rod_space); //,m_segments,m_hips,m_legs,m_feet
634 
635  puppy.move(btVector3(0.0,26,0.0));
636 
637  addMuscles(puppy); //,m_segments,m_hips,m_legs,m_feet
638 
639  //Time to add the muscles to the structure. Todo: make this a function; also try to clean this up.
640  std::vector<tgStructure*> children = puppy.getChildren();
641 
642  // Create the build spec that uses tags to turn the structure into a real model
643  tgBuildSpec spec;
644  spec.addBuilder("rod", new tgRodInfo(rodConfig));
645 
646 #ifdef USE_KINEMATIC
647 
648  #ifdef PASSIVE_STRUCTURE
649  spec.addBuilder("muscleAct", new tgKinematicContactCableInfo(motorConfig));
650  spec.addBuilder("muscle ", new tgKinematicContactCableInfo(motorConfigOther));
651  //spec.addBuilder("muscle2 ", new tgKinematicContactCableInfo(motorConfigFeet));
652  spec.addBuilder("muscle3 ", new tgKinematicContactCableInfo(motorConfigLegs));
653  #else
654  spec.addBuilder("muscleAct", new tgKinematicContactCableInfo(motorConfigSpine));
655  spec.addBuilder("muscle ", new tgKinematicContactCableInfo(motorConfigOther));
656  //spec.addBuilder("muscle2 ", new tgKinematicContactCableInfo(motorConfigFeet));
657  spec.addBuilder("muscle3 ", new tgKinematicContactCableInfo(motorConfigLegs));
658 
659  #endif
660 
661 #else
662  #ifdef PASSIVE_STRUCTURE
663  spec.addBuilder("muscleAct", new tgBasicActuatorInfo(muscleConfig));
664  spec.addBuilder("muscle " , new tgBasicActuatorInfo(muscleConfigOther));
665  //spec.addBuilder("muscle2 " , new tgBasicActuatorInfo(muscleConfigFeet));
666  spec.addBuilder("muscle3 " , new tgBasicActuatorInfo(muscleConfigLegs));
667  #else
668  spec.addBuilder("muscleAct" , new tgBasicActuatorInfo(muscleConfigSpine));
669  spec.addBuilder("muscle " , new tgBasicActuatorInfo(muscleConfigOther));
670  //spec.addBuilder("muscle2 " , new tgBasicActuatorInfo(muscleConfigFeet));
671  spec.addBuilder("muscle3 " , new tgBasicActuatorInfo(muscleConfigLegs));
672  #endif
673 
674 #endif
675 
676 
677 
678  // Create your structureInfo
679  tgStructureInfo structureInfo(puppy, spec);
680 
681  // Use the structureInfo to build ourselves
682  structureInfo.buildInto(*this, world);
683 
684  // We could now use tgCast::filter or similar to pull out the
685  // models (e.g. muscles) that we want to control.
686  m_allMuscles = tgCast::filter<tgModel, tgSpringCableActuator> (getDescendants());
687 
688  m_allSegments = this->find<tgModel> ("spine segment");
689 
690  // Actually setup the children, notify controller that the setup has finished
692 
693  children.clear();
694 }
695 
696 void BigPuppyNoFeet::step(double dt)
697 {
698  // Precondition
699  if (dt <= 0.0)
700  {
701  throw std::invalid_argument("dt is not positive");
702  }
703  else
704  {
705  // Notify observers (controllers) of the step so that they can take action
707  }
708 }
709 
711 {
713 }
const std::vector< tgStructure * > & getChildren() const
Definition: tgStructure.h:184
void addChild(tgStructure *child)
Definition of class tgRodInfo.
virtual void teardown()
Convenience function for combining strings with ints, mostly for naming structures.
Implementing the Flemons quadruped model (roughly), but as a subclass of Brian's BaseSpineModelLearni...
virtual void setup(tgWorld &world)
Definition of class tgBasicActuatorInfo.
virtual void step(double dt)
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.
Definition of class tgKinematicActuatorInfo.
Contains the definition of class tgRod.
Definition of class tgBuildSpec.
virtual void step(double dt)
virtual void setup(tgWorld &world)
Definition of class tgKinematicContactCableInfo.
std::vector< tgModel * > getDescendants() const
Definition: tgModel.cpp:170
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")
Definition: tgStructure.cpp:70