ROVER - RoverDriving API added Signed-off-by: Mustafa Ozcelikors <mozcelikors@gmail.com>
diff --git a/rover/include/roverapi/rover_driving.hpp b/rover/include/roverapi/rover_driving.hpp new file mode 100644 index 0000000..4c7a8b7 --- /dev/null +++ b/rover/include/roverapi/rover_driving.hpp
@@ -0,0 +1,118 @@ +/* + * Copyright (c) 2017 FH Dortmund and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Description: + * Rover Driving API - Interfaces for Rover driving application development - Header file + * + * Contributors: + * M.Ozcelikors <mozcelikors@gmail.com>, created API 17.11.2017 + * + */ + +#ifndef API_ROVER_DRIVING_HPP_ +#define API_ROVER_DRIVING_HPP_ + +namespace rover +{ + /** + * @brief Contains the member functions to drive the rover using its motors. + */ + class RoverDriving + { + private: + /** + * @brief Speed for the rover movement. 360 -> Lowest speed (RoverDriving::LOWEST_SPEED), 480 -> Highest speed (RoverDriving::HIGHEST_SPEED). + */ + int SPEED; + + public: + /* Rover driving speeds */ + /** + * @brief Static definition to hold lowest driving speed for rover. + */ + static const int LOWEST_SPEED = 360; + + /** + * @brief Static definition to hold highest driving speed for rover. + */ + static const int HIGHEST_SPEED = 480; + + /** + * @brief Static definition to hold stopping speed for rover. + */ + static const int STOPPING_SPEED = 0; + + /** + * @brief Constructor for RoverDriving class. + */ + RoverDriving(); + + /** + * @brief Initializes wiringPi library and Analog to Digital Converter to start driving the rover. + */ + void initialize(); + + /** + * @brief Commands the rover to stop. + */ + void stopRover(); + + /** + * @brief Sets the speed. 360 -> Lowest speed (RoverDriving::LOWEST_SPEED), 480 -> Highest speed (RoverDriving::HIGHEST_SPEED) + */ + void setSpeed (int speed_setpoint); + + /** + * @brief Retrieves the current speed setpoint. + */ + int getSpeed (void); + + /** + * @brief Commands the rover to go forward. + */ + void goForward (); + + /** + * @brief Commands the rover to go backward. + */ + void goBackward (); + + /** + * @brief Commands the rover to turn right on its spot. + */ + void turnRight (); + + /** + * @brief Commands the rover to turn left on its spot. + */ + void turnLeft (); + + /** + * @brief Commands the rover to turn forward-left using only one motor. + */ + void turnForwardLeft (); + + /** + * @brief Commands the rover to turn forward-right using only one motor. + */ + void turnForwardRight (); + + /** + * @brief Commands the rover to turn backward-left using only one motor. + */ + void turnBackwardLeft (); + + /** + * @brief Commands the rover to turn backward-right using only one motor. + */ + void turnBackwardRight (); + + }; +} + + +#endif /* API_ROVER_DRIVING_HPP_ */
diff --git a/rover/src/roverapi/rover_driving.cpp b/rover/src/roverapi/rover_driving.cpp new file mode 100644 index 0000000..943ab3a --- /dev/null +++ b/rover/src/roverapi/rover_driving.cpp
@@ -0,0 +1,100 @@ +/* + * Copyright (c) 2017 FH Dortmund and others + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Description: + * Rover Driving API - Interfaces for Rover driving application development + * + * Contributors: + * M.Ozcelikors <mozcelikors@gmail.com>, created API 17.11.2017 + * + */ + +#include <roverapi/rover_driving.hpp> +#include <roverapi/basic_psys_rover.h> + +#include <wiringPi.h> +#include <softPwm.h> +#include <wiringPiI2C.h> +#include <stdio.h> +#include <unistd.h> + +rover::RoverDriving::RoverDriving() +{ + this->SPEED = this->HIGHEST_SPEED; +} +void rover::RoverDriving::setSpeed (int speed_setpoint) +{ + this->SPEED = speed_setpoint; +} + +int rover::RoverDriving::getSpeed (void) +{ + return this->SPEED; +} + +void rover::RoverDriving::initialize (void) +{ + //wiringPiSetup(); + /* Initialize RoverDriving once */ + pinMode (ENABLE_MOTOR_LEFT, OUTPUT) ; + digitalWrite (ENABLE_MOTOR_LEFT, HIGH) ; + pinMode (ENABLE_MOTOR_RIGHT, OUTPUT) ; + digitalWrite (ENABLE_MOTOR_RIGHT, HIGH) ; + pinMode (DIRECTION_PIN_LEFT, OUTPUT) ; + pinMode (DIRECTION_PIN_RIGHT, OUTPUT) ; + + + softPwmCreate (SOFT_PWM_ENGINE_LEFT, 0, this->HIGHEST_SPEED) ; + softPwmCreate (SOFT_PWM_ENGINE_RIGHT, 0, this->HIGHEST_SPEED) ; + + pinMode (FLASH_LIGHT_LED, OUTPUT) ; +} + +void rover::RoverDriving::turnForwardRight (void) +{ + turn(FORWARD, LEFT, this->SPEED); +} + +void rover::RoverDriving::turnForwardLeft (void) +{ + turn(FORWARD, RIGHT, this->SPEED); +} + +void rover::RoverDriving::turnBackwardRight (void) +{ + turn(BACKWARD, LEFT, this->SPEED); +} + +void rover::RoverDriving::turnBackwardLeft (void) +{ + turn(BACKWARD, RIGHT, this->SPEED); +} + +void rover::RoverDriving::turnLeft (void) +{ + turnOnSpot(FORWARD, LEFT, this->SPEED); +} + +void rover::RoverDriving::turnRight (void) +{ + turnOnSpot(FORWARD, RIGHT, this->SPEED); +} + +void rover::RoverDriving::goForward (void) +{ + go(FORWARD, this->SPEED); +} + +void rover::RoverDriving::goBackward (void) +{ + go(BACKWARD, this->SPEED); +} + +void rover::RoverDriving::stopRover (void) +{ + stop(); +}