当前位置: 首页>>代码示例>>C++>>正文


C++ VectorNd类代码示例

本文整理汇总了C++中VectorNd的典型用法代码示例。如果您正苦于以下问题:C++ VectorNd类的具体用法?C++ VectorNd怎么用?C++ VectorNd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了VectorNd类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mult

/// Multiplies a vector of spatial axes by a vector
SVelocityd mult(const vector<SVelocityd>& t, const VectorNd& v)
{
  const unsigned SPATIAL_DIM = 6;

  if (t.size() != v.size())
    throw MissizeException();

  // verify that the vector is not empty - we lose frame info!
  if (t.empty())
    throw std::runtime_error("loss of frame information");

  // setup the result
  SVelocityd result = SVelocityd::zero();

  // verify that all twists are in the same pose
  result.pose = t.front().pose;
  for (unsigned i=1; i< t.size(); i++)
    if (t[i].pose != result.pose)
      throw FrameException(); 

  // finally, do the computation
  const double* vdata = v.data();
  for (unsigned j=0; j< SPATIAL_DIM; j++)
    for (unsigned i=0; i< t.size(); i++)
      result[j] += t[i][j]*vdata[i];

  return result;
}
开发者ID:praman2s,项目名称:Moby,代码行数:29,代码来源:Spatial.cpp

示例2: updatePosition

 void CartVelController::updatePosition(const VectorNd& position) {
     if (q_.size() != position.size()) {
         ROS_ERROR_STREAM("Size of joint position vector (" << position.size() << ") doesn't match chain size (" << kdl_chain_.getNrOfJoints() << ").");
         return;
     }
     q_ = position;
 }
开发者ID:progtologist,项目名称:compliant_control,代码行数:7,代码来源:CartVelController.cpp

示例3: get_vector_value

/// Gets a list of space-delimited and/or comma-delimited vectors from the underlying string value
void XMLAttrib::get_vector_value(SVector6d& v)
{
  // indicate this attribute has been processed
  processed = true;

  VectorNd w = VectorNd::parse(value);
  if (w.size() != v.size())
    throw MissizeException();
  v = SVector6d(w[0], w[1], w[2], w[3], w[4], w[5]);
}  
开发者ID:PositronicsLab,项目名称:Moby,代码行数:11,代码来源:XMLTree.cpp

示例4: get_rpy_value

/// Returns a quaternion value from a roll-pitch-yaw attribute
Quatd XMLAttrib::get_rpy_value()
{
  // indicate this attribute has been processed
  processed = true;

  VectorNd v = VectorNd::parse(value);
  if (v.size() != 3)
    throw std::runtime_error("Unable to parse roll-pitch-yaw from vector!");
  return Quatd::rpy(v[0], v[1], v[2]);
}
开发者ID:PositronicsLab,项目名称:Moby,代码行数:11,代码来源:XMLTree.cpp

示例5: setup

void setup(){
  boost::shared_ptr<Pacer::Controller> ctrl(ctrl_weak_ptr);

  q_goal = ctrl->get_joint_generalized_value(Pacer::Controller::position);
  qd_goal = Ravelin::VectorNd::zero(q_goal.rows());
  qdd_goal = Ravelin::VectorNd::zero(q_goal.rows());
  
  x_goal = ctrl->get_foot_value(Pacer::Controller::position_goal);
  for (std::map<std::string,Origin3d>::iterator it = x_goal.begin();  it != x_goal.end(); it++) {
    xd_goal[it->first] = Origin3d(0,0,0);
    xdd_goal[it->first] = Origin3d(0,0,0);
  }
}
开发者ID:nrkumar93,项目名称:Pacer,代码行数:13,代码来源:stay.cpp

示例6: get_origin_value

/// Returns an Origin3d value from the attribute
Origin3d XMLAttrib::get_origin_value() 
{
  // indicate this attribute has been processed
  processed = true;

  VectorNd v = VectorNd::parse(value);
  if (v.size() != 3)
    throw std::runtime_error("Unable to parse origin from vector!");
  Origin3d o;
  o.x() = v[0];
  o.y() = v[1];
  o.z() = v[2];
  return o;
}
开发者ID:PositronicsLab,项目名称:Moby,代码行数:15,代码来源:XMLTree.cpp

