In Box2D is a platform given with a ball on top. The platform can be moved to left and right, and the object is moving according to standard gravity of 9.8f which is set in the Box2D setting. To make the task a bit harder, there are two platforms at the same time. Left in the image is the demonstration and right is the repetition. The repetition platform gets the same input signals but starts with a slightly different position of the object. The position of the ball can be retrieved in realtime from the program.

The human operator is sending a “left” command, the platform is moving and the ball is rolling. How the controller looks like for the repetition platform if both balls should be in the same position?

enter image description here

My efforts to solve the problem

  1. I've created the sourcecode in C++ which is 420 lines long
  2. I've programmed a manual controller for testing if the physics engine works
  3. I read some papers about Dynamic movement primitives, Learning from demonstration and Tracking control

But it seems, that something is missing for solving the problem. Any advice is welcome.


The controller is executed in the mainloop. It works currently as a normal pid-controller, which measures the difference between the x-positions of both balls and executes a left or right counteraction. The idea is, that the human-operator controls the demonstration and this modifies the pid-control loop in the agent. But in most cases, it works not very well. The controller is not very intelligent.


class Agent {
  void automode() {
    int posA=myphysics.mybox[6].positioncenter.x-200;
    int posB=myphysics.mybox[9].positioncenter.x-400;
    int diff = posB-posA;
    std::cout << mysettings.framestep << " "<<diff << "\n";
    if (diff>0) {
      std::thread t1;
      t1=std::thread(&Agent::autoleftrun, this);
    if (diff<-0) {
      std::thread t1;
      t1=std::thread(&Agent::autorightrun, this);
  • $\begingroup$ Be more specific..like what is your code doing? And why? $\endgroup$ – DuttaA Feb 14 '18 at 11:39
  • $\begingroup$ What is the link with AI ? $\endgroup$ – Jérémy Blain Nov 27 '18 at 15:08
  • $\begingroup$ @JérémyBlain It's a very old post, many months ago. The idea was to build some kind of AI planning system. In the description the forward simulation is given, that means a balance task for a moving ball. And the AI controller should generate the actions to reach a certain state in the system. In the literature the problem is called model predictive control, and i have no idea how to solve it. $\endgroup$ – Manuel Rodriguez Nov 27 '18 at 16:04
  • $\begingroup$ I didn't understand well what the program does, and what the goal is. You have two balls on a box, they start at different positions on the box, and your goal is to put them on the same position on their box, given the fact that both box moves the same way ? Is that right ? $\endgroup$ – Jérémy Blain Nov 27 '18 at 17:52
  • $\begingroup$ @JérémyBlain It is a teleoperation mirror, the same system is available twice. The advantage over a single system is, that from the beginning their is a bug, because both systems are not synchronized. Even the human operator is able to bring the ball into the goal position, he has lost the game, because the second system doesn't follow. $\endgroup$ – Manuel Rodriguez Nov 27 '18 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.