11 #include <dynamic-graph/factory.h> 13 #include <boost/format.hpp> 14 #include <boost/numeric/ublas/io.hpp> 31 forceSIN(NULL,
"InvertedPendulum(" + inName +
")::input(double)::force"),
32 stateSOUT(
"InvertedPendulum(" + inName +
")::output(vector)::state"),
49 std::string docstring;
54 " Integrate dynamics for time step provided as input\n" 56 " take one floating point number as input\n" 66 new ::dynamicgraph::command::Setter<InvertedPendulum, double>(
75 new ::dynamicgraph::command::Getter<InvertedPendulum, double>(
81 " Set pendulum mass\n" 84 new ::dynamicgraph::command::Setter<InvertedPendulum, double>(
90 " Get pendulum mass\n" 93 new ::dynamicgraph::command::Getter<InvertedPendulum, double>(
99 " Set pendulum length\n" 102 new ::dynamicgraph::command::Setter<InvertedPendulum, double>(
108 " Get pendulum length\n" 111 new ::dynamicgraph::command::Getter<InvertedPendulum, double>(
118 const double& inControl,
120 if (inState.size() != 4)
122 "state signal size is ",
123 "%d, should be 4.", inState.size());
125 double dt = inTimeStep;
126 double dt2 = dt * dt;
128 double x = inState(0);
129 double th = inState(1);
130 double dx = inState(2);
131 double dth = inState(3);
132 double F = inControl;
138 double dth2 = dth * dth;
139 double sth = sin(th);
140 double cth = cos(th);
141 double sth2 = sth * sth;
143 double b1 = F - m * l * dth2 * sth - lambda * dx;
144 double b2 = m * l * g * sth - lambda * dth;
146 double det = m * l2 * (M + m * sth2);
148 double ddx = (b1 * m * l2 + b2 * m * l * cth) / det;
149 double ddth = ((M + m) * b2 + m * l * cth * b1) / det;
152 nextState(0) = x + dx * dt + .5 * ddx * dt2;
153 nextState(1) = th + dth * dt + .5 * ddth * dt2;
154 nextState(2) = dx + dt * ddx;
155 nextState(3) = dth + dt * ddth;
double cartMass_
Mass of the cart.
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(MyEntity, "MyEntity")
double viscosity_
Viscosity coefficient.
void signalRegistration(const SignalArray< int > &signals)
static const double gravity
void incr(double inTimeStep)
Integrate equation of motion over time step given as input.
void setCartMass(const double &inMass)
Set the mass of the cart.
virtual void setConstant(const T &t)
double getCartMass() const
Get the mass of the cart.
Signal< ::dynamicgraph::Vector, int > stateSOUT
State of the inverted pendulum.
::dynamicgraph::Vector computeDynamics(const ::dynamicgraph::Vector &inState, const double &inControl, double inTimeStep)
Compute the evolution of the state of the pendulum.
virtual void setConstant(const T &t)
InvertedPendulum(const std::string &inName)
Constructor by name.
void setPendulumLength(const double &inLength)
Set the length of the cart.
SignalPtr< double, int > forceSIN
Input force acting on the inverted pendulum.
void setPendulumMass(const double &inMass)
Set the mass of the cart.
double pendulumLength_
Length of the pendulum.
Inverted Pendulum on a cart.
double getPendulumLength() const
Get the length of the pendulum.
void addCommand(const std::string &name, command::Command *command)
virtual const Time & getTime() const
double pendulumMass_
Mass of the pendulum.
virtual void setTime(const Time &t)
double getPendulumMass() const
Get the mass of the pendulum.