Simon Krogedal / Karbot_wheel_control

Dependencies:   mbed ros_lib_melodic

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers motor.h Source File

motor.h

00001 #ifndef KARBOT_MOTOR_H
00002 #define KARBOT_MOTOR_H
00003 
00004 /* Karbot motor class
00005  * Written by Simon Krogedal
00006  * 27/05/21
00007  * Team 9 4th Year project
00008  * 
00009  * for NUCLEO-F401RE
00010  * 
00011  */
00012  
00013  #include "mbed.h"
00014  
00015  class motor {
00016     
00017     private:
00018         PwmOut          output;     // PWM output pin
00019         DigitalOut      dir;        // direction pin
00020         
00021         double          T, dutCyc;  // Period and duty cycle variables
00022         bool            driving;    // flag on wheter the motor is driving or not
00023         
00024     public:
00025         // constructor takes 2 pins and the period
00026         motor(PinName pwm_pin, PinName dir_pin, double period);
00027         
00028         void drive(void);           // drives at set direction and duty cycle
00029         
00030         void stop(void);            // stops
00031         
00032         void setOut(double dc);     // set the output, number between -1 and 1
00033         
00034         double getPeriod(void);     // returns period
00035         
00036         double getDuty(void);       // returns dutycycle
00037 };
00038  
00039  
00040  #endif