Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
main.cpp
- Committer:
- Floris_Hoek
- Date:
- 2019-10-14
- Revision:
- 8:7dab565a208e
- Parent:
- 5:2ae500da8fe1
- Child:
- 9:e8cc37a94fec
File content as of revision 8:7dab565a208e:
#include "mbed.h"
#include "HIDScope.h"
#include "BiQuad.h"
#include "MODSERIAL.h"
#include "FastPWM.h"
#include "QEI.h"
#include <math.h>
#include "Motor_Control.h"
DigitalIn button1(D12);
AnalogIn pot2(A0);
Ticker measurecontrol;
DigitalOut motor1Direction(D7);
FastPWM motor1Velocity(D6);
MODSERIAL pc(USBTX, USBRX);
QEI Encoder(D8,D9,NC,8400);
float PI = 3.1415926535897932384626433832795028841971693993;
float timeinterval = 0.001;
// README
//P control implementation (behaves like a spring)
double P_controller(double error)
{
double Kp = 17.5;
//Proportional part:
double u_k = Kp * error;
//sum all parts and return it
return u_k;
}
void nothing(){// Do nothing
}
int main()
{
double frequency = 17000.0;
double period_signal = 1.0/frequency;
pc.baud(115200);
pc.printf("Starting...\r\n\r\n");
motor1Velocity.period(period_signal);
measurecontrol.attach(measureandcontrol, timeinterval);
bool aa = true;
while(aa)
{
char c = pc.getcNb();
aa = c == 'c' ? false : true;
}
pc.printf("Programm stops running\r\n");
sendtomotor(0);
measurecontrol.attach(nothing,10000);
return 0;
}