Hi Prof. Hauser,
I am not pretty clear about how to change the low-level configuration reference with SetPIDCommand function. For example, if I have two configurations:
- config_init is the initial robot configuration.
- config_goal is the new goal configuration.
My idea is to use the SetPIDCommand to let the robot move to config_goal and remain here. However, if I use this command directly into the simulation loop, the controller does not bring the robot towards config_goal but still stays at config_init for the whole duration of simulation. So is there something wrong with the way I use the SetPIDCommand?
This is the sample code.
#include <Klampt/Interface/SimulationGUI.h>
int main(int argc,const char** argv) {
//create a world
RobotWorld world;
SimGUIBackend backend(&world);
WorldSimulation& sim=backend.sim;
//line arguments like SimTest
if(!backend.LoadAndInitSim(argc,argv)) {
cerr<<"Error loading simulation from command line"<<endl;
return 1;
}
//pick some duration between printouts in main loop
double dt = 0.1;
//run the simulation
Config config_goal;
sim.robotControllers[0]->GetCommandedConfig(config_goal);
config_goal[7] -= 1.0;
std::cout<<"Goal Config: ";
std::cout<<config_goal<<endl;
while(sim.time < 5) {
sim.robotControllers[0]->SetPIDCommand(config_goal);
sim.Advance(dt);
//update the world
sim.UpdateModel();
//print time, robot 0's configuration
cout<<sim.time<<'\t'<<world.robots[0]->q<<endl;
//Uncomment the following line to log the true state of
//the robot to disk.
//backend.DoStateLogging_LinearPath(0,"test_state.path");
}
return 0;
}