38 #include <exotica_core/planning_problem_initializer.h> 39 #include <exotica_core/task_map_initializer.h> 49 ret +=
"\n" + prepend +
" Task definitions:";
51 ret +=
"\n" + it.second->Print(prepend +
" ");
57 return scene_->get_num_positions();
62 return scene_->get_num_velocities();
67 return scene_->get_num_controls();
73 if (
scene_->GetDynamicsSolver() !=
nullptr)
75 const Eigen::VectorXd start_state =
scene_->GetDynamicsSolver()->GetPosition(
start_state_);
83 return scene_->GetControlledState();
88 for (
auto& it :
task_maps_) it.second->PreUpdate();
93 const auto num_states =
scene_->get_num_positions() +
scene_->get_num_velocities();
94 if (x.rows() == num_states)
98 else if (x.rows() ==
scene_->GetKinematicTree().GetNumControlledJoints())
100 std::vector<std::string> jointNames =
scene_->GetControlledJointNames();
101 std::vector<std::string> modelNames =
scene_->GetModelJointNames();
102 for (
int i = 0; i < jointNames.size(); ++i)
104 for (
int j = 0; j < modelNames.size(); ++j)
106 if (jointNames[i] == modelNames[j])
start_state_[j] = x(i);
110 else if (x.rows() ==
scene_->get_num_positions())
117 ThrowNamed(
"Wrong start state vector size, expected " << num_states <<
", got " << x.rows());
139 PlanningProblemInitializer init(init_in);
146 scene_->InstantiateInternal(SceneInitializer(init.PlanningScene));
151 N =
scene_->GetKinematicTree().GetNumControlledJoints();
155 if (init.StartState.rows() > 0)
159 if (
scene_->GetDynamicsSolver() !=
nullptr &&
161 scene_->GetDynamicsSolver()->get_num_state() ==
scene_->GetDynamicsSolver()->get_num_state_derivative() + 1)
167 if (init.StartTime < 0)
ThrowNamed(
"Invalid start time " << init.StartTime);
171 switch (init.DerivativeOrder)
186 ThrowPretty(
"Unsupported DerivativeOrder: " << init.DerivativeOrder);
194 for (
const Initializer& MapInitializer : init.Maps)
197 new_map->AssignScene(
scene_);
198 new_map->ns_ =
ns_ +
"/" + new_map->GetObjectName();
201 ThrowNamed(
"Map '" + new_map->GetObjectName() +
"' already exists!");
203 std::vector<KinematicFrameRequest> frames = new_map->GetFrames();
205 for (
size_t i = 0; i < new_map->kinematics.size(); ++i)
209 request.
frames.insert(request.
frames.end(), frames.begin(), frames.end());
210 task_maps_[new_map->GetObjectName()] = new_map;
211 tasks_.push_back(new_map);
217 for (
int i = 0; i <
tasks_.size(); ++i)
222 tasks_[i]->start_jacobian = idJ;
223 tasks_[i]->length_jacobian =
tasks_[i]->TaskSpaceJacobianDim();
225 idJ +=
tasks_[i]->length_jacobian;
228 if (
debug_ && init.Maps.size() == 0)
237 task->kinematics[0].Create(response);
244 if (task->kinematics.size() > responses.size())
246 ThrowNamed(responses.size() <<
" responses provided but task " << task->GetObjectName() <<
" requires " << task->kinematics.size());
249 for (
size_t i = 0; i < task->kinematics.size(); ++i)
251 task->kinematics[i].Create(responses[i]);
273 std::pair<std::vector<double>, std::vector<double>> ret;
274 for (
size_t position = 0; position <
cost_evolution_.size(); ++position)
277 double time_point = std::chrono::duration_cast<std::chrono::duration<double>>(
cost_evolution_[position].first -
cost_evolution_[0].first).count();
278 ret.first.push_back(time_point);
295 else if (index == -1)
308 cost_evolution_.assign(size, std::make_pair<std::chrono::high_resolution_clock::time_point, double>(std::chrono::high_resolution_clock::now(), std::numeric_limits<double>::quiet_NaN()));
315 cost_evolution_[index].first = std::chrono::high_resolution_clock::now();
318 else if (index == -1)
KinematicRequestFlags flags_
std::shared_ptr< TaskMap > TaskMapPtr
Task Map smart pointer.
int get_num_positions() const
! Dimension of planning problem. TODO: Update from positions/velocities/controls and make private...
virtual Eigen::VectorXd ApplyStartState(bool update_traj=true)
std::vector< KinematicFrameRequest > frames
void NormalizeQuaternionInConfigurationVector(Eigen::Ref< Eigen::VectorXd > q)
void InstantiateBase(const Initializer &init) override
virtual ~PlanningProblem()
void InstantiateObject(const Initializer &init)
void UpdateTaskKinematics(std::shared_ptr< KinematicResponse > response)
int get_num_controls() const
std::vector< std::pair< std::chrono::high_resolution_clock::time_point, double > > cost_evolution_
void ResetCostEvolution(size_t size)
std::vector< TaskMapPtr > TaskMapVec
std::shared_ptr< Scene > ScenePtr
TaskMapMap & GetTaskMaps()
std::string Print(const std::string &prepend) const override
int get_num_velocities() const
void SetStartTime(double t)
KinematicRequestFlags flags
std::pair< std::vector< double >, std::vector< double > > GetCostEvolution() const
The KinematicSolution is created from - and maps into - a KinematicResponse.
int GetNumberOfIterations() const
The class of EXOTica Scene.
const Eigen::Ref< const Eigen::VectorXd > & VectorXdRefConst
Convenience wrapper for storing references to sub-matrices/vectors.
Eigen::VectorXd GetStartState() const
void UpdateMultipleTaskKinematics(std::vector< std::shared_ptr< KinematicResponse >> responses)
void SetCostEvolution(int index, double value)
void SetStartState(Eigen::VectorXdRefConst x)
std::map< std::string, TaskMapPtr > TaskMapMap
The mapping by name of TaskMaps.
double GetStartTime() const
ScenePtr GetScene() const
static std::shared_ptr< exotica::TaskMap > CreateMap(const std::string &type, bool prepend=true)
virtual std::string Print(const std::string &prepend) const
Eigen::VectorXd start_state_