P1

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Controller.h Source File

Controller.h

00001 /*
00002  * Controller.h
00003  * Copyright (c) 2020, ZHAW
00004  * All rights reserved.
00005  */
00006 
00007 #ifndef CONTROLLER_H_
00008 #define CONTROLLER_H_
00009 
00010 #include <cstdlib>
00011 #include <mbed.h>
00012 #include "EncoderCounter.h"
00013 #include "LowpassFilter.h"
00014 
00015 /**
00016  * This class implements a controller that regulates the
00017  * speed of the two motors of the ROME2 mobile robot.
00018  */
00019 class Controller {
00020     
00021     public:
00022         
00023                 Controller(PwmOut& pwmLeft, PwmOut& pwmRight, EncoderCounter& counterLeft, EncoderCounter& counterRight);
00024         virtual ~Controller();
00025         void    setDesiredSpeedLeft(float desiredSpeedLeft);
00026         void    setDesiredSpeedRight(float desiredSpeedRight);
00027         
00028   private:
00029         
00030         static const float  PERIOD;
00031         static const float  COUNTS_PER_TURN;
00032         static const float  LOWPASS_FILTER_FREQUENCY;
00033         static const float  KN;
00034         static const float  KP;
00035         static const float  MAX_VOLTAGE;
00036         static const float  MIN_DUTY_CYCLE;
00037         static const float  MAX_DUTY_CYCLE;
00038 
00039         PwmOut&             pwmLeft;
00040         PwmOut&             pwmRight;
00041         EncoderCounter&     counterLeft;
00042         EncoderCounter&     counterRight;
00043         short               previousValueCounterLeft;
00044         short               previousValueCounterRight;
00045         LowpassFilter       speedLeftFilter;
00046         LowpassFilter       speedRightFilter;
00047         float               desiredSpeedLeft;
00048         float               desiredSpeedRight;
00049         float               actualSpeedLeft;
00050         float               actualSpeedRight;
00051         Ticker              ticker;
00052         
00053         void    run();
00054 };
00055 
00056 #endif /* CONTROLLER_H_ */
00057