int comsumerth(void){ int i=0; char result; int angle=10; int initialp=90; int m=90; float SM_1_duty ; /* Servomotor 1 , connect to ePWM0A */ //dequeue the data from buffer for 3000 times. SM_1_duty = 100.0 - ((SRV_0/PER) + (initialp/180.0) * ((SRV_180-SRV_0)/PER))*100.0; printf("Angle : %d , duty : %f\n" ,initialp ,SM_1_duty); BBBIO_PWMSS_Setting(BBBIO_PWMSS0 , FRQ, SM_1_duty , SM_1_duty); /* Set up PWM */ BBBIO_ehrPWM_Enable(BBBIO_PWMSS0); /* Enable PWM, generate waveform */ sleep(2); /* Allow time for servo to settle and for humans to see something. */ //BBBIO_ehrPWM_Disable(BBBIO_PWMSS0); for (i=0;i<20;i++) { result=dequeue(); printf("instruction dequeue: %c\n",result); if (result=='L') { m=m-angle; /* Calculate duty cycle */ /* Note: the 100-X duty cyle is to account for the level shifter that inverts */ SM_1_duty = 100.0 - ((SRV_0/PER) + (m/180.0) * ((SRV_180-SRV_0)/PER))*100.0; printf("Angle : %d , duty : %f\n" ,m ,SM_1_duty); BBBIO_PWMSS_Setting(BBBIO_PWMSS0 , FRQ, SM_1_duty , SM_1_duty); /* Set up PWM */ BBBIO_ehrPWM_Enable(BBBIO_PWMSS0); /* Enable PWM, generate waveform */ sleep(2); /* Allow time for servo to settle and for humans to see something. */ //BBBIO_ehrPWM_Disable(BBBIO_PWMSS0); } else if (result=='R') { m=m+angle; /* Calculate duty cycle */ /* Note: the 100-X duty cyle is to account for the level shifter that inverts */ SM_1_duty = 100.0 - ((SRV_0/PER) + (m/180.0) * ((SRV_180-SRV_0)/PER))*100.0; printf("Angle : %d , duty : %f\n" ,m ,SM_1_duty); BBBIO_PWMSS_Setting(BBBIO_PWMSS0 , FRQ, SM_1_duty , SM_1_duty); /* Set up PWM */ BBBIO_ehrPWM_Enable(BBBIO_PWMSS0); /* Enable PWM, generate waveform */ sleep(2); /* Allow time for servo to settle and for humans to see something. */ //BBBIO_ehrPWM_Disable(BBBIO_PWMSS0); } } return 0; }
/* * Class: io_silverspoon_bulldog_beagleboneblack_jni_NativePwm * Method: enable * Signature: (I)V */ JNIEXPORT void JNICALL Java_io_silverspoon_bulldog_beagleboneblack_jni_NativePwm_enable (JNIEnv * env, jclass clazz, jint pwmId) { BBBIO_ehrPWM_Enable(pwmId); }