]> rtime.felk.cvut.cz Git - hubacji1/simple-stage.git/commitdiff
Add gobackward ctrl
authorJiri Vlasak <jiri.vlasak.2@cvut.cz>
Tue, 15 Jun 2021 12:41:09 +0000 (14:41 +0200)
committerJiri Vlasak <jiri.vlasak.2@cvut.cz>
Thu, 17 Jun 2021 15:28:02 +0000 (17:28 +0200)
README.md
ctrl/gobackward.cc [new file with mode: 0644]
meson.build

index 33e0120e84c04c17b6ccaa7aaf3a7765716fae35..233e79767cbfff6f077a5c3ba0db3f10b838dc84 100644 (file)
--- 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 (file)
index 0000000..9a8b2a1
--- /dev/null
@@ -0,0 +1,21 @@
+#include "stage.hh"
+using namespace Stg;
+
+class ControlledRobot {
+private:
+       ModelPosition *pos = nullptr;
+public:
+       ControlledRobot(Model *m) : pos(dynamic_cast<ModelPosition *>(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;
+}
index b343b504320d048083bdd92c637e3c321d5fd413..cc911ce17f8bdd64ee9a0762b7cb6c681ac47b94 100644 (file)
@@ -9,3 +9,8 @@ library('goforward',
        dependencies: stgdep,
        include_directories: stginc,
 )
+library('gobackward',
+       'ctrl/gobackward.cc',
+       dependencies: stgdep,
+       include_directories: stginc,
+)