void run_test() { printf("Running test for DAXPY with N = %d, incx = %d, incy = %d, alpha = %f\n", N, incx, incy, alpha); printf("%32s%32s\n","ACML","Fortran"); printf("Trials\n"); printf("%32s%32s%32s\n", "Time (ns)", "Time (ns)", "ACML == FT"); int c = 8, it = 0; unsigned long long int tot1 = 0, tot2 = 0; int ic; for (ic = 0; ic < c; ic++) { unsigned long long int t1, t2; t1 = acml_time(); t2 = f_time(); printf("%32d", array_cmp()); if (ic >= 2) { tot1 += t1; tot2 += t2; ++it; } printf("\n"); } printf("Average (Does not include first two trials)\n"); printf("%32llu%32llu\n",tot1/it,tot2/it); printf("\n"); }
void run_test() { printf("Running test for DROTM with N = %d, incx = %d, incy = %d, flag = %f\n", N, incx, incy, param[0]); printf("%32s%32s\n","ACML", "FORTRAN"); printf("Trials\n"); printf("%32s%32s%32s\n", "Time (ns)", "Time (ns)", "ACML == FT"); int c = 8, ic, it = 0; unsigned long long int tot1 = 0, tot2 = 0; for (ic = 0; ic < c; ic++) { unsigned long long int t1, t2; t1 = acml_time(); t2 = f_time(); printf("%32d", array_cmp()); if (ic >= 2) { tot1 += t1; tot2 += t2; it ++; } printf("\n"); } printf("Average (Does not include first two trials)\n"); printf("%32llu%32llu\n",tot1/it,tot2/it); printf("\n"); }
void test_quick_sort_suite1(void) { int list[] = {3,1,2,4,5,21,19,7}; int expected_list[] = {1,2,3,4,5,7,19,21}; quick_sort(list, 8); array_cmp(list, expected_list, 8); }
void test_partition_suite1(void) { int list[] = {1,22,7,4,3,2,44}; int expected_list[] = {1,3,2,4,22,7,44}; partition( list, 0, 6, 3 ); array_cmp(list, expected_list, 7); }
void test_swap_suite1(void) { int list[] = {1,2,4,7}; int expected_list[] = {1,7,4,2}; swap( list, 1, 3 ); array_cmp(list, expected_list, 4); }
void test_merge_sort_suite1(void) { int list[] = {3,1,2,4,5,21,19,7}; int merged_list[] = {1,2,3,4,5,7,19,21}; merge_sort(list, 8); array_cmp(list, merged_list, 8); }
/** * Sends the tag to the computer. */ void sendCode() { //This is where I would add a return value (the code) to "validate" or whatever at. //Serial.print("TAG:"); char full_tag[10]; for(int i=0; i<CODE_LEN; i++) { if (i == 9) //Edits by riley porter Serial.println(tag[i]); //This checks to see if its the last byte else //If it is it will print a "new line" so that the codes to jumble together Serial.print(tag[i]); } if (array_cmp(Serial.readln, "Authenticated")) { openDoor(); if (array_cmp(tag, "XXXXXXXXXX")) { Serial.println("Dbax's tag authenticated"); openDoor(); } else if (array_cmp(tag, "XXXXXXXXXX")) { Serial.println("Jacob's tag authenticated"); openDoor(); } else if (array_cmp(tag, "XXXXXXXXXX")) { Serial.println("Johns's tag authenticated"); openDoor(); } else if (array_cmp(tag, "XXXXXXXXXX")) { Serial.println("Jared's tag authenticated"); openDoor(); } else { Serial.println("Denied"); } } /**************************************************************/ /******************** RFID Functions ***********************/ /**************************************************************/ void enableRFID() { digitalWrite(RFID_ENABLE, LOW); }
void calculate_merge() { int eq; seq_function(dim_x, log_x); int Cp[dim_2x] = {1, 2, 2, 3, 4, 5, 6, 8, 8, 10, 12, 13, 14, 16, 18, 20, 21, 22, 24, 26, 28, 30, 32, 34, 55, 89, 144, 233, 377, 610, 987, 1597}; eq = array_cmp(C, Cp); assert(eq == 1); }
static int sa_search_high(int *SA, int32_t *s, int n, int32_t *p, int m) { int lo = 0, hi = n - 1, mid; while (lo <= hi) { mid = lo + (hi - lo) / 2; int cmp = array_cmp(p, m, s + SA[mid], m); if (cmp < 0) hi = mid - 1; else lo = mid + 1; } return lo; }
void test_merge_suite1(void) { int list[8] = {0}; int sorted_list[] = {1,2,3,4,5,7,19,21}; int left[] = {1,2,4,7}; int right[] = {3,5,19,21}; merge(left, 4, right, 4, list); array_cmp(list, sorted_list, 8); }
void main( ) { unsigned char status,i; unsigned int str[4]={0xD5,0x5E,0x2A,0xD9}; unsigned int temp,j; InitializeSystem( ); PcdReset(); PcdAntennaOff(); PcdAntennaOn(); while ( 1 ) { // if(RI == 1) { //如果收到. // // RI = 0; //清除标志. // // UART_buff = SBUF; //接收. // // printf("rec id %x",UART_buff); // // } status = PcdRequest(PICC_REQALL, g_ucTempbuf);//寻卡 if (status != MI_OK) { InitializeSystem( ); PcdReset(); PcdAntennaOff(); PcdAntennaOn(); continue; } status = PcdAnticoll(g_ucTempbuf);//防冲撞 if (status != MI_OK) { continue; } //D55E2AD9 // printf("开始: %d \n",array_cmp(g_ucTempbuf,str)); ////////以下为超级终端打印出的内容//////////////////////// if(array_cmp(g_ucTempbuf,str)==0){ LED_GREEN = 0; delay1(100); LED_GREEN = 1; delay1(100); LED_GREEN = 0; delay1(200); LED_GREEN = 1; printf("卡号是 :"); for(i=0;i<4;i++) { temp=g_ucTempbuf[i]; printf("%X",temp); } printf("\n"); } else{ printf("卡号错误 错误的卡号是 :"); for(i=0;i<4;i++) { temp=g_ucTempbuf[i]; printf("%X",temp); } printf("\n"); } //////////////////////////////////////////////////////// for(i=0;i<250;i++)//先输出一种频率的声音 { for(j=0;j<80;j++); Speaker=~Speaker; } PcdHalt(); } }
//---------------------------【主函数】↓----------------------------------------------------------- void main(void) { //.....................[函数体内变量声明]............................... uchar i;//清空指令存储变量时所用循环的计数变量 //向舵机发送移动命令时所用的变量(下面2个)↓ uchar motor_command[9]={0xff,0xff,0x00,0x05,0x03,0x20,0x00,0x00,0x00};// uchar CHECK;//舵机指令最后一位校验码 //上电手指复位阶段用到的变量(下面2个)↓ //保证舵机停止命令只进行一次 uchar cage_0=1; uchar cage_1=1; //正常工作模式(模式一)手指松开阶段用到的变量(下面2个)↓ //保证每次夹紧操作时舵机停止命令只进行一次 uchar approach_0; uchar approach_1; //夹紧第二阶段的while循环跳出指示 uchar hold_stage_2_continue=1; //大循环中查询两端限位和空夹所用到的变量(下面7个)↓ //while大循环从两端限位后开始,因此不允许再次发送舵机停止命令,而是等待限位结束 uchar stop_allow_cage_0=0; uchar stop_allow_cage_1=0; //不允许手指向端部移动,允许手指向中间移动,设置四个变量是因为考虑到两端限位跟空夹 uchar release_allow_motor_0=0; uchar release_allow_motor_1=0; uchar hold_allow_motor_0=1; uchar hold_allow_motor_1=1; //允许上电复位后就开始检测是否空夹 uchar stop_allow_empty=1; //调试模式手指移动速度,初始值为通过串口设定前的默认值 uchar PARA2=0x10,PARA3=0x01;//保证低速,仅允许通过串口命令更改其值! //一般模式手指移动速度,仅允从EEPROM中获取数值 uchar com_finger0_ratio_1_PARA2,com_finger0_ratio_1_PARA3;//手指0,Ratio 1 uchar com_finger0_ratio_2_PARA2,com_finger0_ratio_2_PARA3;//手指0,Ratio 2 uchar com_finger0_ratio_3_PARA2,com_finger0_ratio_3_PARA3;//手指0,Ratio 3 uchar com_finger1_ratio_1_PARA2,com_finger1_ratio_1_PARA3;//手指1,Ratio 1 uchar com_finger1_ratio_2_PARA2,com_finger1_ratio_2_PARA3;//手指1,Ratio 2 uchar com_finger1_ratio_3_PARA2,com_finger1_ratio_3_PARA3;//手指1,Ratio 3 uchar msg_eeprom_array[17];//向上位机返回EEPROM中数值 uchar msg_interrupt_array[7]={'z','z','4','4','0','0','0'};//向上位机返回夹持器与外部碰撞报警(中断)允许变量的值 //.......................[初始化配置]......................... uart0_init(19200);//串口0(与上位机通信)初始化,波特率均为19200 uart1_init(19200);//串口1(与舵机通信)初始化,波特率均为19200 timer1_init();//定时计数器1初始化 force_data_init();//应变片读取初始化 //限位的配置 //PE2=接近开关0,高阻态输入 DDRE&=(~BIT(2));//DDRE2=0 PORTE&=(~BIT(2));//PORTE2=0 //PE3=接近开关1,高阻态输入 DDRE&=(~BIT(3));//DDRE2=0 PORTE&=(~BIT(3));//PORTE2=0 //PE5=INT5=限位0,带上拉电阻输入 DDRE&=(~BIT(5));//意思是DDRE5=0,其余位不变。但注意不可按注释的方式写! PORTE|=BIT(5);//意思是PORTE5=1,其余位不变。但注意不可按注释的方式写! //PE6=INT6=限位1,带上拉电阻输入 DDRE&=(~BIT(6)); PORTE|=BIT(6); //PE7=空夹,带上拉电阻输入 DDRE&=(~BIT(7)); PORTE|=BIT(7); //................[功能:上电后手指复位].................................... SREG |= 0X80;//打开全局中断 //相关变量初始化 cage0_state=0; cage1_state=0; //命令舵机停止转动 uart1_send_string((uchar*)no0stop,9); delay(50); uart1_send_string((uchar*)no1stop,9); delay(50); //使手爪松开 uart1_send_string((uchar*)no0release,9); delay(50); uart1_send_string((uchar*)no1release,9); //等待两端限位触发 while(cage_0|cage_1) { if(cage_0) { if(!(PINE & BIT(5)))//PE5=0进入 { delay(50); if(!(PINE & BIT(5))) { uart1_send_string((uchar*)no0stop,9); //uart0_send_string("zz30"); cage_0=0; } } } if(cage_1) { if(!(PINE & BIT(6)))//PE6=0进入 { delay(50); if(!(PINE & BIT(6))) { uart1_send_string((uchar*)no1stop,9); //uart0_send_string("zz31"); cage_1=0; } } } } uart0_send_string("zz00");//向上位机报告准备就绪 UCSR0B|=(1<<RXEN0)|(1<<RXCIE0); //UART0接收使能,接收中断使能 //........................[while(1)大循环]............................................ while(1) { if(uart0_instr_flag==1) { switch(gripper_mood) { case 0: { if(array_cmp(uart0_instr,"0100")==0) { //uart0_send_string(" mood 0: enter 1-regular working mood! "); gripper_mood=1; ext_interrupt_init();//外部中断(夹持器与外部环境碰撞)初始化 //初始化后会立即出发一次INT0和INT1,所以报警允许变量需要先置0再置1 //夹持器与外部碰撞报警(中断)允许变量 ext_collision_alert_allow_int0=1;//上侧 ext_collision_alert_allow_int1=1;//下侧 ext_collision_alert_allow_int4=1;//指尖 //获取EEPROM中存储的RATIO值 command_data_read_finger_0_ratio_1(&com_finger0_ratio_1_PARA2,&com_finger0_ratio_1_PARA3); command_data_read_finger_0_ratio_2(&com_finger0_ratio_2_PARA2,&com_finger0_ratio_2_PARA3); command_data_read_finger_0_ratio_3(&com_finger0_ratio_3_PARA2,&com_finger0_ratio_3_PARA3); command_data_read_finger_1_ratio_1(&com_finger1_ratio_1_PARA2,&com_finger1_ratio_1_PARA3); command_data_read_finger_1_ratio_2(&com_finger1_ratio_2_PARA2,&com_finger1_ratio_2_PARA3); command_data_read_finger_1_ratio_3(&com_finger1_ratio_3_PARA2,&com_finger1_ratio_3_PARA3); //获取EEPROM中存储的夹紧力阈值有效值高八位 command_data_read_force_high8(&force_judge); } if(array_cmp(uart0_instr,"0200")==0) { //uart0_send_string(" mood 0: enter 2-configuration mood! "); gripper_mood=2; ext_interrupt_init();//外部中断(夹持器与外部环境碰撞)初始化 //初始化后会立即出发一次INT0和INT1,所以报警允许变量需要先置0再置1 //夹持器与外部碰撞报警(中断)允许变量 ext_collision_alert_allow_int0=1;//上侧 ext_collision_alert_allow_int1=1;//下侧 ext_collision_alert_allow_int4=1;//指尖 } break; } case 1: { if(array_cmp(uart0_instr,"1000")==0)//调试模式·读取EEPROM中存储的RATIO和力阈值 { //更新ratio变量值、力阈值和消息数组的值 //获取EEPROM中存储的RATIO值 command_data_read_finger_0_ratio_1(&com_finger0_ratio_1_PARA2,&com_finger0_ratio_1_PARA3); command_data_read_finger_0_ratio_2(&com_finger0_ratio_2_PARA2,&com_finger0_ratio_2_PARA3); command_data_read_finger_0_ratio_3(&com_finger0_ratio_3_PARA2,&com_finger0_ratio_3_PARA3); command_data_read_finger_1_ratio_1(&com_finger1_ratio_1_PARA2,&com_finger1_ratio_1_PARA3); command_data_read_finger_1_ratio_2(&com_finger1_ratio_2_PARA2,&com_finger1_ratio_2_PARA3); command_data_read_finger_1_ratio_3(&com_finger1_ratio_3_PARA2,&com_finger1_ratio_3_PARA3); msg_eeprom_array[0]='z'; msg_eeprom_array[1]='z'; msg_eeprom_array[2]='3'; msg_eeprom_array[3]='3'; msg_eeprom_array[4]=com_finger0_ratio_1_PARA2; msg_eeprom_array[5]=com_finger0_ratio_1_PARA3; msg_eeprom_array[6]=com_finger0_ratio_2_PARA2; msg_eeprom_array[7]=com_finger0_ratio_2_PARA3; msg_eeprom_array[8]=com_finger0_ratio_3_PARA2; msg_eeprom_array[9]=com_finger0_ratio_3_PARA3; msg_eeprom_array[10]=com_finger1_ratio_1_PARA2; msg_eeprom_array[11]=com_finger1_ratio_1_PARA3; msg_eeprom_array[12]=com_finger1_ratio_2_PARA2; msg_eeprom_array[13]=com_finger1_ratio_2_PARA3; msg_eeprom_array[14]=com_finger1_ratio_3_PARA2; msg_eeprom_array[15]=com_finger1_ratio_3_PARA3; //获取EEPROM中存储的夹紧力阈值有效值高八位 command_data_read_force_high8(&force_judge); msg_eeprom_array[16]=force_judge; delay(50); uart0_send_string_with_num(msg_eeprom_array,17);//上传EEPROM中存储的数值 } if(array_cmp(uart0_instr,"1100")==0)//松开 { if(release_allow_motor_0) { //构造舵机指令 motor_command[2]=0x00;//ID=0 motor_command[6]=com_finger0_ratio_3_PARA2; motor_command[7]=com_finger0_ratio_3_PARA3+0x04; CHECK=ratio_command_check(0,com_finger0_ratio_3_PARA2,com_finger0_ratio_3_PARA3+0x04); motor_command[8]=CHECK; delay(50); uart1_send_string(motor_command,9);//下发指令 } if(release_allow_motor_1) { //构造舵机指令 motor_command[2]=0x01;//ID=1 motor_command[6]=com_finger1_ratio_3_PARA2; motor_command[7]=com_finger1_ratio_3_PARA3+0x04; CHECK=ratio_command_check(1,com_finger1_ratio_3_PARA2,com_finger1_ratio_3_PARA3+0x04); motor_command[8]=CHECK; delay(50); uart1_send_string(motor_command,9);//下发指令 } } if(array_cmp(uart0_instr,"1200")==0)//夹紧 { if(hold_allow_motor_0 & hold_allow_motor_1) { //第一阶段 //构造舵机指令 motor_command[2]=0x00;//ID=0 motor_command[6]=com_finger0_ratio_1_PARA2; motor_command[7]=com_finger0_ratio_1_PARA3; CHECK=ratio_command_check(0,com_finger0_ratio_1_PARA2,com_finger0_ratio_1_PARA3); motor_command[8]=CHECK; delay(50); uart1_send_string(motor_command,9);//下发指令 //构造舵机指令 motor_command[2]=0x01;//ID=1 motor_command[6]=com_finger1_ratio_1_PARA2; motor_command[7]=com_finger1_ratio_1_PARA3; CHECK=ratio_command_check(1,com_finger1_ratio_1_PARA2,com_finger1_ratio_1_PARA3); motor_command[8]=CHECK; delay(50); uart1_send_string(motor_command,9);//下发指令 approach_0=1; approach_1=1; //等接近开关触发,同时查询检测是否空夹 while((approach_0|approach_1)&&(PINE & BIT(7))) { if(approach_0) { if(!(PINE & BIT(2)))//PE2=0进入 { delay(50); if(!(PINE & BIT(2))) { uart1_send_string((uchar*)no0stop,9); //uart0_send_string(" interrupt 5 "); approach_0=0; } } } if(approach_1) { if(!(PINE & BIT(3)))//PE3=0进入 { delay(50); if(!(PINE & BIT(3))) { uart1_send_string((uchar*)no1stop,9); //uart0_send_string(" interrupt 6 "); approach_1=0; } } } } if(PINE & BIT(7))//不空夹则进行第二阶段 { //第二阶段 //构造舵机指令 motor_command[2]=0x00;//ID=0 motor_command[6]=com_finger0_ratio_2_PARA2; motor_command[7]=com_finger0_ratio_2_PARA3; CHECK=ratio_command_check(0,com_finger0_ratio_2_PARA2,com_finger0_ratio_2_PARA3); motor_command[8]=CHECK; delay(50); uart1_send_string(motor_command,9);//下发指令 //构造舵机指令 motor_command[2]=0x01;//ID=1 motor_command[6]=com_finger1_ratio_2_PARA2; motor_command[7]=com_finger1_ratio_2_PARA3; CHECK=ratio_command_check(1,com_finger1_ratio_2_PARA2,com_finger1_ratio_2_PARA3); motor_command[8]=CHECK; delay(50); uart1_send_string(motor_command,9);//下发指令 //等待夹紧力达到阈值并继续判断是否空夹 force_high8=0; hold_stage_2_continue=1; while(hold_stage_2_continue && (PINE & BIT(7))) { force_ulong=ReadCount(); ulong_to_uchar_array(force_ulong);//目的是获取force_high8 if(force_high8>=force_judge) { hold_stage_2_continue=0;//下次循环跳出 //停止舵机运行 delay(50); uart1_send_string((uchar*)no0stop,9); delay(50); uart1_send_string((uchar*)no1stop,9); hold_allow_motor_0=0;//禁止0号手指向端部靠近 hold_allow_motor_1=0;//禁止1号手指向端部靠近 //报告上位机已经夹紧 delay(50); uart0_send_string("zz10"); delay(50); uart0_send_string("zz10"); } } } } } if(array_cmp(Type(uart0_instr),"13")==0)//设定手指0,Ratio 1 { com_finger0_ratio_1_PARA2=uart0_instr[2]; com_finger0_ratio_1_PARA3=uart0_instr[3]; command_data_save_finger_0_ratio_1(com_finger0_ratio_1_PARA2,com_finger0_ratio_1_PARA3); } if(array_cmp(Type(uart0_instr),"14")==0)//设定手指0,Ratio 2 { com_finger0_ratio_2_PARA2=uart0_instr[2]; com_finger0_ratio_2_PARA3=uart0_instr[3]; command_data_save_finger_0_ratio_2(com_finger0_ratio_2_PARA2,com_finger0_ratio_2_PARA3); } if(array_cmp(Type(uart0_instr),"15")==0)//设定手指0,Ratio 3 { com_finger0_ratio_3_PARA2=uart0_instr[2]; com_finger0_ratio_3_PARA3=uart0_instr[3]; command_data_save_finger_0_ratio_3(com_finger0_ratio_3_PARA2,com_finger0_ratio_3_PARA3); } if(array_cmp(Type(uart0_instr),"16")==0)//设定手指1,Ratio 1 { com_finger1_ratio_1_PARA2=uart0_instr[2]; com_finger1_ratio_1_PARA3=uart0_instr[3]; command_data_save_finger_1_ratio_1(com_finger1_ratio_1_PARA2,com_finger1_ratio_1_PARA3); } if(array_cmp(Type(uart0_instr),"17")==0)//设定手指1,Ratio 2 { com_finger1_ratio_2_PARA2=uart0_instr[2]; com_finger1_ratio_2_PARA3=uart0_instr[3]; command_data_save_finger_1_ratio_2(com_finger1_ratio_2_PARA2,com_finger1_ratio_2_PARA3); } if(array_cmp(Type(uart0_instr),"18")==0)//设定手指1,Ratio 3 { com_finger1_ratio_3_PARA2=uart0_instr[2]; com_finger1_ratio_3_PARA3=uart0_instr[3]; command_data_save_finger_1_ratio_3(com_finger1_ratio_3_PARA2,com_finger1_ratio_3_PARA3); } if(array_cmp(Type(uart0_instr),"19")==0)//设定force_judge { force_judge=uart0_instr[2]; command_data_save_force_high8(force_judge); } break; } case 2: { if(array_cmp(uart0_instr,"2100")==0)//调试模式·手指0停止 { TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值 uart1_send_string((uchar*)no0stop,9); } if(array_cmp(uart0_instr,"2101")==0)//调试模式·手指0松开方向移动 { if(release_allow_motor_0) { TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值 motor_command[2]=0x00;//ID=0 motor_command[6]=PARA2; motor_command[7]=PARA3+0x04;//顺时针,绝对不可在此更改PARA3的值! CHECK=ratio_command_check(0,PARA2,PARA3+0x04); motor_command[8]=CHECK; delay(50); uart1_send_string(motor_command,9); //delay(50); //uart0_send_string_with_num(motor_command,9); TIMSK|=BIT(2);//打开定时计数1中断,向上返回夹持力值 } } if(array_cmp(uart0_instr,"2102")==0)//调试模式·手指0夹紧方向移动 { if(hold_allow_motor_0) { TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值 motor_command[2]=0x00;//ID=0 motor_command[6]=PARA2; motor_command[7]=PARA3; CHECK=ratio_command_check(0,PARA2,PARA3); motor_command[8]=CHECK; delay(50); uart1_send_string(motor_command,9); //delay(50); //uart0_send_string_with_num(motor_command,9); TIMSK|=BIT(2);//打开定时计数1中断,向上返回夹持力值 } } if(array_cmp(uart0_instr,"2110")==0)//调试模式·手指1停止 { TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值 uart1_send_string((uchar*)no1stop,9); } if(array_cmp(uart0_instr,"2111")==0)//调试模式·手指1松开方向移动 { if(release_allow_motor_1) { TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值 motor_command[2]=0x01;//ID=1 motor_command[6]=PARA2; motor_command[7]=PARA3+0x04;//顺时针,绝对不可在此更改PARA3的值! CHECK=ratio_command_check(1,PARA2,PARA3+0x04); motor_command[8]=CHECK; delay(50); uart1_send_string(motor_command,9); //delay(50); //uart0_send_string_with_num(motor_command,9); TIMSK|=BIT(2);//打开定时计数1中断,向上返回夹持力值 } } if(array_cmp(uart0_instr,"2112")==0)//调试模式·手指1夹紧方向移动 { if(hold_allow_motor_1) { TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值 motor_command[2]=0x01;//ID=1 motor_command[6]=PARA2; motor_command[7]=PARA3; CHECK=ratio_command_check(1,PARA2,PARA3); motor_command[8]=CHECK; delay(50); uart1_send_string(motor_command,9); //delay(50); //uart0_send_string_with_num(motor_command,9); TIMSK|=BIT(2);//打开定时计数1中断,向上返回夹持力值 } } if(array_cmp(Type(uart0_instr),"22")==0) { TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值 delay(50); uart1_send_string((uchar*)no0stop,9); delay(50); uart1_send_string((uchar*)no1stop,9); PARA2=uart0_instr[2]; PARA3=uart0_instr[3]; //delay(50); //uart0_send_string("ratio changed"); } if(array_cmp(uart0_instr,"2301")==0)//调试模式·设置手指0速度1(两指相同)夹紧第一阶段 { command_data_save_finger_0_ratio_1(PARA2,PARA3); //delay(50); //uart0_send_string(" Finger-0 Ratio-1 Set Successfully! "); } if(array_cmp(uart0_instr,"2302")==0)//调试模式·设置手指0速度2(两指相同)夹紧第二阶段 { command_data_save_finger_0_ratio_2(PARA2,PARA3); //delay(50); //uart0_send_string(" Finger-0 Ratio-2 Set Successfully! "); } if(array_cmp(uart0_instr,"2303")==0)//调试模式·设置手指0速度3(两指相同)松开阶段 { command_data_save_finger_0_ratio_3(PARA2,PARA3); //delay(50); //uart0_send_string(" Finger-0 Ratio-3 Set Successfully! "); } if(array_cmp(uart0_instr,"2311")==0)//调试模式·设置手指1速度1(两指相同)夹紧第一阶段 { command_data_save_finger_1_ratio_1(PARA2,PARA3); //delay(50); //uart0_send_string(" Finger-1 Ratio-1 Set Successfully! "); } if(array_cmp(uart0_instr,"2312")==0)//调试模式·设置手指1速度2(两指相同)夹紧第二阶段 { command_data_save_finger_1_ratio_2(PARA2,PARA3); //delay(50); //uart0_send_string(" Finger-1 Ratio-2 Set Successfully! "); } if(array_cmp(uart0_instr,"2313")==0)//调试模式·设置手指1速度3(两指相同)松开阶段 { command_data_save_finger_1_ratio_3(PARA2,PARA3); //delay(50); //uart0_send_string(" Finger-1 Ratio-3 Set Successfully! "); } if(array_cmp(Type(uart0_instr),"24")==0)//调试模式·设置夹紧力阈值 { force_judge=uart0_instr[2]; command_data_save_force_high8(force_judge); //delay(50); //uart0_send_string(" Force Set Successfully! "); } if(array_cmp(uart0_instr,"2500")==0)//调试模式·读取EEPROM中存储的RATIO和力阈值 { //更新ratio变量值、力阈值和消息数组的值 //获取EEPROM中存储的RATIO值 command_data_read_finger_0_ratio_1(&com_finger0_ratio_1_PARA2,&com_finger0_ratio_1_PARA3); command_data_read_finger_0_ratio_2(&com_finger0_ratio_2_PARA2,&com_finger0_ratio_2_PARA3); command_data_read_finger_0_ratio_3(&com_finger0_ratio_3_PARA2,&com_finger0_ratio_3_PARA3); command_data_read_finger_1_ratio_1(&com_finger1_ratio_1_PARA2,&com_finger1_ratio_1_PARA3); command_data_read_finger_1_ratio_2(&com_finger1_ratio_2_PARA2,&com_finger1_ratio_2_PARA3); command_data_read_finger_1_ratio_3(&com_finger1_ratio_3_PARA2,&com_finger1_ratio_3_PARA3); msg_eeprom_array[0]='z'; msg_eeprom_array[1]='z'; msg_eeprom_array[2]='3'; msg_eeprom_array[3]='3'; msg_eeprom_array[4]=com_finger0_ratio_1_PARA2; msg_eeprom_array[5]=com_finger0_ratio_1_PARA3; msg_eeprom_array[6]=com_finger0_ratio_2_PARA2; msg_eeprom_array[7]=com_finger0_ratio_2_PARA3; msg_eeprom_array[8]=com_finger0_ratio_3_PARA2; msg_eeprom_array[9]=com_finger0_ratio_3_PARA3; msg_eeprom_array[10]=com_finger1_ratio_1_PARA2; msg_eeprom_array[11]=com_finger1_ratio_1_PARA3; msg_eeprom_array[12]=com_finger1_ratio_2_PARA2; msg_eeprom_array[13]=com_finger1_ratio_2_PARA3; msg_eeprom_array[14]=com_finger1_ratio_3_PARA2; msg_eeprom_array[15]=com_finger1_ratio_3_PARA3; //获取EEPROM中存储的夹紧力阈值有效值高八位 command_data_read_force_high8(&force_judge); msg_eeprom_array[16]=force_judge; delay(50); uart0_send_string_with_num(msg_eeprom_array,17);//上传EEPROM中存储的数值 } break; } default:break; } if(array_cmp(uart0_instr,"3100")==0)//恢复触碰报警 ext interrupt 0 { ext_collision_alert_allow_int0=1;//上侧 } if(array_cmp(uart0_instr,"3200")==0)//恢复触碰报警 ext interrupt 1 { ext_collision_alert_allow_int1=1;//下侧 } if(array_cmp(uart0_instr,"3300")==0)//恢复触碰报警 ext interrupt 4 { ext_collision_alert_allow_int4=1;//指尖 } if(array_cmp(uart0_instr,"3400")==0)//读取报警允许变量的状态 { msg_interrupt_array[4]=ext_collision_alert_allow_int0; msg_interrupt_array[5]=ext_collision_alert_allow_int1; msg_interrupt_array[6]=ext_collision_alert_allow_int4; uart0_send_string_with_num(msg_interrupt_array,7); } /*末尾应完成命令执行后的还原工作A-D*/ uart0_instr_flag=0; //A.命令接收标志位置0 uart0_r_instr_chk=0;//B.命令构造字符数计数置0 for(i=0;i<12;i++)//C.命令清除 { uart0_instr[i]=0; } UCSR0B|=BIT(RXCIE0);//D.恢复UART0的接收中断 } /* 【偏向撞击保护的编程】 (1)一旦手指碰撞到限位开关产生低电平,哪怕是抖动、不稳定的低电平, 也要禁止手指继续向碰撞位置移动,此时不需要延迟防抖的处理; (2)只有当手指真正完全地离开了碰撞地点,限位开关IO成为稳定的高电平, 才允许手指再次向碰撞的方向移动。 */ if(!(PINE & BIT(5)))//检测手指0是否复位 { if(stop_allow_cage_0) { release_allow_motor_0=0;//禁止1号手指向端部靠近 hold_allow_motor_0=1;//允许1号手指向中间靠近 TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值 delay(50); uart1_send_string((uchar*)no0stop,9); delay(50); uart0_send_string("zz30"); delay(50); uart0_send_string("zz30"); stop_allow_cage_0=0; } } else { if(!stop_allow_cage_0) { delay(500); if(PINE & BIT(5)) { release_allow_motor_0=1;//允许1号手指向端部靠近 stop_allow_cage_0=1; } } } if(!(PINE & BIT(6)))//检测手指1是否复位 { if(stop_allow_cage_1) { release_allow_motor_1=0;//禁止1号手指向端部靠近 hold_allow_motor_1=1;//允许1号手指向中间靠近 TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值 delay(50); uart1_send_string((uchar*)no1stop,9); delay(50); uart0_send_string("zz31"); delay(50); uart0_send_string("zz31"); stop_allow_cage_1=0; } } else { if(!stop_allow_cage_1) { delay(500); if(PINE & BIT(6)) { release_allow_motor_1=1;//允许1号手指向端部靠近 stop_allow_cage_1=1; } } } if(!(PINE & BIT(7)))//检测是否空夹 { if(stop_allow_empty) { hold_allow_motor_0=0;//禁止0号手指向端部靠近 hold_allow_motor_1=0;//禁止1号手指向端部靠近 TIMSK&=(~BIT(2));//屏蔽定时计数1中断,停止向上返回夹持力值 delay(50); uart1_send_string((uchar*)no1stop,9); delay(50); uart1_send_string((uchar*)no0stop,9); delay(50); uart0_send_string("zz32"); delay(50); uart0_send_string("zz32"); stop_allow_empty=0; } } else { if(!stop_allow_empty) { delay(500); if(PINE & BIT(7)) { hold_allow_motor_0=1;//允许0号手指向中间靠近 hold_allow_motor_1=1;//允许1号手指向中间靠近 stop_allow_empty=1; } } } } }