From: Jiri Vlasak Date: Tue, 15 Jun 2021 12:41:09 +0000 (+0200) Subject: Add gobackward ctrl X-Git-Url: http://rtime.felk.cvut.cz/gitweb/hubacji1/simple-stage.git/commitdiff_plain/c58d2e44bd3114f52adb56f18815ca0bea885b91 Add gobackward ctrl --- diff --git a/README.md b/README.md index 33e0120..233e797 100644 --- a/README.md +++ b/README.md @@ -57,4 +57,7 @@ Test race track The _test race track_ and `tx2-auto-3` are used in F1/10 project of [IID][] group. The `libgoforward` controls the robot to just go straight. +`libgobackward` is the same as `libgoforward` but with the negative speed. It's +written in more OOP way. + [IID]: https://iid.ciirc.cvut.cz/ diff --git a/ctrl/gobackward.cc b/ctrl/gobackward.cc new file mode 100644 index 0000000..9a8b2a1 --- /dev/null +++ b/ctrl/gobackward.cc @@ -0,0 +1,21 @@ +#include "stage.hh" +using namespace Stg; + +class ControlledRobot { +private: + ModelPosition *pos = nullptr; +public: + ControlledRobot(Model *m) : pos(dynamic_cast(m)) + { + assert(this->pos != nullptr); + this->pos->Subscribe(); + } + ModelPosition *get_pos() const { return this->pos; } +}; + +extern "C" int Init(Model *model, CtrlArgs *) +{ + auto r = new ControlledRobot(model); + r->get_pos()->SetXSpeed(-3.0); + return 0; +} diff --git a/meson.build b/meson.build index b343b50..cc911ce 100644 --- a/meson.build +++ b/meson.build @@ -9,3 +9,8 @@ library('goforward', dependencies: stgdep, include_directories: stginc, ) +library('gobackward', + 'ctrl/gobackward.cc', + dependencies: stgdep, + include_directories: stginc, +)