NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
T6RestLengthController.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 
27 // This module
28 #include "T6RestLengthController.h"
29 // This application
30 #include "T6Model.h"
31 // This library
32 #include "core/tgBasicActuator.h"
34 #include "tgcreator/tgUtil.h"
35 // The C++ Standard Library
36 #include <cassert>
37 #include <stdexcept>
38 #include <vector>
39 #include <iostream>
40 
41 T6RestLengthController::T6RestLengthController(T6Model* subject, const double restLengthDiff) :
42  m_restLengthDiff(restLengthDiff),
43  m_controllerMuscleRatio(subject->muscleRatio())
44 {
45  if (restLengthDiff < 0.0)
46  {
47  throw std::invalid_argument("You tried to push a rope!");
48  }
49 }
50 
52 {
53  // Do a one-time update of all cable rest lengths
54  // First, get all muscles (cables)
55 
56  const std::vector<tgBasicActuator*> passiveMuscles = subject.getPassiveMuscles();
57  const std::vector<tgBasicActuator*> activeMuscles = subject.getActiveMuscles();
58 
59  // then, iterate over all muscles
60  for (size_t i = 0; i < passiveMuscles.size(); ++i)
61  {
62  tgBasicActuator * const pMuscle = passiveMuscles[i];
63  assert(pMuscle != NULL);
64 
65  // set rest length of the i-th muscle
66  double desiredRestLength = pMuscle->getStartLength() - 0.7;
67  pMuscle->setRestLengthSingleStep(desiredRestLength);
68  }
69  for (size_t i = 0; i < activeMuscles.size(); ++i)
70  {
71  tgBasicActuator * const pMuscle = activeMuscles[i];
72  assert(pMuscle != NULL);
73 
74  // set rest length of the i-th muscle
75  double desiredRestLength = pMuscle->getStartLength() - 0.22;
76  pMuscle->setRestLengthSingleStep(desiredRestLength);
77  }
78 }
79 
80 void T6RestLengthController::onStep(T6Model& subject, double dt)
81 {
82  static int count = 0;
83  const std::vector<tgBasicActuator*> strings = subject.getAllMuscles();
85  const tgBulletSpringCable* muscles;
86 
87  if(count > 100)
88  {
89  for(size_t i=0; i<strings.size(); i++)
90  {
91  std::cout << (strings[i]->getTension())/10 << "\t";
92  }
93  std::cout << "\n";
94  for(size_t i=0; i<strings.size(); i++)
95  {
96  std::cout << (strings[i]->getCurrentLength())/10 << "\t";
97  }
98  std::cout << "\n";
99 // for(size_t i=0; i<strings.size(); i++)
100 // muscles = strings[i]->getMuscle();
101 // {
102 // std::cout << getTransform(muscles->anchor1->getWorldPosition() - muscles->anchor2->getWorldPosition()) << "\t";
103 // }
104 // std::cout << "\n";
105  count = 0;
106  }
107  else
108  {
109  count++;
110  }
111 
112  // Nothing!!
113 }
virtual const double getStartLength() const
T6RestLengthController(T6Model *subject, const double restLengthDiff=4)
const std::vector< tgBasicActuator * > & getAllMuscles() const
Definition: T6Model.cpp:247
const std::vector< tgBasicActuator * > & getPassiveMuscles() const
Definition: T6Model.cpp:252
Contains the definition of class tgBasicActuator.
virtual void onSetup(T6Model &subject)
const std::vector< tgBasicActuator * > & getActiveMuscles() const
Definition: T6Model.cpp:257
Rand seeding simular to the evolution and terrain classes.
Definitions of classes tgBulletSpringCable $Id$.
virtual void onStep(T6Model &subject, double dt)