Changed BB2B into a Thing class
This commit is contained in:
parent
58b4d2cada
commit
cd76da6a7d
@ -1,31 +1,37 @@
|
|||||||
using System.Threading;
|
|
||||||
using RoboidControl;
|
using RoboidControl;
|
||||||
|
|
||||||
class BB2B {
|
class BB2B : Thing {
|
||||||
static void Main() {
|
readonly DifferentialDrive drive;
|
||||||
// The robot's propulsion is a differential drive
|
readonly TouchSensor touchLeft;
|
||||||
DifferentialDrive bb2b = new();
|
readonly TouchSensor touchRight;
|
||||||
// Is has a touch sensor at the front left of the roboid
|
|
||||||
TouchSensor touchLeft = new(bb2b);
|
public BB2B() : base(128) { // thingType = 128
|
||||||
// and other one on the right
|
|
||||||
TouchSensor touchRight = new(bb2b);
|
// The robot's propulsion is a differential drive
|
||||||
|
drive = new();
|
||||||
|
|
||||||
|
// Is has a touch sensor at the front left of the roboid
|
||||||
|
touchLeft = new(drive);
|
||||||
|
// and other one on the right
|
||||||
|
touchRight = new(drive);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(ulong currentTimeMs, bool recurse = true) {
|
||||||
|
|
||||||
// Do forever:
|
|
||||||
while (true) {
|
|
||||||
// The left wheel turns forward when nothing is touched on the right side
|
// The left wheel turns forward when nothing is touched on the right side
|
||||||
// and turn backward when the roboid hits something on the right
|
// and turn backward when the roboid hits something on the right
|
||||||
float leftWheelSpeed = touchRight.touchedSomething ? -600.0f : 600.0f;
|
float leftWheelSpeed = touchRight.touchedSomething ? -600.0f : 600.0f;
|
||||||
|
|
||||||
// The right wheel does the same, but instead is controlled by
|
// The right wheel does the same, but instead is controlled by
|
||||||
// touches on the left side
|
// touches on the left side
|
||||||
float rightWheelSpeed = touchLeft.touchedSomething ? -600.0f : 600.0f;
|
float rightWheelSpeed = touchLeft.touchedSomething ? -600.0f : 600.0f;
|
||||||
|
|
||||||
// When both sides are touching something, both wheels will turn backward
|
// When both sides are touching something, both wheels will turn backward
|
||||||
// and the roboid will move backwards
|
// and the roboid will move backwards
|
||||||
bb2b.SetWheelVelocity(leftWheelSpeed, rightWheelSpeed);
|
|
||||||
|
|
||||||
// Update the roboid state
|
drive.SetWheelVelocity(leftWheelSpeed, rightWheelSpeed);
|
||||||
bb2b.Update(true);
|
|
||||||
// and sleep for 100ms
|
base.Update(currentTimeMs, recurse);
|
||||||
Thread.Sleep(100);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
12
Examples/BB2B/Program.cs
Normal file
12
Examples/BB2B/Program.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
class Program {
|
||||||
|
static void Main() {
|
||||||
|
BB2B bb2b = new();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
bb2b.Update();
|
||||||
|
Thread.Sleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user