NagaokaRoboticsClub_mbedTeam / NHK2021_ikarashiSV

Dependents:   NHK2021_ikarashiSV_code NHK2021_ikarashiSV_code_withservo 2021NHK_B_syudo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ikarashiSV.cpp Source File

ikarashiSV.cpp

00001 #include "ikarashiSV.h"
00002 
00003 ikarashiSV::ikarashiSV(PinName pin_a,PinName pin_b,PinName pin_c,PinName pin_d):
00004     port_a(pin_a), port_b(pin_b), port_c(pin_c), port_d(pin_d)
00005 {
00006     state = 0;
00007     solenoid_status = 0;
00008 }
00009 
00010 void ikarashiSV::add_state()
00011 {
00012     state++;
00013 }
00014 
00015 void ikarashiSV::solenoid(int _state)
00016 {
00017     switch(_state) {
00018         case 1:
00019             //投げる
00020             port_a = 0;
00021             port_b = 1;
00022             port_c = 0;
00023             port_d = 1;
00024             solenoid_status = 1;
00025             break;
00026         case 2:
00027             //戻る
00028             port_c = 1;
00029             port_d = 0;
00030             port_a = 1;
00031             port_b = 0;
00032             solenoid_status = 2;
00033             break;
00034         case 0://禅開放
00035             port_c = 0;
00036             port_d = 1;
00037             solenoid_status = 0;
00038             break;
00039     }
00040 }
00041 
00042 void ikarashiSV::solenoid_show()
00043 {
00044     switch(solenoid_status) {
00045         case 1:
00046             printf("1:push\t");
00047             break;
00048         case 2:
00049             printf("1:pull\t");
00050             break;
00051         case 0:
00052             printf("1:open\t");
00053             break;
00054     }
00055 }
00056 
00057 int ikarashiSV::state_show()
00058 {
00059     return state;
00060 }
00061 
00062 
00063 ikarashiSV2::ikarashiSV2(PinName pin_e, PinName pin_f):
00064     port_e(pin_e),port_f(pin_f)
00065 {
00066     solenoid_status2 = 0;
00067 }
00068 
00069 void ikarashiSV2::solenoid(int _state2)
00070 {
00071     switch(_state2) {
00072         case 1://push
00073             port_e = 0;
00074             port_f = 1;
00075             solenoid_status2 = 1;
00076             break;
00077         case 0://pull
00078             port_e = 1;
00079             port_f = 0;
00080             solenoid_status2 = 0;
00081             break;
00082     }
00083 }
00084 
00085 void ikarashiSV2::solenoid_show()
00086 {
00087     if(solenoid_status2) {
00088         printf("2:push\t");
00089     } else {
00090         printf("2:pull\t");
00091     }
00092 }
00093 
00094 /* サンプルコード
00095 
00096 #include "mbed.h"
00097 #include "ikarashiSV.h"
00098 
00099 DigitalOut led1(LED1);
00100 Serial pc(USBTX, USBRX,115200);
00101 
00102 ikarashiSV slv1(PB_5,PB_4,PB_10,PA_5);
00103 ikarashiSV2 slv2(PB_9,PB_8);
00104 Servo servo(PB_14);
00105 Ticker timer;
00106 
00107 //ボタンを押したときor離したときを読み取る定義の仕方
00108 InterruptIn button(USER_BUTTON);
00109 
00110 int check = 0;
00111 
00112 void add()
00113 {
00114     if(check >= 1) {
00115         slv1.add_state();
00116     }
00117     check++;
00118 }
00119 
00120 int main()
00121 {
00122     int val;
00123     timer.attach(&add, 2);
00124     while(1) {
00125         val = slv1.state_show();
00126         pc.printf("state : %d",val);
00127         pc.printf("\tservo : %0.2f\t",servo.read());
00128         slv1.solenoid_show();
00129         slv2.solenoid_show();
00130         printf("\n\r");
00131         slv1.solenoid(val%3);
00132         slv2.solenoid(val%2);
00133     }
00134 }
00135 
00136 */