Skip to content

Commit

Permalink
add comments to pendulum.py example #212
Browse files Browse the repository at this point in the history
  • Loading branch information
dtotsila committed Aug 6, 2024
1 parent b875398 commit 4877fc4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/docs/include/macros.py

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/examples/pendulum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ int main()
ctrl << 0.0;
// @SIMPLE_CONTROL@
auto controller1 = std::make_shared<robot_dart::control::SimpleControl>(ctrl);
// add the controller to the robot, with a default weight of 1.0
robot->add_controller(controller1);
// @SIMPLE_CONTROL_END@
ctrl << -1.0;
auto controller2 = std::make_shared<robot_dart::control::SimpleControl>(ctrl);
// add the controller to the robot, with a weight of 5.0
robot->add_controller(controller2, 5.);

// initialize the simulation with a default timestep of 0.015s
robot_dart::RobotDARTSimu simu;
#ifdef GRAPHIC
simu.set_graphics(std::make_shared<robot_dart::gui::magnum::Graphics>());
#endif
simu.add_robot(robot);

// the the dimensions of the pendulum to calculate the end effector position
Eigen::Vector3d size(0.0402, 0.05, 1);
std::cout << (robot->body_pose("pendulum_link_1") * size).transpose() << std::endl;
simu.run(2.5);
Expand All @@ -34,7 +37,7 @@ int main()
controller1->set_parameters(ctrl);
simu.run(2.5);
std::cout << (robot->body_pose("pendulum_link_1") * size).transpose() << std::endl;

// reset the positions, velocities, and accelerations of the robot, clear internal and external forces, and also commands
robot.reset();
return 0;
}
5 changes: 5 additions & 0 deletions src/examples/python/pendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
ctrl = [0.0]
# @SIMPLE_CONTROL_PYTHON@
controller1 = rd.SimpleControl(ctrl)
# add the controller to the robot, with a default weight of 1.0
robot.add_controller(controller1)
# @SIMPLE_CONTROL_PYTHON_END@
ctrl = [-1.0]
controller2 = rd.SimpleControl(ctrl)
# add the controller to the robot, with a weight of 5.0
robot.add_controller(controller2, 5.)
# initialize the simulation with a default timestep of 0.015s
simu = rd.RobotDARTSimu()

simu.set_graphics(rd.gui.Graphics())

simu.add_robot(robot)
# the dimensions of the pendulum to calculate the end effector position
size = [0.0402, 0.05, 1]
print((robot.body_pose("pendulum_link_1").multiply(size)).transpose())
simu.run(2.5)
Expand All @@ -29,4 +33,5 @@
simu.run(2.5)
print((robot.body_pose("pendulum_link_1").multiply(size)).transpose())

# reset the positions, velocities, and accelerations of the robot, clear internal and external forces, and also commands
robot.reset()

0 comments on commit 4877fc4

Please sign in to comment.