JSMP.cpp
Go to the documentation of this file.
1#include "JSMP.h"
2
3#include <SimoxUtility/math/compare/is_equal.h>
4#include <SimoxUtility/math/convert/mat4f_to_pos.h>
5#include <SimoxUtility/math/convert/mat4f_to_quat.h>
6#include <VirtualRobot/MathTools.h>
7
9
10#include "../utils.h"
11
13{
14
15 JSMP::JSMP(const arondto::MPConfig& c) : MP{c}
16 {
17 ARMARX_INFO << "-- created JSMP with name: " << VAROUT(cfg.name);
18 // if (cfg.viaPoints.size() > 0)
19 // {
20 // for (const auto& vp : cfg.viaPoints)
21 // {
22 // ARMARX_IMPORTANT << VAROUT(vp.canonicalValue) << " " << VAROUT(common::dVecToString(vp.viaPointValue)) << " " << VAROUT(vmp->getUmin());
23 // ARMARX_CHECK_GREATER_EQUAL(vp.canonicalValue, 0);
24 // ARMARX_CHECK_LESS_EQUAL(vp.canonicalValue, 1);
25 // userDefinedViaPoints.push_back({vp.canonicalValue, vp.viaPointValue});
26 // }
27 // }
28 }
29
30 void
31 JSMP::run(MPInputPtr input, MPOutputPtr output, const PhaseStopResult& phase)
32 {
33 if (not running.load())
34 {
35 return;
36 }
37 JSMPInputPtr in = std::dynamic_pointer_cast<JSMPInput>(input);
38 JSMPOutputPtr out = std::dynamic_pointer_cast<JSMPOutput>(output);
39 ARMARX_CHECK_NOT_NULL(in) << "\nInput pointer for JSMP has wrong type or empty";
40 ARMARX_CHECK_NOT_NULL(out) << "\nOutput pointer for JSMP has wrong type or empty";
41
42 out->angularVel.setZero(in->angularVel.size());
43 if (paused.load())
44 {
45 return;
46 }
47
48 // ARMARX_INFO << VAROUT(canonicalValue);
49 double phaseStop = phase.phaseStop;
50 double tau = 1.0;
51
52 if (canonicalValue < 0.01 && cfg.mpStyle == "Periodic")
53 {
54 canonicalValue = 1.0;
55 }
56 if (canonicalValue < 1e-8 && cfg.mpStyle == "Discrete")
57 {
58 ARMARX_INFO << " -- Discrete mode: MP " << cfg.name << " finished.";
59 running.store(false);
60 return;
61 }
62
64 ARMARX_CHECK_EQUAL(in->angleRadian.size(), in->angularVel.size());
65 for (int i = 0; i < in->angleRadian.size(); i++)
66 {
67 currentState[i].pos = in->angleRadian(i);
68 currentState[i].vel = in->angularVel(i);
69 }
70 double deltaT = in->deltaT;
71
72 double timeDuration = cfg.durationSec;
73 canonicalValue -= tau * deltaT / ((1 + phaseStop) * timeDuration);
74
75 std::vector<mplib::representation::MPState> targetState =
76 std::dynamic_pointer_cast<mplib::representation::vmp::PrincipalComponentVMP>(vmp)
77 ->calculateDesiredState(canonicalValue, currentState);
78
79 ARMARX_CHECK_EQUAL(out->angleRadian.size(), out->angularVel.size());
80 for (int i = 0; i < in->angleRadian.size(); i++)
81 {
82 out->angleRadian(i) = targetState[i].pos;
83 out->angularVel(i) = targetState[i].vel;
84 // ARMARX_INFO << VAROUT(targetState[i].pos) << VAROUT(targetState[i].vel);
85 }
86 if (firstRun.load())
87 {
88 firstRun.store(false);
89 }
90 }
91
92} // namespace armarx::control::common::mp
#define VAROUT(x)
constexpr T c
void run(MPInputPtr, MPOutputPtr, const PhaseStopResult &phase) override
Definition JSMP.cpp:31
JSMP(const arondto::MPConfig &c)
Definition JSMP.cpp:15
MP(const MPConfig &c)
Definition MP.cpp:17
std::atomic_bool running
Definition MP.h:167
std::vector< mplib::representation::MPState > currentState
Definition MP.h:180
std::atomic_bool firstRun
Definition MP.h:172
std::atomic_bool paused
Definition MP.h:169
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file is part of ArmarX.
std::lock_guard< std::recursive_mutex > LockGuardType
Definition MP.h:45
std::shared_ptr< MPInput > MPInputPtr
Definition MP.h:70
std::shared_ptr< JSMPOutput > JSMPOutputPtr
Definition JSMP.h:48
std::shared_ptr< MPOutput > MPOutputPtr
Definition MP.h:71
std::shared_ptr< JSMPInput > JSMPInputPtr
Definition JSMP.h:47