RSeries astromech firmware
TankDriveSerial.h
Go to the documentation of this file.
1 #ifndef TankDriveSerial_h
2 #define TankDriveSerial_h
3 
4 #include "ServoDispatch.h"
5 #include "drive/TankDrive.h"
6 
22 class TankDriveSerial : public TankDrive
23 {
24 public:
31  fSerial(&stream),
32  fStopped(false)
33  {
34  setMaxSpeed(1.0f);
35  }
36 
37  virtual void setup() override
38  {
39  }
40 
41  virtual void stop() override
42  {
43  if (!fStopped)
44  {
45  if (fSerial != nullptr)
46  fSerial->println("~DRIVESTOP");
47  fStopped = true;
48  }
50  }
51 
52 protected:
53  Stream* fSerial;
54  bool fStopped;
55 
56  virtual void motor(float left, float right, float throttle) override
57  {
58  if (fSerial != nullptr)
59  {
60  fSerial->print("~DRIVE");
61  printNumZeroPad(unsigned(100+left*100));
62  fSerial->print(",");
63  printNumZeroPad(unsigned(100+right*100));
64  fSerial->print(",");
65  printNumZeroPad(unsigned(100+throttle*100));
66  fSerial->println();
67  }
68  fStopped = false;
69  }
70 
71  void printNumZeroPad(unsigned num)
72  {
73  if (num < 100)
74  fSerial->print(0);
75  if (num < 10)
76  fSerial->print(0);
77  fSerial->print(num);
78  }
79 };
80 #endif
ServoDispatch.h
TankDriveSerial::fStopped
bool fStopped
Definition: TankDriveSerial.h:54
TankDriveSerial::fSerial
Stream * fSerial
Definition: TankDriveSerial.h:53
TankDriveSerial::stop
virtual void stop() override
Definition: TankDriveSerial.h:41
TankDriveSerial::motor
virtual void motor(float left, float right, float throttle) override
Definition: TankDriveSerial.h:56
TankDriveSerial
Base template of automatic forwarder from i2c to CommandEvent.
Definition: TankDriveSerial.h:22
TankDrive::driveStick
void driveStick(JoystickController *stick, float speedModifier)
Definition: TankDrive.h:346
TankDrive::setMaxSpeed
void setMaxSpeed(float modifier)
Definition: TankDrive.h:137
TankDrive
Base template of automatic forwarder from i2c to CommandEvent.
Definition: TankDrive.h:37
TankDriveSerial::TankDriveSerial
TankDriveSerial(Stream &stream, JoystickController &driveStick)
Constructor.
Definition: TankDriveSerial.h:29
JoystickController
Definition: JoystickController.h:4
TankDriveSerial::printNumZeroPad
void printNumZeroPad(unsigned num)
Definition: TankDriveSerial.h:71
TankDriveSerial::setup
virtual void setup() override
Subclasses must implement this function to perform any necessary setup that cannot happen in the cons...
Definition: TankDriveSerial.h:37
TankDrive.h
TankDrive::stop
virtual void stop()
Definition: TankDrive.h:261