41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
|
|
namespace RoboidControl {
|
|
|
|
// The robot is based on a differential drive
|
|
public class BB2B : DifferentialDrive {
|
|
readonly DifferentialDrive drive;
|
|
readonly TouchSensor touchLeft;
|
|
readonly TouchSensor touchRight;
|
|
|
|
public BB2B(Participant owner) : base(owner) {
|
|
this.name = "BB2B";
|
|
this.wheelRadius = 0.032f;
|
|
this.wheelSeparation = 0.128f;
|
|
|
|
// Is has a touch sensor at the front left of the roboid
|
|
touchLeft = new(this);
|
|
// and other one on the right
|
|
touchRight = new(this);
|
|
}
|
|
|
|
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
|
|
|
|
this.SetWheelVelocity(leftWheelSpeed, rightWheelSpeed);
|
|
|
|
base.Update(currentTimeMs, recurse);
|
|
}
|
|
}
|
|
|
|
}
|