Control project for the Lift-arm. Works with ROS Melodic

Dependencies:   mbed Servo ros_lib_melodic ULN2003_StepperDriver Async_4pin_Stepper

Committer:
krogedal
Date:
Thu May 27 18:36:23 2021 +0000
Revision:
0:441289ea4e29
Set up basic motor control

Who changed what in which revision?

UserRevisionLine numberNew contents of line
krogedal 0:441289ea4e29 1 #ifndef KARBOT_MOTOR_H
krogedal 0:441289ea4e29 2 #define KARBOT_MOTOR_H
krogedal 0:441289ea4e29 3
krogedal 0:441289ea4e29 4 /* Karbot motor class
krogedal 0:441289ea4e29 5 * Written by Simon Krogedal
krogedal 0:441289ea4e29 6 * 27/05/21
krogedal 0:441289ea4e29 7 * Team 9 4th Year project
krogedal 0:441289ea4e29 8 *
krogedal 0:441289ea4e29 9 * for NUCLEO-F401RE
krogedal 0:441289ea4e29 10 *
krogedal 0:441289ea4e29 11 */
krogedal 0:441289ea4e29 12
krogedal 0:441289ea4e29 13 #include "mbed.h"
krogedal 0:441289ea4e29 14
krogedal 0:441289ea4e29 15 class motor {
krogedal 0:441289ea4e29 16
krogedal 0:441289ea4e29 17 private:
krogedal 0:441289ea4e29 18 PwmOut output; // PWM output pin
krogedal 0:441289ea4e29 19 DigitalOut dir; // direction pin
krogedal 0:441289ea4e29 20
krogedal 0:441289ea4e29 21 double T, dutCyc; // Period and duty cycle variables
krogedal 0:441289ea4e29 22 bool driving; // flag on wheter the motor is driving or not
krogedal 0:441289ea4e29 23
krogedal 0:441289ea4e29 24 public:
krogedal 0:441289ea4e29 25 // constructor takes 2 pins and the period
krogedal 0:441289ea4e29 26 motor(PinName pwm_pin, PinName dir_pin, double period);
krogedal 0:441289ea4e29 27
krogedal 0:441289ea4e29 28 void drive(void); // drives at set direction and duty cycle
krogedal 0:441289ea4e29 29
krogedal 0:441289ea4e29 30 void stop(void); // stops
krogedal 0:441289ea4e29 31
krogedal 0:441289ea4e29 32 void setOut(double dc); // set the output, number between -1 and 1
krogedal 0:441289ea4e29 33
krogedal 0:441289ea4e29 34 double getPeriod(void); // returns period
krogedal 0:441289ea4e29 35
krogedal 0:441289ea4e29 36 double getDuty(void); // returns dutycycle
krogedal 0:441289ea4e29 37 };
krogedal 0:441289ea4e29 38
krogedal 0:441289ea4e29 39
krogedal 0:441289ea4e29 40 #endif