f3rc 3班のエンコーダのプログラムです。

Dependencies:   EC2 Math mbed

main.cpp

Committer:
nobu0103
Date:
2018-09-03
Revision:
2:a682612dd8b7
Parent:
1:0ff59878537a
Child:
3:f3ef2e7a9407

File content as of revision 2:a682612dd8b7:

#include "mbed.h"
#include "Math.h"
#include "EC.h"
#include "SpeedController.h"
DigitalIn cylinder(p9,PullUp);
DigitalIn cylindert(p10,PullUp);
DigitalIn encoder1a(p11);
DigitalIn encoder1b(p12);
DigitalIn encoder2a(p13);
DigitalIn encoder2b(p14);
AnalogIn LBR1(p17,PullUp);
AnalogIn LBR2(p18,PullUp);
AnalogIn LBR3(p19,PullUp);
AnalogIn LBR4(p20,PullUp);
PwmOut servo12(p21);
PwmOut servo3(p22);
PwmOut motor1(p25);
PwmOut motor2(p26);
DigitalIn motor1cw(p27,PullUp);
DigitalIn motor2cw(p28,PullUp);

EC wheel_1 (p11,p12,/*z相*/,/*分解能*/,0.05)
EC wheel_2 (p13,p14,/*z相*/,/*分解能*/,0.05)

/*直進用*/
void straight(int l)  //l=移動距離(mm)
{
    mortor1.period_us(50);
    mortor2.period_us(50);
    wheel_1.setDiameter_mm(/*測定輪半径(mm)*/);
    wheel_2.setDiameter_mm(/*測定輪半径(mm)*/);
    double EC1_distance = wheel_1.getDistance_mm (); //ec1の移動距離(mm)
    double EC2_distance = wheel_2.getDistance_mm (); //ec2の移動距離(mm)
    
    while(EC1_distance <= l && EC2_distance <= l) {
        motor1 = ;
        motor2 = ;
        motor1cw = ;
        motor2cw = ;
    }
}

/*後退用*/
void straight(int l)  //l=移動距離(mm)
{
    mortor1.period_us(50);
    mortor2.period_us(50);
    wheel_1.setDiameter_mm(/*測定輪半径(mm)*/);
    wheel_2.setDiameter_mm(/*測定輪半径(mm)*/);
    double EC1_distance = wheel_1.getDistance_mm (); //ec1の移動距離(mm)
    double EC2_distance = wheel_2.getDistance_mm (); //ec2の移動距離(mm)
    
    while(EC1_distance <= l && EC2_distance <= l) {
        motor1 = ;
        motor2 = ;
        motor1cw = ;
        motor2cw = ;
    }
}

/*右回転*/
void straight(int l)  //l=ecの移動距離(mm)
{
    mortor1.period_us(50);
    mortor2.period_us(50);
    wheel_1.setDiameter_mm(/*測定輪半径(mm)*/);
    wheel_2.setDiameter_mm(/*測定輪半径(mm)*/);
    double EC1_distance = wheel_1.getDistance_mm (); //ec1の移動距離(mm)
    double EC2_distance = wheel_2.getDistance_mm (); //ec2の移動距離(mm)
    
    while(EC1_distance <= l && EC2_distance <= -1*l) {
        motor1 = ;
        motor2 = ;
        motor1cw = ;
        motor2cw = ;
    }
}

/*左回転*/
void straight(int l)  //l=ecの移動距離(mm)
{
    mortor1.period_us(50);
    mortor2.period_us(50);
    wheel_1.setDiameter_mm(/*測定輪半径(mm)*/);
    wheel_2.setDiameter_mm(/*測定輪半径(mm)*/);
    double EC1_distance = wheel_1.getDistance_mm (); //ec1の移動距離(mm)
    double EC2_distance = wheel_2.getDistance_mm (); //ec2の移動距離(mm)
    
    while(EC1_distance <= -1*l && EC2_distance <= l) {
        motor1 = ;
        motor2 = ;
        motor1cw = ;
        motor2cw = ;
    }
}