NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgSpringCableActuatorSensor.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 
27 // This class:
29 
30 // Includes from NTRT:
31 #include "core/tgSenseable.h"
32 #include "core/tgCast.h"
33 #include "core/tgTags.h"
34 
35 // Includes from the c++ standard library:
36 #include <sstream>
37 #include <stdexcept>
38 #include <cassert>
39 #include <string> // for std::to_string(float)
40 
41 // Includes from Bullet Physics:
42 #include "LinearMath/btVector3.h"
43 
49 {
50  // Note that this pointer may be 0 (equivalent to NULL) if the cast in
51  // the calling function from tgSenseable to tgSpringCableActuator fails.
52  if (pSCA == NULL) {
53  throw std::invalid_argument("Pointer to pSCA is NULL inside tgSpringCableActuatorSensor.");
54  }
55 }
56 
63 {
64 }
65 
73  // Note that this class has access to the parent's pointer, m_pSens.
74  // Let's cast that to a pointer to a tgSpringCableActuator right now.
75  // Here, "m_pSCA" stands for "my pointer to a tgSpringCableActuator."
76  tgSpringCableActuator* m_pSCA =
77  tgCast::cast<tgSenseable, tgSpringCableActuator>(m_pSens);
78  // Check: if the cast failed, this will return 0.
79  // In that case, this tgSpringCableActuatorSensor does
80  // not point to a tgSpringCableActuator!!!
81  assert( m_pSCA != 0);
82 
83  // The list to which we'll append all the sensor headings:
84  std::vector<std::string> headings;
85 
86  // Pull out the tags for this spring cable actuator,
87  // so we only have to call the accessor once.
88  tgTags m_tags = m_pSCA->getTags();
89 
90  // Copied from tgSensor.h:
100  // The string 'prefix' will be added to each heading.
101  std::string prefix = "SCA(";
102 
103  // This SCA will give a rest length, current length, and tension.
104  headings.push_back( prefix + m_tags + ").RestLen" );
105  headings.push_back( prefix + m_tags + ").CurrLen" );
106  headings.push_back( prefix + m_tags + ").Tension" );
107 
108  // Return the string version of this string stream.
109  return headings;
110 }
111 
115 std::vector<std::string> tgSpringCableActuatorSensor::getSensorData() {
116  // Similar to getSensorDataHeading, cast the a pointer
117  // to a tgSpringCableActuator right now.
118  tgSpringCableActuator* m_pSCA =
119  tgCast::cast<tgSenseable, tgSpringCableActuator>(m_pSens);
120  // Check: if the cast failed, this will return 0.
121  // In that case, this tgSpringCableActuatorSensor does not point
122  // to a tgSpringCableActuator!!!
123  assert( m_pSCA != 0);
124 
125  // The list of sensor data that will be returned:
126  std::vector<std::string> sensordata;
127 
128  // The floats doubles need to be converted to strings via a stringstream.
129  std::stringstream ss;
130 
131  // rest length
132  ss << m_pSCA->getRestLength();
133  sensordata.push_back( ss.str() );
134  // Reset the stream.
135  ss.str("");
136 
137  // current length
138  ss << m_pSCA->getCurrentLength();
139  sensordata.push_back( ss.str() );
140  ss.str("");
141 
142  // tension
143  ss << m_pSCA->getTension();
144  sensordata.push_back( ss.str() );
145  ss.str("");
146 
147  return sensordata;
148 }
149 
150 //end.
Constains definition of concrete class tgSpringCableActuatorSensor.
virtual std::vector< std::string > getSensorDataHeadings()
virtual const double getTension() const
Utility class for class casting and filtering collections by type.
tgSpringCableActuatorSensor(tgSpringCableActuator *pSCA)
Contains the definition of class tgTags.
tgSenseable * m_pSens
Definition: tgSensor.h:102
virtual std::vector< std::string > getSensorData()
virtual const double getRestLength() const
virtual const double getCurrentLength() const
Constains the implementation of mixin class tgSenseable.
Definition: tgTags.h:44