00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00034 #include "tutsim.hpp"
00035 #include <jspace/test/sai_util.hpp>
00036 #include <boost/shared_ptr.hpp>
00037 #include <err.h>
00038
00039
00040 static std::string model_filename(TUTROB_XML_PATH_STR);
00041 static boost::shared_ptr<jspace::Model> model;
00042
00043
00044 static bool servo_cb(size_t toggle_count,
00045 double wall_time_ms,
00046 double sim_time_ms,
00047 jspace::State & state,
00048 jspace::Vector & command)
00049 {
00050 model->update(state);
00051 jspace::Matrix mass_inertia;
00052 model->getMassInertia(mass_inertia);
00053 jspace::Vector gravity;
00054 model->getGravity(gravity);
00055
00056 static size_t counter(0);
00057 if (0 == (counter % 50)) {
00058 std::cerr << "wall: " << wall_time_ms << " sim: " << sim_time_ms << "\n";
00059 jspace::pretty_print(state.position_, std::cerr, "jpos", " ");
00060 jspace::pretty_print(mass_inertia, std::cerr, "mass_inertia", " ");
00061 jspace::pretty_print(gravity, std::cerr, "gravity", " ");
00062 }
00063 ++counter;
00064
00065 if (0 == (toggle_count % 2)) {
00066 static double const aa(M_PI / 2);
00067 for (int ii(0); ii < state.position_.rows(); ++ii) {
00068 state.position_[ii] = aa * sin((1.0 + 0.1 * ii) * 1e-3 * wall_time_ms);
00069 state.velocity_[ii] = 0.0;
00070 }
00071 return false;
00072 }
00073
00074 command = jspace::Vector::Zero(state.position_.rows());
00075 return true;
00076 }
00077
00078
00079 int main(int argc, char ** argv)
00080 {
00081 try {
00082 model.reset(jspace::test::parse_sai_xml_file(model_filename, true));
00083 }
00084 catch (std::runtime_error const & ee) {
00085 errx(EXIT_FAILURE, "%s", ee.what());
00086 }
00087 return tutsim::run(servo_cb);
00088 }