示例7: get_quat_value

/// Returns a quaternion value from the attribute
Quatd XMLAttrib::get_quat_value()
{
  // indicate this attribute has been processed
  processed = true;

  VectorNd v = VectorNd::parse(value);
  if (v.size() != 4)
    throw std::runtime_error("Unable to parse quaternion from vector!");
  Quatd q;
  q.w = v[0];
  q.x = v[1];
  q.y = v[2];
  q.z = v[3];
  return q;
}
开发者ID:PositronicsLab,项目名称:Moby,代码行数:16,代码来源:XMLTree.cpp

示例8: calc_gradient

// Computes the gradient for conservative advancement 
// gradient: | (radius * -sin theta * sin phi) * y(1) + ...
//             (radius * cos theta * sin phi) * y(2)         |
//           | (radius * cos theta * cos phi) * y(1) + ...
//             (radius * sin theta * cos phi) * y(2) + ...
//             (radius * -sin phi) * y(3)                    |
void SpherePrimitive::calc_gradient(const VectorNd& x, void* data, VectorNd& g)
{
  // get the pair
  std::pair<double, VectorNd>& data_pair = *((std::pair<double, VectorNd>*) data);

  // get radius and y
  double r = data_pair.first;
  VectorNd& y = data_pair.second;

  // get components of y
  const double Y1 = y[0];
  const double Y2 = y[1];
  const double Y3 = y[2];

  // get theta and phi
  double THETA = x[0];
  double PHI = x[1];

  // compute trig functions 
  double CTHETA = std::cos(THETA);
  double STHETA = std::sin(THETA);
  double CPHI = std::cos(PHI);
  double SPHI = std::sin(PHI);

  // setup gradient 
  g.resize(2);
  g[0] = (-STHETA * SPHI) * Y1 + (CTHETA * SPHI) * Y2;
  g[1] = (CTHETA * CPHI) * Y1 + (STHETA * CPHI) * Y2 - SPHI * Y3; 
  g *= -r;
}
开发者ID:PositronicsLab,项目名称:Moby,代码行数:36,代码来源:SpherePrimitive.cpp

示例9: determine_q

/// Determines (and sets) the value of Q from the axes and the inboard link and outboard link transforms
void UniversalJoint::determine_q(VectorNd& q)
{
  const unsigned X = 0, Y = 1, Z = 2;

  // get the outboard link
  RigidBodyPtr outboard = get_outboard_link();

  // verify that the outboard link is set
  if (!outboard)
    throw std::runtime_error("determine_q() called on NULL outboard link!");

  // set proper size for q
  this->q.resize(num_dof());

  // get the poses of the joint and outboard link
  shared_ptr<const Pose3d> Fj = get_pose();
  shared_ptr<const Pose3d> Fo = outboard->get_pose();

  // compute transforms
  Transform3d wTo = Pose3d::calc_relative_pose(Fo, GLOBAL); 
  Transform3d jTw = Pose3d::calc_relative_pose(GLOBAL, Fj);
  Transform3d jTo = jTw * wTo;

  // determine the joint transformation
  Matrix3d R = jTo.q;

  // determine q1 and q2 -- they are uniquely determined by examining the rotation matrix
  // (see get_rotation())
  q.resize(num_dof());
  q[DOF_1] = std::atan2(R(Z,Y), R(Y,Y));
  q[DOF_2] = std::atan2(R(X,Z), R(X,X));   
}
开发者ID:praman2s,项目名称:Moby,代码行数:33,代码来源:UniversalJoint.cpp

示例10: post_step_callback

