diff --git a/Examples/BB2B/BB2B.cs b/Examples/BB2B/BB2B.cs index 9429ddc..d694a87 100644 --- a/Examples/BB2B/BB2B.cs +++ b/Examples/BB2B/BB2B.cs @@ -1,31 +1,37 @@ -using System.Threading; + using RoboidControl; -class BB2B { - static void Main() { +class BB2B : Thing { + readonly DifferentialDrive drive; + readonly TouchSensor touchLeft; + readonly TouchSensor touchRight; + + public BB2B() : base(128) { // thingType = 128 + // The robot's propulsion is a differential drive - DifferentialDrive bb2b = new(); + drive = new(); + // Is has a touch sensor at the front left of the roboid - TouchSensor touchLeft = new(bb2b); + touchLeft = new(drive); // and other one on the right - TouchSensor touchRight = new(bb2b); + touchRight = new(drive); + } - // Do forever: - while (true) { - // The left wheel turns forward when nothing is touched on the right side - // and turn backward when the roboid hits something on the right - float leftWheelSpeed = touchRight.touchedSomething ? -600.0f : 600.0f; - // The right wheel does the same, but instead is controlled by - // touches on the left side - float rightWheelSpeed = touchLeft.touchedSomething ? -600.0f : 600.0f; - // When both sides are touching something, both wheels will turn backward - // and the roboid will move backwards - bb2b.SetWheelVelocity(leftWheelSpeed, rightWheelSpeed); + public override void Update(ulong currentTimeMs, bool recurse = true) { - // Update the roboid state - bb2b.Update(true); - // and sleep for 100ms - Thread.Sleep(100); - } + // The left wheel turns forward when nothing is touched on the right side + // and turn backward when the roboid hits something on the right + float leftWheelSpeed = touchRight.touchedSomething ? -600.0f : 600.0f; + + // The right wheel does the same, but instead is controlled by + // touches on the left side + float rightWheelSpeed = touchLeft.touchedSomething ? -600.0f : 600.0f; + + // When both sides are touching something, both wheels will turn backward + // and the roboid will move backwards + + drive.SetWheelVelocity(leftWheelSpeed, rightWheelSpeed); + + base.Update(currentTimeMs, recurse); } } \ No newline at end of file diff --git a/Examples/BB2B/Program.cs b/Examples/BB2B/Program.cs new file mode 100644 index 0000000..a00023f --- /dev/null +++ b/Examples/BB2B/Program.cs @@ -0,0 +1,12 @@ +using System.Threading; + +class Program { + static void Main() { + BB2B bb2b = new(); + + while (true) { + bb2b.Update(); + Thread.Sleep(100); + } + } +} \ No newline at end of file