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.
Dependencies: mbed
Fork of Robotics_Lab_Servo by
Diff: main.cpp
- Revision:
- 7:db4ddfc0cf4e
- Parent:
- 6:52f6c4d57d74
--- a/main.cpp Thu Mar 10 07:26:03 2016 +0000
+++ b/main.cpp Thu Mar 10 11:03:39 2016 +0000
@@ -12,10 +12,6 @@
AnalogIn adc(A2);//Temporary usage
-//LED1 = D13 = PA_5 (LED on Nucleo board)
-DigitalOut led1(LED1);
-DigitalOut led2(D12);
-
// timer variables
Ticker timer1;
int timer1_counter;
@@ -42,13 +38,7 @@
init_TIMER();
while(1)
{
- if(timer1_counter == 100)
- {
- timer1_counter = 0;
- angle_ref += 15;
- if (angle_ref == 45)
- break;
- }
+ ;
}
}
@@ -56,15 +46,23 @@
{
timer1_counter ++;
+ if(timer1_counter == 100)
+ {
+ timer1_counter = 0;
+ angle_ref += 15.0f;
+ if (angle_ref == 45.0f)
+ break;
+ }
+
angle_read = (adc.read() - 0.45f) / 0.48f * 180.0f; //0.21 ~ 0.69 respect to -90 ~ +90 degree
angle_check = angle_read;
//////code for PI control//////
err = angle_ref - angle_read;
ierr += err;
- PI_out = Kp * err + Ki * 0.01f*(ierr - err);
+ PI_out = Kp * err + Ki * 0.01f * (ierr - err);
- ////////////
+ // staturation
if(PI_out >= 0.5f)PI_out = 0.5;
else if(PI_out <= -0.5f)PI_out = -0.5;
pwm1_duty = PI_out + 0.5f;
@@ -82,7 +80,7 @@
void init_IO(void)
{
- angle_ref = -45;
+ angle_ref = -45.0f;
}
void init_PWM(void)
@@ -90,9 +88,4 @@
pwm1.period_us(50);
pwm1.write(0.5);
TIM1->CCER |= 0x4;
-}
-
-void flash(void)
-{
- led1 = !led1;
}
\ No newline at end of file