// simulator callback
void post_step_callback(Simulator* sim)
{
  // output the sliding velocity at the contact 
  std::ofstream out("rke.dat", std::ostream::app);
  out << sim->current_time << " " << box->calc_kinetic_energy() << std::endl;
  out.close();

  // save the generalized coordinates of the box
  out.open("telemetry.box", std::ostream::app);
  VectorNd q;
  box->get_generalized_coordinates_euler(q);
  out << sim->current_time;
  for (unsigned i=0; i< q.size(); i++)
    out << " " << q[i];
  out << std::endl;
  out.close();
}
开发者ID:PositronicsLab,项目名称:wafr16-experiments,代码行数:18,代码来源:rbox-plugin-adaptive.cpp

示例11: step

/// runs the simulator and updates all transforms
bool step(void* arg)
{
    // get the simulator pointer
    boost::shared_ptr<Simulator> s = *(boost::shared_ptr<Simulator>*) arg;

    // get the generalized coordinates for all bodies in alphabetical order
    std::vector<ControlledBodyPtr> bodies = s->get_dynamic_bodies();
    std::sort(bodies.begin(), bodies.end(), compbody);
    VectorNd q;
    outfile << s->current_time;
    for (unsigned i=0; i< bodies.size(); i++)
    {
        shared_ptr<DynamicBodyd> db = dynamic_pointer_cast<DynamicBodyd>(bodies[i]);
        db->get_generalized_coordinates_euler(q);
        for (unsigned j=0; j< q.size(); j++)
            outfile << " " << q[j];
    }
    outfile << std::endl;

    // output the iteration #
    if (OUTPUT_ITER_NUM)
        std::cout << "iteration: " << ITER << "  simulation time: " << s->current_time << std::endl;
    if (Log<OutputToFile>::reporting_level > 0)
        FILE_LOG(Log<OutputToFile>::reporting_level) << "iteration: " << ITER << "  simulation time: " << s->current_time << std::endl;

    // step the simulator and update visualization
    clock_t pre_sim_t = clock();
    s->step(STEP_SIZE);
    clock_t post_sim_t = clock();
    double total_t = (post_sim_t - pre_sim_t) / (double) CLOCKS_PER_SEC;
    TOTAL_TIME += total_t;

    // output the iteration / stepping rate
    if (OUTPUT_SIM_RATE)
        std::cout << "time to compute last iteration: " << total_t << " (" << TOTAL_TIME / ITER << "s/iter, " << TOTAL_TIME / s->current_time << "s/step)" << std::endl;

    // update the iteration #
    ITER++;

    // check that maximum number of iterations or maximum time not exceeded
    if (ITER >= MAX_ITER || s->current_time > MAX_TIME)
        return false;

    return true;
}
开发者ID:PositronicsLab,项目名称:Moby,代码行数:46,代码来源:regress.cpp

示例12: update

    bool CartVelController::update(const Vector6d& command, VectorNd& velocities) {
        // init
        if (!initialized_) {
            ROS_ERROR("Controller wasn't initilized before calling 'update'.");
            return false;
        }
        setCommand(command);
        if (velocities.size() != kdl_chain_.getNrOfJoints()) {
            ROS_ERROR_STREAM("Size of velocities vector (" << velocities.size() << ") doesn't match number of joints (" << kdl_chain_.getNrOfJoints() << ").");
            return false;
        }
        for (unsigned int i = 0; i < kdl_chain_.getNrOfJoints(); i++) {
            velocities(i) = 0.0;
        }

        // forward kinematics
//        KDL::Frame frame_tip_pose;
//        if(chain_fk_solver_->JntToCart(*q_, frame_tip_pose) < 0) {
//            ROS_ERROR("Unable to compute forward kinematics");
//            return false;
//        }
        // transform vel command to root frame // not necessary, command is in root frame
//        KDL::Frame frame_tip_pose_inv = frame_tip_pose.Inverse();
//        KDL::Twist linear_twist = frame_tip_pose_inv * cmd_linear_twist_;
//        KDL::Twist angular_twist = frame_tip_pose_inv.M * cmd_angular_twist_;
//        KDL::Twist twist(linear_twist.vel, angular_twist.rot);

        // cartesian to joint space
        ConversionHelper::eigenToKdl(q_, qtmp_);
        ConversionHelper::eigenToKdl(cmd_twist_, twist_tmp_);
        if(chain_ik_solver_vel_->CartToJnt(qtmp_, twist_tmp_, joint_vel_tmp_) < 0) {
            ROS_ERROR("Unable to compute cartesian to joint velocity");
            return false;
        }

        // assign values to output.
        ConversionHelper::kdlToEigen(joint_vel_tmp_, velocities);
        return true;
    }
