jrl-umi3218 / mc_rtc

mc_rtc is an interface for simulated and real robotic systems suitable for real-time control
BSD 2-Clause "Simplified" License
122 stars 36 forks source link

Updating GUI information Posture #435

Open MTdeVries opened 9 months ago

MTdeVries commented 9 months ago

Hi I'm currently working on controlling a new robot with a custom made "PartialPostureTask". I load the robot in as is shown in the tutorial of "integrating a new robot in mc_rtc". In this folder I define an initial stance for the robot. While controlling the robot, I remove the existing posture task and add a custom posture task for specified joints. However in the GUI the Posture targets don't seem to get update anymore, in other words the sliders aren't connected. I was therefore wondering if I could include or either overwrite the information of the slider in my code to be able to control certain joints with the sliders in the task.

For elaboration purposes, I added a screencapture below. In the figure the sliders are depicted under the tabs talos_partial_posture task as target. However these are set to the initial stance and don't get updated. Ideally these would get updated and I'm able to set a different position for certain joint while using this custom partialposturetask.

Slider_problem

With kind regards,

Mark

gergondet commented 9 months ago

Hi @MTdeVries

It's hard to tell without seeing the code of your task but the values in the slider are those you provide through the callback for mc_rtc::gui::NumberSlider

In the built-in posture task, the relevant code is here, i.e.

      gui.addElement({"Tasks", name_, "Target"},
                     mc_rtc::gui::NumberSlider(
                         j.name(), [this, jIndex]() { return this->posture_[jIndex][0]; },
                         [jIndex, updatePosture](double v) { updatePosture(jIndex, v); },
                         robots_.robot(rIndex_).ql()[jIndex][0], robots_.robot(rIndex_).qu()[jIndex][0]));

Here, the first callback returns posture_[jIndex][0] which is the target for the given joint, this is the value you are seeing in the GUI.

in other words the sliders aren't connected

I'm guessing you are inheriting the mc_tasks::PostureTask but you are not re-using posture_ to store the target so the sliders appears for the base class?

I was therefore wondering if I could include or either overwrite the information of the slider in my code to be able to control certain joints with the sliders in the task.

You could override addToGUI(mc_rtc::gui::StateBuilder & gui) for your class then:

void MyTask::addToGUI(mc_rtc::gui::StateBuilder & gui)
{
  // Add the GUI of PostureTask
  mc_tasks::PostureTask::addToGUI(gui);
  // Remove the Target elements since we want to override them
  gui.removeCategory({"Tasks", name_, "Target"});
  // Add elements to Target with the behavior you want
  // .... 
}
MTdeVries commented 9 months ago

Thank you for your quick reply, If I understand it correctly I then need to load all joint names in terms of j to be able to updated the sliders? Another problem: I can't seem to adjust the protected gui. Using either:
protected: void addToGUI(mc_rtc::gui::StateBuilder & gui) override; or void addToGUI(mc_rtc::gui::StateBuilder & gui);

in both cases the following inclusion is used: #include <mc_rtc/gui/StateBuilder.h>

The inclusion of this line results in the following error message: Gui_error

With kind regards,

Mark

gergondet commented 9 months ago

If I understand it correctly I then need to load all joint names in terms of j to be able to updated the sliders?

Yes. You have to create a separate NumberSlider for each target you want to set this way.

I can't seem to adjust the protected gui. Using either:

Did you add the corresponding implementation? The error you're getting might be due to unresolved symbols.