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: HIDScope MODSERIAL QEI biquadFilter mbed
Fork of frdm_Motor_V2_2 by
main.cpp
- Committer:
- Rvs94
- Date:
- 2015-09-29
- Revision:
- 6:3af4a77c9935
- Parent:
- 5:455773cf460b
File content as of revision 6:3af4a77c9935:
#include "mbed.h"
#include "MODSERIAL.h"
#include "HIDScope.h"
#include "QEI.h"
Serial pc(USBTX, USBRX); // tx, rx
DigitalOut led(LED_RED);
DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield)
PwmOut motor2speed(D5);
DigitalIn button1(SW3);
DigitalIn EncoderA(D3);
DigitalIn EncoderB(D2);
QEI Encoder(D3, D2, NC, 128);
HIDScope scope(3);
Ticker ScopeTime;
double Aantal_Degs;
double Aantal_pulses;
double Error;
double refference;
void ScopeSend()//Functie die de gegevens voor de scope uitleest en doorstuurt
{
scope.set(0, motor2direction.read());
scope.set(1, motor2speed.read());
scope.set(2, Aantal_Degs);
Aantal_Degs = Encoder.getPulses()*360/128/131;
scope.send();
}
double p_control(double kp, double Error)
{
return Error*kp;
}
int main()
{
motor2direction = 0;
motor2speed = 0;
led = 1;
pc.baud(115200);
double refference = 0;
pc.printf("Tot aan loop werkt\n");
ScopeTime.attach_us(&ScopeSend, 10e4);
while (true)
{
char c = pc.getc();
if(c == 'r')
{
refference = refference + 10;
pc.printf("rx \n");
Error = refference - Aantal_Degs;
double Output = p_control(0.05,Error);
while(abs(Error) > 2)
{
Error = refference - Aantal_Degs;
motor2speed = abs(Output);
pc.printf("reffence = %d,error = %d \n",refference,Error);
if(Error > 0)
{
motor2direction = 0;
}
else
{
motor2direction = 1;
}
}
}
}
}