开发者ID:progtologist,项目名称:compliant_control,代码行数:39,代码来源:CartVelController.cpp

示例13: str

/// Constructs a vector-valued attribute with the given name
XMLAttrib::XMLAttrib(const std::string& name, const VectorNd& vector_value)
{
  this->processed = false;
  this->name = name;
  std::ostringstream oss;

  // if the vector is empty, return prematurely
  if (vector_value.size() == 0)
  {
    this->value = "";
    return;
  }

  // set the first value of the vector
  oss << str(vector_value[0]);

  // set subsequent values of the vector
  for (unsigned i=1; i< vector_value.size(); i++)
      oss << " " << str(vector_value[i]);

  // get the string value
  this->value = oss.str();
}
开发者ID:PositronicsLab,项目名称:Moby,代码行数:24,代码来源:XMLTree.cpp

示例14: compute_signed_dist_dot_Jacobians

/**
 * Assume the signed distance function is Phi(q(t)), so 
 * Phi(q(t_0 + \Delta t))_{t_0} \approx Phi(q(t_0)) + d/dt Phi(q(t_0)) * dt ==>
 * d/dt Phi(q(t_0)) \approx (Phi(q(t_0 + \Delta t)) - Phi(q(t_0))/dt 
 */
void SignedDistDot::compute_signed_dist_dot_Jacobians(UnilateralConstraintProblemData& q, MatrixNd& Cdot_iM_CnT, MatrixNd& Cdot_iM_CsT, MatrixNd& Cdot_iM_CtT, MatrixNd& Cdot_iM_LT, VectorNd& Cdot_v)
{
  const double DT = NEAR_ZERO;
  vector<shared_ptr<DynamicBodyd> > tmp_supers1, tmp_supers2, isect;
  VectorNd gc, gv;

  // get all pairs of bodies involved in contact
  vector<shared_ptr<DynamicBodyd> > ubodies;
  for (unsigned i=0; i< q.signed_distances.size(); i++)
  {
    // get the two single bodies
    shared_ptr<SingleBodyd> s1 = q.signed_distances[i].a->get_single_body();
    shared_ptr<SingleBodyd> s2 = q.signed_distances[i].b->get_single_body();

    // get the two super bodies
    shared_ptr<DynamicBodyd> sb1 = ImpactConstraintHandler::get_super_body(s1); 
    shared_ptr<DynamicBodyd> sb2 = ImpactConstraintHandler::get_super_body(s2); 

    // add the bodies to ubodies
    ubodies.push_back(sb1);
    ubodies.push_back(sb2);
  } 

  // get all unique bodies involved in contact
  std::sort(ubodies.begin(), ubodies.end());
  ubodies.erase(std::unique(ubodies.begin(), ubodies.end()), ubodies.end());

  // save all configurations for all bodies involved in contact
  map<shared_ptr<DynamicBodyd>, VectorNd> gc_map;
  for (unsigned i=0; i< ubodies.size(); i++)
    ubodies[i]->get_generalized_coordinates_euler(gc_map[ubodies[i]]);

  // save all velocities for all bodies involved in contact
  map<shared_ptr<DynamicBodyd>, VectorNd> gv_map;
  for (unsigned i=0; i< ubodies.size(); i++)
    ubodies[i]->get_generalized_velocity(DynamicBodyd::eSpatial, gv_map[ubodies[i]]);

  // resize Cdot(v)
  Cdot_v.resize(q.signed_distances.size());

  // for each pair of bodies
  for (unsigned k=0; k< q.signed_distances.size(); k++)
  {
    // get the two single bodies
    shared_ptr<SingleBodyd> s1 = q.signed_distances[k].a->get_single_body();
    shared_ptr<SingleBodyd> s2 = q.signed_distances[k].b->get_single_body();

    // get the signed distance between the two bodies
    double phi = q.signed_distances[k].dist;

    // integrates bodies' positions forward
    shared_ptr<DynamicBodyd> sup1 = ImpactConstraintHandler::get_super_body(s1);
    shared_ptr<DynamicBodyd> sup2 = ImpactConstraintHandler::get_super_body(s2);
    tmp_supers1.clear();
    tmp_supers1.push_back(sup1);
    if (sup1 != sup2)
      tmp_supers1.push_back(sup2);
    integrate_positions(tmp_supers1, DT);

    // compute the signed distance function
    double phi_new = calc_signed_dist(s1, s2);

    // set the appropriate entry of Cdot(v) 
    Cdot_v[k] = (phi_new - phi)/DT;  

    // restore coordinates and velocities
    restore_coords_and_velocities(tmp_supers1, gc_map, gv_map);
  }  

  // resize the Jacobians
  Cdot_iM_CnT.resize(q.signed_distances.size(), q.N_CONTACTS);
  Cdot_iM_CsT.resize(q.signed_distances.size(), q.N_CONTACTS);
  Cdot_iM_CtT.resize(q.signed_distances.size(), q.N_CONTACTS);
  Cdot_iM_LT.resize(q.signed_distances.size(), q.N_LIMITS);

  // prepare iterators for contacts
  ColumnIteratord Cn_iter = Cdot_iM_CnT.column_iterator_begin();
  ColumnIteratord Cs_iter = Cdot_iM_CsT.column_iterator_begin();
  ColumnIteratord Ct_iter = Cdot_iM_CtT.column_iterator_begin();
  ColumnIteratord L_iter =  Cdot_iM_LT.column_iterator_begin();

  // for each pair of bodies
  for (unsigned k=0; k< q.signed_distances.size(); k++)
  {
    // get the two single bodies
    shared_ptr<SingleBodyd> s1 = q.signed_distances[k].a->get_single_body();
    shared_ptr<SingleBodyd> s2 = q.signed_distances[k].b->get_single_body();

    // get the two bodies involved
    shared_ptr<DynamicBodyd> sup1 = ImpactConstraintHandler::get_super_body(s1);
    shared_ptr<DynamicBodyd> sup2 = ImpactConstraintHandler::get_super_body(s2);
    tmp_supers1.clear();
    tmp_supers1.push_back(sup1);
    tmp_supers1.push_back(sup2);

//.........这里部分代码省略.........
开发者ID:PositronicsLab,项目名称:Moby,代码行数:101,代码来源:SignedDistDot.cpp

示例15: sqr

/**
 * \param x the solution is returned here; zeros will be returned at appropriate indices for inactive contacts
 */
void ImpactConstraintHandler::solve_nqp_work(UnilateralConstraintProblemData& q, VectorNd& x)
{
  const double INF = std::numeric_limits<double>::max();

  // setup constants
  const unsigned N_CONTACTS = q.N_CONTACTS;
  const unsigned N_LIMITS = q.N_LIMITS;
  const unsigned N_CONSTRAINT_EQNS_IMP = q.N_CONSTRAINT_EQNS_IMP; 
  const unsigned CN_IDX = 0;
  const unsigned CS_IDX = N_CONTACTS;
  const unsigned CT_IDX = CS_IDX + N_CONTACTS;
  const unsigned CL_IDX = CT_IDX + N_CONTACTS;
  const unsigned NVARS = N_LIMITS + CL_IDX; 

  // setup the optimization data
  _ipsolver->epd = &q;
  _ipsolver->mu_c.resize(N_CONTACTS);
  _ipsolver->mu_visc.resize(N_CONTACTS);

  // setup true friction cone for every contact
  for (unsigned i=0; i< N_CONTACTS; i++)
  {
    _ipsolver->mu_c[i] = sqr(q.contact_constraints[i]->contact_mu_coulomb);
    _ipsolver->mu_visc[i] = (sqr(q.Cs_v[i]) + sqr(q.Ct_v[i])) *
                       sqr(q.contact_constraints[i]->contact_mu_viscous);
  }

  // setup matrices
  MatrixNd& R = _ipsolver->R;
  MatrixNd& H = _ipsolver->H;
  VectorNd& c = _ipsolver->c; 
  VectorNd& z = _ipsolver->z; 

  // init z (particular solution) 
  z.set_zero(NVARS);

  // first, compute the appropriate nullspace 
  if (N_CONSTRAINT_EQNS_IMP > 0)
  {
    // compute the homogeneous solution
    _A = q.Jx_iM_JxT;
    (_workv = q.Jx_v).negate();
    try
    {
      _LA.solve_LS_fast1(_A, _workv);
    }
    catch (NumericalException e)
    {
      _A = q.Jx_iM_JxT;
      _LA.solve_LS_fast2(_A, _workv);
    }
    z.set_sub_vec(q.ALPHA_X_IDX, _workv);

    // setup blocks of A
    _A.resize(N_CONSTRAINT_EQNS_IMP, NVARS);
    SharedMatrixNd b1 = _A.block(0, N_CONSTRAINT_EQNS_IMP, 0, N_CONTACTS);
    SharedMatrixNd b2 = _A.block(0, N_CONSTRAINT_EQNS_IMP, N_CONTACTS, N_CONTACTS*2);
    SharedMatrixNd b3 = _A.block(0, N_CONSTRAINT_EQNS_IMP, N_CONTACTS*2, N_CONTACTS*3);
    SharedMatrixNd b4 = _A.block(0, N_CONSTRAINT_EQNS_IMP, N_CONTACTS*3, N_CONTACTS*3+N_LIMITS);

    // compute the nullspace
    MatrixNd::transpose(q.Cn_iM_JxT, b1);
    MatrixNd::transpose(q.Cs_iM_JxT, b2);
    MatrixNd::transpose(q.Ct_iM_JxT, b3);
    MatrixNd::transpose(q.L_iM_JxT, b4);
    _LA.nullspace(_A, R);
  }
  else
    // clear the nullspace 
    R.resize(0,0);

  // get number of qp variables
  const unsigned N_PRIMAL = (R.columns() > 0) ? R.columns() : NVARS;

  // setup number of nonlinear inequality constraints
  const unsigned NONLIN_INEQUAL = N_CONTACTS;

  // init the QP matrix and vector
  H.resize(N_PRIMAL, N_PRIMAL);
  c.resize(H.rows());

  // setup row (block) 1 -- Cn * iM * [Cn' Cs Ct' L']
  unsigned col_start = 0, col_end = N_CONTACTS;
  unsigned row_start = 0, row_end = N_CONTACTS;
  SharedMatrixNd Cn_iM_CnT = H.block(row_start, row_end, col_start, col_end);
  col_start = col_end; col_end += N_CONTACTS;
  SharedMatrixNd Cn_iM_CsT = H.block(row_start, row_end, col_start, col_end);
  col_start = col_end; col_end += N_CONTACTS;
  SharedMatrixNd Cn_iM_CtT = H.block(row_start, row_end, col_start, col_end);
  col_start = col_end; col_end += N_LIMITS;
  SharedMatrixNd Cn_iM_LT = H.block(row_start, row_end, col_start, col_end);

  // setup row (block) 2 -- Cs * iM * [Cn' Cs' Ct' L']
  row_start = row_end; row_end += N_CONTACTS;
  col_start = 0; col_end = N_CONTACTS;
  SharedMatrixNd Cs_iM_CnT = H.block(row_start, row_end, col_start, col_end);
  col_start = col_end; col_end += N_CONTACTS;
//.........这里部分代码省略.........
开发者ID:PositronicsLab,项目名称:Moby,代码行数:101,代码来源:ImpactConstraintHandlerNQP.cpp


注:本文中的VectorNd类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。