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.
main.cpp
- Committer:
- maxnagazumi
- Date:
- 2019-11-14
- Revision:
- 1:9732c03b0de4
- Parent:
- 0:ef259ff25554
- Child:
- 2:d213999ee436
File content as of revision 1:9732c03b0de4:
#include "mbed.h"
#include "EC.h" //Encoderライブラリをインクルード
#include "SpeedController.h" //SpeedControlライブラリをインクルード
#define RESOLUTION 500
//PwmOut f(PA_9);
//PwmOut b(PA_10);
DigitalIn s(PB_7,PullUp);
DigitalOut out1(PA_8);
Ticker ticker;
Ec4multi EC(PA_6,PA_7,RESOLUTION);
InterruptIn X(PA_4);
SpeedControl motor(PA_10,PA_9,50,EC);
void calOmega()
{
EC.calOmega();
}
int X_count=0;
void Xcount()
{
X_count++;
}
/*void shot()
{
out1 = 1;
}
*/
int main()
{
out1 =0;
motor.setPDparam(0.01,0.01);
motor.setEquation(0.005,0.01,0.023,0.0);
/*
b.setPDparam(double kp,double kd);
b.setEquation(double cf,double df,double cb,double db);
*/
//int i=0;
double a=0,r=0.4,v=0;//rで半径指定 a*r=v
X.rise(&Xcount);
ticker.attach(&calOmega,0.05);
printf("%d\n",s.read());
motor.setDutyLimit(0.6);
printf("Omega V(m/s)");
while(1) {
if(s.read()==1) {
while(1) {
a=EC.getOmega();
v=a*r;
printf("%f %f %d\r\n",a,v,X_count);
motor.Sc(10.5);
motor.setDutyLimit(0.4);
/*if(a>16.9||a<17.1) {
i++;
}*/
/*if(X_count==6) {
out1 =1;
printf("shot\n");break;
}
*/
if(s.read()==0)break;
}
}
motor.stop();
motor.reset();
if(s.read() ==0)break;
}
return 0;
}