GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: benchmark/factory/arm-kinova.hpp Lines: 0 23 0.0 %
Date: 2024-02-13 11:12:33 Branches: 0 68 0.0 %

Line Branch Exec Source
1
///////////////////////////////////////////////////////////////////////////////
2
// BSD 3-Clause License
3
//
4
// Copyright (C) 2019-2021, University of Edinburgh, LAAS-CNRS
5
// Copyright note valid unless otherwise stated in individual files.
6
// All rights reserved.
7
///////////////////////////////////////////////////////////////////////////////
8
9
#ifndef CROCODDYL_ARM_KINOVA_FACTORY_HPP_
10
#define CROCODDYL_ARM_KINOVA_FACTORY_HPP_
11
12
#include <example-robot-data/path.hpp>
13
#include <pinocchio/algorithm/model.hpp>
14
#include <pinocchio/parsers/srdf.hpp>
15
#include <pinocchio/parsers/urdf.hpp>
16
17
#include "crocoddyl/core/costs/cost-sum.hpp"
18
#include "crocoddyl/core/costs/residual.hpp"
19
#include "crocoddyl/core/integrator/euler.hpp"
20
#include "crocoddyl/core/mathbase.hpp"
21
#include "crocoddyl/core/residuals/control.hpp"
22
#include "crocoddyl/multibody/actions/free-fwddyn.hpp"
23
#include "crocoddyl/multibody/actuations/full.hpp"
24
#include "crocoddyl/multibody/residuals/frame-placement.hpp"
25
#include "crocoddyl/multibody/residuals/state.hpp"
26
#include "crocoddyl/multibody/states/multibody.hpp"
27
28
namespace crocoddyl {
29
namespace benchmark {
30
31
template <typename Scalar>
32
void build_arm_kinova_action_models(
33
    boost::shared_ptr<crocoddyl::ActionModelAbstractTpl<Scalar> >& runningModel,
34
    boost::shared_ptr<crocoddyl::ActionModelAbstractTpl<Scalar> >&
35
        terminalModel) {
36
  typedef typename crocoddyl::DifferentialActionModelFreeFwdDynamicsTpl<Scalar>
37
      DifferentialActionModelFreeFwdDynamics;
38
  typedef typename crocoddyl::IntegratedActionModelEulerTpl<Scalar>
39
      IntegratedActionModelEuler;
40
  typedef typename crocoddyl::CostModelSumTpl<Scalar> CostModelSum;
41
  typedef typename crocoddyl::ActuationModelFullTpl<Scalar> ActuationModelFull;
42
  typedef typename crocoddyl::CostModelAbstractTpl<Scalar> CostModelAbstract;
43
  typedef typename crocoddyl::CostModelResidualTpl<Scalar> CostModelResidual;
44
  typedef typename crocoddyl::ResidualModelFramePlacementTpl<Scalar>
45
      ResidualModelFramePlacement;
46
  typedef typename crocoddyl::ResidualModelStateTpl<Scalar> ResidualModelState;
47
  typedef typename crocoddyl::ResidualModelControlTpl<Scalar>
48
      ResidualModelControl;
49
  typedef typename crocoddyl::MathBaseTpl<Scalar>::Vector3s Vector3s;
50
  typedef typename crocoddyl::MathBaseTpl<Scalar>::Matrix3s Matrix3s;
51
52
  // because urdf is not supported with all scalar types.
53
  pinocchio::ModelTpl<double> modeld;
54
  pinocchio::urdf::buildModel(EXAMPLE_ROBOT_DATA_MODEL_DIR
55
                              "/kinova_description/robots/kinova.urdf",
56
                              modeld);
57
  pinocchio::srdf::loadReferenceConfigurations(
58
      modeld,
59
      EXAMPLE_ROBOT_DATA_MODEL_DIR "/kinova_description/srdf/kinova.srdf",
60
      false);
61
  pinocchio::ModelTpl<Scalar> model(modeld.cast<Scalar>());
62
63
  boost::shared_ptr<crocoddyl::StateMultibodyTpl<Scalar> > state =
64
      boost::make_shared<crocoddyl::StateMultibodyTpl<Scalar> >(
65
          boost::make_shared<pinocchio::ModelTpl<Scalar> >(model));
66
67
  boost::shared_ptr<CostModelAbstract> goalTrackingCost =
68
      boost::make_shared<CostModelResidual>(
69
          state, boost::make_shared<ResidualModelFramePlacement>(
70
                     state, model.getFrameId("j2s6s200_end_effector"),
71
                     pinocchio::SE3Tpl<Scalar>(
72
                         Matrix3s::Identity(),
73
                         Vector3s(Scalar(0), Scalar(0), Scalar(.4)))));
74
  boost::shared_ptr<CostModelAbstract> xRegCost =
75
      boost::make_shared<CostModelResidual>(
76
          state, boost::make_shared<ResidualModelState>(state));
77
  boost::shared_ptr<CostModelAbstract> uRegCost =
78
      boost::make_shared<CostModelResidual>(
79
          state, boost::make_shared<ResidualModelControl>(state));
80
81
  // Create a cost model per the running and terminal action model.
82
  boost::shared_ptr<CostModelSum> runningCostModel =
83
      boost::make_shared<CostModelSum>(state);
84
  boost::shared_ptr<CostModelSum> terminalCostModel =
85
      boost::make_shared<CostModelSum>(state);
86
87
  // Then let's added the running and terminal cost functions
88
  runningCostModel->addCost("gripperPose", goalTrackingCost, Scalar(1));
89
  runningCostModel->addCost("xReg", xRegCost, Scalar(1e-4));
90
  runningCostModel->addCost("uReg", uRegCost, Scalar(1e-4));
91
  terminalCostModel->addCost("gripperPose", goalTrackingCost, Scalar(1));
92
93
  // We define an actuation model
94
  boost::shared_ptr<ActuationModelFull> actuation =
95
      boost::make_shared<ActuationModelFull>(state);
96
97
  // Next, we need to create an action model for running and terminal knots. The
98
  // forward dynamics (computed using ABA) are implemented
99
  // inside DifferentialActionModelFullyActuated.
100
  boost::shared_ptr<DifferentialActionModelFreeFwdDynamics> runningDAM =
101
      boost::make_shared<DifferentialActionModelFreeFwdDynamics>(
102
          state, actuation, runningCostModel);
103
104
  // VectorXs armature(state->get_nq());
105
  // armature << 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.;
106
  // runningDAM->set_armature(armature);
107
  // terminalDAM->set_armature(armature);
108
  runningModel =
109
      boost::make_shared<IntegratedActionModelEuler>(runningDAM, Scalar(1e-3));
110
  terminalModel =
111
      boost::make_shared<IntegratedActionModelEuler>(runningDAM, Scalar(0.));
112
}
113
114
}  // namespace benchmark
115
}  // namespace crocoddyl
116
117
#endif  // CROCODDYL_ARM_FACTORY_HPP_