Cleanup motor
This commit is contained in:
		
							parent
							
								
									bab29a01c5
								
							
						
					
					
						commit
						1df58e9066
					
				@ -1,18 +1,18 @@
 | 
				
			|||||||
#include "Motor.h"
 | 
					#include "Motor.h"
 | 
				
			||||||
#include <time.h>
 | 
					#include <time.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <Arduino.h>
 | 
					// #include <Arduino.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Motor::Motor() {
 | 
					Motor::Motor() {
 | 
				
			||||||
  type = Type::Motor;
 | 
					  type = Type::Motor;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
float Motor::GetSpeed() {
 | 
					float Motor::GetSpeed() {
 | 
				
			||||||
  return this->currentSpeed;
 | 
					  return this->currentTargetSpeed;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Motor::SetSpeed(float speed) {
 | 
					void Motor::SetSpeed(float targetSpeed) {
 | 
				
			||||||
  this->currentSpeed = speed;
 | 
					  this->currentTargetSpeed = targetSpeed;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Motor::Drive(float distance) {
 | 
					bool Motor::Drive(float distance) {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										17
									
								
								Motor.h
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								Motor.h
									
									
									
									
									
								
							@ -10,18 +10,25 @@ class Motor : public Thing {
 | 
				
			|||||||
 public:
 | 
					 public:
 | 
				
			||||||
  Motor();
 | 
					  Motor();
 | 
				
			||||||
  /// @brief Turning direction of the motor
 | 
					  /// @brief Turning direction of the motor
 | 
				
			||||||
  enum Direction { Forward = 1, Reverse = -1 };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// @brief Set the turning direction of the motor
 | 
					  /// @brief Motor turning direction
 | 
				
			||||||
  // void SetDirection(Direction direction);
 | 
					  enum class Direction { Clockwise = 1, CounterClockwise = -1 };
 | 
				
			||||||
 | 
					  /// @brief The forward turning direction of the motor
 | 
				
			||||||
 | 
					  Direction direction = Direction::Clockwise;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /// @brief Set the target motor speed
 | 
				
			||||||
 | 
					  /// @param speed The speed between -1 (full backward), 0 (stop) and 1 (full
 | 
				
			||||||
 | 
					  /// forward)
 | 
				
			||||||
  virtual void SetSpeed(float speed);
 | 
					  virtual void SetSpeed(float speed);
 | 
				
			||||||
  float GetSpeed();
 | 
					  /// @brief Get the current target speed of the motor
 | 
				
			||||||
 | 
					  /// @return The speed between -1 (full backward), 0 (stop) and 1 (full
 | 
				
			||||||
 | 
					  /// forward)
 | 
				
			||||||
 | 
					  virtual float GetSpeed();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool Drive(float distance);
 | 
					  bool Drive(float distance);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 protected:
 | 
					 protected:
 | 
				
			||||||
  float currentSpeed = 0;
 | 
					  float currentTargetSpeed = 0;
 | 
				
			||||||
  bool driving = false;
 | 
					  bool driving = false;
 | 
				
			||||||
  float targetDistance = 0;
 | 
					  float targetDistance = 0;
 | 
				
			||||||
  time_t startTime = 0;
 | 
					  time_t startTime = 0;
 | 
				
			||||||
 | 
				
			|||||||
@ -1 +1 @@
 | 
				
			|||||||
Subproject commit 80c89a8232aa77cabaee9f739ef6fdd3e5508260
 | 
					Subproject commit 493a3f748907b4fb7e64177f94b7cb98a951af4c
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user