Skip to content

Commit 585c5db

Browse files
authored
Merge pull request #425 from antodld/topic/guiRobotMsg
[mc_rtc_gui] change the robot type to handle more informations of mc_rbdyn::Robot
2 parents be8887c + bf72892 commit 585c5db

File tree

5 files changed

+117
-1
lines changed

5 files changed

+117
-1
lines changed

include/mc_control/ControllerClient.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ struct MC_CONTROL_CLIENT_DLLAPI ControllerClient
461461
default_impl("Robot", id);
462462
}
463463

464+
virtual void robot_msg(const ElementId & id, const mc_rtc::gui::RobotMsgData & /*msg*/)
465+
{
466+
default_impl("RobotMsg", id);
467+
}
468+
464469
/** Should display the visual element \p visual at the position \p pose */
465470
virtual void visual(const ElementId & id,
466471
[[maybe_unused]] const rbd::parsers::Visual & visual,

include/mc_rtc/gui/RobotMsg.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2015-2020 CNRS-UM LIRMM, CNRS-AIST JRL
3+
*/
4+
5+
#pragma once
6+
7+
#include <mc_rtc/gui/details/traits.h>
8+
#include <mc_rtc/gui/elements.h>
9+
#include <mc_rtc/gui/types.h>
10+
11+
#include <mc_rbdyn/Robot.h>
12+
13+
namespace mc_rtc::gui
14+
{
15+
16+
namespace details
17+
{
18+
19+
/** Robot should display a robot model in the environment
20+
*
21+
* The element provides the following data to the client:
22+
* - the parameters passed to RobotLoader to get the RobotModule (vector<string>)
23+
* - the current robot configuration (vector<vector<double>>)
24+
*
25+
* \tparam GetT Should return an mc_rbdyn::Robot
26+
*/
27+
template<typename GetT>
28+
struct RobotMsgImpl : public Element
29+
{
30+
static constexpr auto type = Elements::RobotMsg;
31+
32+
RobotMsgImpl(const std::string & name, GetT get_fn) : Element(name), get_fn_(get_fn)
33+
{
34+
static_assert(CheckReturnType<GetT, mc_rbdyn::Robot>::value, "Robot element must return an mc_rbdyn::Robot");
35+
}
36+
37+
static constexpr size_t write_size() { return Element::write_size() + 7; }
38+
39+
void write(mc_rtc::MessagePackBuilder & builder)
40+
{
41+
const mc_rbdyn::Robot & robot = get_fn_();
42+
update(robot);
43+
Element::write(builder);
44+
builder.write(robot.module().parameters());
45+
builder.write(msg_.q);
46+
builder.write(msg_.alpha);
47+
builder.write(msg_.alphaD);
48+
builder.write(msg_.tau);
49+
builder.write(robot.mbc().force);
50+
builder.write(robot.posW());
51+
}
52+
53+
private:
54+
GetT get_fn_;
55+
RobotMsgData msg_;
56+
57+
void update(const mc_rbdyn::Robot & robot)
58+
{
59+
msg_.q.resize(robot.mb().nrParams());
60+
rbd::paramToVector(robot.mbc().q, msg_.q);
61+
msg_.alpha.resize(robot.mb().nrDof());
62+
rbd::paramToVector(robot.mbc().alpha, msg_.alpha);
63+
msg_.alphaD.resize(msg_.alpha.size());
64+
rbd::paramToVector(robot.mbc().alphaD, msg_.alphaD);
65+
msg_.tau.resize(msg_.alpha.size());
66+
rbd::paramToVector(robot.mbc().jointTorque, msg_.tau);
67+
}
68+
};
69+
70+
} // namespace details
71+
72+
/** Helper function to create a RobotImpl */
73+
template<typename GetT>
74+
auto RobotMsg(const std::string & name, GetT get_fn)
75+
{
76+
return details::RobotMsgImpl(name, get_fn);
77+
}
78+
79+
} // namespace mc_rtc::gui

include/mc_rtc/gui/elements.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ enum class Elements
4848
PolyhedronTrianglesList,
4949
PolyhedronVerticesTriangles,
5050
GenericArray,
51-
OneOf
51+
OneOf,
52+
RobotMsg
5253
};
5354

5455
/** Element is the common class for every element's type available in the

include/mc_rtc/gui/types.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,31 @@ struct MC_RTC_GUI_DLLAPI PolyhedronConfig
476476
///< passed along with the triangles
477477
bool fixed_vertices_color = true;
478478
};
479+
480+
/** Provides full information about a robot kinematic and dynamic state */
481+
struct MC_RTC_GUI_DLLAPI RobotMsgData
482+
{
483+
RobotMsgData() = default;
484+
RobotMsgData(const std::vector<std::string> & params,
485+
const Eigen::VectorXd & q,
486+
const Eigen::VectorXd & alpha,
487+
const Eigen::VectorXd & alphaD,
488+
const Eigen::VectorXd & tau,
489+
const std::vector<sva::ForceVecd> & forces,
490+
const sva::PTransformd & posW)
491+
: parameters(params), q(q), alpha(alpha), alphaD(alphaD), tau(tau), forces(forces), posW(posW)
492+
{
493+
}
494+
495+
std::vector<std::string> parameters;
496+
Eigen::VectorXd q;
497+
Eigen::VectorXd alpha;
498+
Eigen::VectorXd alphaD;
499+
Eigen::VectorXd tau;
500+
std::vector<sva::ForceVecd> forces;
501+
sva::PTransformd posW;
502+
};
503+
479504
} // namespace gui
480505

481506
template<>

src/mc_control/ControllerClient.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ void ControllerClient::handle_widget(const ElementId & id, const mc_rtc::Configu
375375
case Elements::Robot:
376376
robot(id, data[3], data[4], data[5]);
377377
break;
378+
case Elements::RobotMsg:
379+
{
380+
mc_rtc::gui::RobotMsgData msg(data[3], data[4], data[5], data[6], data[7], data[8], data[9]);
381+
robot_msg(id, msg);
382+
break;
383+
}
378384
case Elements::Visual:
379385
if(data[4].size() == 3)
380386
{

0 commit comments

Comments
 (0)