Feature/dynamic model for mock interface - #14
Conversation
| { | ||
| using kinematics_translator = kinematics::KinematicsTranslator<kinematics_mapping>; | ||
|
|
||
| static constexpr bool IS_MOCK_ = is_dua_drive_interface_mock_v<DriveTypeT>; |
There was a problem hiding this comment.
please do not use upper case letters as this will create confusion with macros.
Also (my style) I would move it into the public part of the class and remove the trailing _
| // In case there are predefined positions for mock operation we enforce them | ||
| // This is a pure compile time statement | ||
| if constexpr (std::is_same_v<DriveTypeT, DuaDriveInterfaceMock>) { | ||
| if constexpr (IS_MOCK_) { |
There was a problem hiding this comment.
good idea to replace it like that
| namespace duatic::duadrive_interface::dynamic_model | ||
| { | ||
|
|
||
| void DynamicModelNon::on_init( |
There was a problem hiding this comment.
I dont like the name. It is rather undescriptive.
Also I think for a single function I would not add a cpp file and keep it simply in the header
There was a problem hiding this comment.
other suggestions?
There was a problem hiding this comment.
The DynamicModelNon is bascially just for the standard mock case.
I would just call it like that ?
DynamicModelMock.
Please also see my argument below how I would actually setup the whole structure.
| namespace duatic::duadrive_interface::dynamic_model | ||
| { | ||
|
|
||
| void DynamicModelPinocchio::on_init(const hardware_interface::HardwareComponentInterfaceParams& system_info) |
There was a problem hiding this comment.
You do not need to resemble in your architecture the way a ros2 hardware interface component is built.
The reason the DuaDriveInterfaces are built like this is because they actually need to resemble the same lifestyle model.
But for this dynamic pinocchio model I don't think this is needed (it also creates quite a bit of overhead)
Also I think you could directly pass the urdf model which is created here:
There was a problem hiding this comment.
Pass-by-reference, i.e. no overhead.
(Unlike the logger, which is copied all the way down to the base class)
The idea here was to just pass the entire description because we have and may one day wanna use other information inside ...
There was a problem hiding this comment.
But I change it to pass the urdf
There was a problem hiding this comment.
Do as you find it fitting. My argument about overhead was about creating the urdf::Model twice btw.
There was a problem hiding this comment.
Da hast du recht, das wird zweimal erzeugt.
Ist geändert.
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| #include "duatic_duadrive_interface/dynamic_model/dynamic_model_pinocchio.hpp" |
There was a problem hiding this comment.
In general just as a suggestion: I often avoid creating for every header file a cpp file especially if there is just like one function in there
Reason is: a) amount of files to manage b) in this case one could also argue performance
There was a problem hiding this comment.
@firesurfer Compile-time performance will be better with dedicated cpp files.
If you think about run-time performance, we can link with lto enabled (Link-time-Optimization) to allow function inlining across compilation units.
However, from what I see in the rest of the code, optimizing a single, non-conditional function call is absolutely not the level of optimization that is currently required or matters with respect to optimization potentials throughout the rest of the code.
However, I'm happy about your opinion.
There was a problem hiding this comment.
I think I just come from the other way around. I tend to only add cpp files if I have to. It is more about code organisation overhead.
I can image that LTO might be troublesome if used in a plugin architecture.
There was a problem hiding this comment.
In dem Moment wo du Header-Implementierungen schreibst zwingst du den Linker sowieso schon dazu LTO zu machen um den ganzen doppelten Code zu entfernen.
Also ich glaube was LTO angeht kann man dem Compiler durchaus trauen. (Hab ich aber selbst tatsächlich auch noch nie produktiv benutzt)
There was a problem hiding this comment.
empty cpp removed
| void DuaDriveInterfaceMock::stage_mock_acceleration(const double acceleration) | ||
| { | ||
| mock_acceleration_ = acceleration; | ||
| } |
There was a problem hiding this comment.
Even though this is rather easy to implement this way I would say it might be better to implement it like this:
During creation of each DuaDriveInterfaceMock instance just pass a function pointer which allows each drive to obtain the necessary information from the dynamic model. I would also consider not just returning the acceleration but just the whole state for that specific actuator in that function. This already introduces the necessary infrastructure code for more complex simulation approaches
There was a problem hiding this comment.
@firesurfer
The Problem here is, that the drives themselves have nothing to do with the dynamic model.
Especially, due to the fact that the drives drive coupled kinematics and the model models decoupled kinematics.
There was a problem hiding this comment.
By using a function pointer you fully decouple it. Given that you also create a DynamicNonModel (which is basically -> do nothing) I would argue it is even more consistent to actually just have the Drive instances get that information from the Model and have less stuff in the DuaDriveInterfaceMock. This would even make it more consistent with the real hardware one could argue.
| /** | ||
| * @brief Register a mock dynamics model with the mock hardware | ||
| */ | ||
| void register_mock_dynamics(const std::function<double()>& acceleration_callback) |
There was a problem hiding this comment.
can you pass this via the ctr ?
|
|
||
| target_link_libraries(duatic_duadrive_interface ${YAML_CPP_LIBRARIES}) | ||
| target_link_libraries(duatic_duadrive_interface ${YAML_CPP_LIBRARIES} | ||
| pinocchio::pinocchio |
There was a problem hiding this comment.
move the pinnochio::pinocchio update to the target_link_libraries in line 40
In case we are on older platforms ament_target_dependencies should do the job
firesurfer
left a comment
There was a problem hiding this comment.
Looks good to me. See my small comments of stuff to fix.
Before merging I would suggest we test this out with real hardware just to make sure that we didn't break anything (what I dont expect btw).
Also please test this change against all Duatic hardware components.
Is your plan to ship the DynamicModel as default ? What are the necessary steps in a downstream component to support this ?
Task: https://app.clickup.com/t/86ca8y8tj
Depending on whether you like what you see or not, we may wanna have some discussion about Coding Style, Naming, Dos, Don'ts, what so ever ...