00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00036 #include "tutsim.hpp"
00037
00038
00039 static bool servo_cb(size_t toggle_count,
00040 double wall_time_ms,
00041 double sim_time_ms,
00042 jspace::State & state,
00043 jspace::Vector & command)
00044 {
00045 if (0 == (toggle_count % 2)) {
00046 command = -400.0 * state.position_ - 20.0 * state.velocity_;
00047 }
00048 else {
00049 command = jspace::Vector::Zero(state.position_.rows());
00050 int const idx(command.rows() - 1);
00051 double dq_des(15.0);
00052 if (fmod(sim_time_ms, 4e3) > 2e3) {
00053 dq_des = -dq_des;
00054 }
00055 command[idx] = dq_des - 2.0 * state.velocity_[idx];
00056 }
00057
00058 static size_t iteration(0);
00059 if (0 == (iteration++ % 100)) {
00060 std::cerr << "sim_time_ms: " << sim_time_ms << "\n";
00061 jspace::pretty_print(state.position_, std::cerr, "jpos", " ");
00062 jspace::pretty_print(state.velocity_, std::cerr, "jvel", " ");
00063 jspace::pretty_print(command, std::cerr, "command", " ");
00064 }
00065
00066 return true;
00067 }
00068
00069
00070 int main(int argc, char ** argv)
00071 {
00072 return tutsim::run(servo_cb);
00073 }