39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
|
|
namespace RoboidControl {
|
|
|
|
public 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
|
|
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) {
|
|
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
} |