SmartVehicle-Basis
SmartFactory
Drive.h
Go to the documentation of this file.
1 
17 #ifndef DRIVE_H
18 #define DRIVE_H
19 
20 #include <Adafruit_MotorShield.h> //https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library
21 #include <Arduino.h>
22 
23 #include "LogConfiguration.h"
24 
25 /* https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/library-reference
26 
27 void run(uint8_t)
28 FORWARD - Rotate in a forward direction
29 BACKWARD - Rotate in the reverse direction
30 RELEASE - Stop rotation
31 Also note that "RELEASE" simply cuts power to the motor. It does not apply any braking.
32 
33 void setSpeed(uint8_t);
34 The setSpeed() function controls the power level delivered to the motor.
35 The speed parameter is a value between 0 and 255.
36 */
37 
42 class Drive {
43  //=====PUBLIC====================================================================================
44  public:
49  enum class Direction {
50  Left,
51  Right,
52  Forward,
53  Backward
54  };
55 
62  Drive(const int MotorPortRight, const int MotorPortLeft);
69  void drive(Direction direction, unsigned int speed);
70 
78  void turn(Direction direction, unsigned int speed);
79 
87  void turnonpoint(Direction direction, unsigned int speed);
88 
92  void stop();
93 
94  //=====PRIVATE===================================================================================
95  private:
96  Adafruit_MotorShield pAFMS = Adafruit_MotorShield(); // Create the motor shield object with the default I2C address
97  Adafruit_DCMotor *pMotorRight;
98  Adafruit_DCMotor *pMotorLeft;
99  int pSpeedLeft;
104  //============================================================================
105  //==Aux-Function==============================================================
112  String decodeDirection(Direction direction);
113 };
114 #endif
Direction pWayVehicle
Actual movingdirection Forward or Backward.
Definition: Drive.h:103
Direction
Direction enum holds all possible directions.
Definition: Drive.h:49
String decodeDirection(Direction direction)
Decodes the Direction-Enum and returns a description.
Definition: Drive.cpp:124
int pSpeedRight
actual Speed of right Motor
Definition: Drive.h:100
void drive(Direction direction, unsigned int speed)
Drive straight Forwards or Backwards.
Definition: Drive.cpp:29
Adafruit_DCMotor * pMotorRight
Pointer to right Motor Obj.
Definition: Drive.h:97
Class Drive handels the Driving-System and provides basic functions.
Definition: Drive.h:42
int pTurnSpeedRight
Definition: Drive.h:102
Drive(const int MotorPortRight, const int MotorPortLeft)
Construct a new Drive object https://www.adafruit.com/product/2927.
Definition: Drive.cpp:21
void stop()
Power of the Motor. Does not apply breaking.
Definition: Drive.cpp:110
void turn(Direction direction, unsigned int speed)
Turn left or right. Speed will add to one Motor's actual speed and substract from the others depenig ...
Definition: Drive.cpp:53
int pTurnSpeedLeft
Definition: Drive.h:101
int pSpeedLeft
actual Speed of left Motor
Definition: Drive.h:99
Adafruit_MotorShield pAFMS
Definition: Drive.h:96
void turnonpoint(Direction direction, unsigned int speed)
Turn on Point Drive on Motor Forward and the other Backward with the given speed.
Definition: Drive.cpp:87
Adafruit_DCMotor * pMotorLeft
Pointer to left Motor Obj.
Definition: Drive.h:98