Joint generalized force always returns "0" #372
-
Hey! I've been using ScenarI/O / Gazebo ScenarI/O from this project. Something I've noticed is that the joint generalized force always seems to return "0". Here's the cartpole example, modified in order to reproduce the behavior:
#include <scenario/gazebo/GazeboSimulator.h>
#include <scenario/gazebo/Joint.h>
#include <scenario/gazebo/Model.h>
#include <scenario/gazebo/World.h>
#include <chrono>
#include <string>
#include <thread>
int main(int argc, char* argv[])
{
// Create the simulator
auto gazebo = scenario::gazebo::GazeboSimulator(
/*stepSize=*/0.001, /*rtf=*/1.0, /*stepsPerRun=*/1);
// Initialize the simulator
gazebo.initialize();
// Get the default world
auto world = gazebo.getWorld();
// Insert the ground plane
const std::string groundPlaneSDF = "ground_plane/ground_plane.sdf";
world->insertModel(groundPlaneSDF);
// Select the physics engine
world->setPhysicsEngine(scenario::gazebo::PhysicsEngine::Dart);
// Open the GUI
gazebo.gui();
std::this_thread::sleep_for(std::chrono::seconds(3));
gazebo.run(/*paused=*/true);
// Insert a pendulum
const std::string pendulumURDF = "pendulum/pendulum.urdf";
world->insertModel(/*modelFile=*/pendulumURDF);
gazebo.run(/*paused=*/true);
// Get the pendulum
auto pendulum = world->getModel(/*modelName=*/"pendulum");
// Reset the pole position
auto pivot = pendulum->getJoint("pivot");
auto pivotGazebo = std::static_pointer_cast<scenario::gazebo::Joint>(pivot);
pivotGazebo->resetPosition(0.001);
pendulum->setJointControlMode(scenario::core::JointControlMode::Force);
// Simulate 30 seconds
for (size_t i = 0; i < 30.0 / gazebo.stepSize(); ++i) {
gazebo.run();
pivot->setGeneralizedForceTarget(1.0);
for(auto force : pivotGazebo->jointGeneralizedForce()) {
std::cout << "[pivotGazebo] Joint generalized force: " << force << std::endl;
}
std::cout << "[pivot] Joint generalized force: " << pivot->generalizedForce() << std::endl;
}
// Close the simulator
std::this_thread::sleep_for(std::chrono::seconds(3));
gazebo.close();
return 0;
} For me, the values printed to the terminal are:
Am I missing something perhaps in calling the methods to get the joint generalized force? I'm not sure if this is a bug or if I am incorrectly using the library, hence why I wanted to create a discussion here instead. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Additionally, I was just looking through some of the issues/PRs in this repo. Is the problem above related to #133 and #141 ? If so, then it looks like this may give me what I need:
The output is now:
|
Beta Was this translation helpful? Give feedback.
-
Hi @nicholaspalomo, the situation of joint torques is somewhat complicated.
Hopefully the situation will be fixed soon, but as far as I understood in upstream there are few points to clarify before finalizing this feature. |
Beta Was this translation helpful? Give feedback.
Hi @nicholaspalomo, the situation of joint torques is somewhat complicated.