NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
BaseSpineModelGoal.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 
28 // This module
29 #include "BaseSpineModelGoal.h"
30 // This library
31 #include "core/tgBox.h"
32 #include "tgcreator/tgBoxInfo.h"
33 #include "tgcreator/tgBuildSpec.h"
34 #include "tgcreator/tgStructure.h"
36 #include "tgcreator/tgUtil.h"
37 // The Bullet Physics library
38 #include "LinearMath/btVector3.h"
39 // The C++ Standard Library
40 #include <algorithm> // std::fill
41 #include <iostream>
42 #include <map>
43 #include <set>
44 
45 BaseSpineModelGoal::BaseSpineModelGoal(int segments, double goalAngle) :
46  BaseSpineModelLearning(segments),
47  m_goalAngle(goalAngle)
48 {
49 }
50 
51 BaseSpineModelGoal::~BaseSpineModelGoal()
52 {
53 }
54 
56 {
57 
58  // Create goal box in a new structure
59 #if (0)
60  m_goalAngle = ((rand() / (double)RAND_MAX)) * 3.1415;
61 #endif // If we're resetting the simulation and want to change the angle
62 
63  double xPos = 350 * sin(m_goalAngle);
64  double zPos = 350 * cos(m_goalAngle);
65 
66  tgStructure goalBox;
67 
68  goalBox.addNode(xPos, 20.0, zPos);
69  goalBox.addNode(xPos + 5.0, 20.0, zPos);
70 
71  std::cout << "Goal Position: " << xPos << " " << zPos << std::endl;
72 
73  goalBox.addPair(0, 1, "goalBox");
74 
75  // 1 by 1 by 1 box, fix when tgBoxInfo gets fixed
76  const tgBox::Config boxConfig(10.0, 10.0);
77 
78  tgBuildSpec boxSpec;
79  boxSpec.addBuilder("goalBox", new tgBoxInfo(boxConfig));
80 
81  tgStructureInfo goalStructureInfo(goalBox, boxSpec);
82 
83  goalStructureInfo.buildInto(*this, world);
84 
85  // A little sloppy, but I'm pretty confident there is only one
86  m_goalBox = (find<tgBox>("goalBox"))[0];
87 
88  assert(m_goalBox != NULL);
89 
90  // Actually setup the children, notify controller
92 }
93 
95 {
96 
98 
99 }
100 
102 {
103  /* CPG update occurs in the controller so that we can decouple it
104  * from the physics update
105  */
106 
107  BaseSpineModelLearning::step(dt); // Step any children
108 }
109 
110 btVector3 BaseSpineModelGoal::goalBoxPosition() const
111 {
112  return m_goalBox->centerOfMass();
113 }
114 
Create a box shape as an obstacle or add it to your tensegrity.
virtual void setup(tgWorld &world)
virtual void setup(tgWorld &world)
virtual btVector3 centerOfMass() const
Definition: tgBaseRigid.cpp:74
Implementing the tetrahedral complex spine inspired by Tom Flemons.
virtual void step(double dt)
Class that interfaces with Bullet to build the boxes.
void addPair(int fromNodeIdx, int toNodeIdx, std::string tags="")
Definition: tgStructure.cpp:80
Definition of class tgStructure.
Definition of class tgStructureInfo.
Rand seeding simular to the evolution and terrain classes.
Definition of class tgBuildSpec.
virtual void step(double dt)
void buildInto(tgModel &model, tgWorld &world)
void addNode(double x, double y, double z, std::string tags="")
Definition: tgStructure.cpp:70