-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservo_control.c
89 lines (72 loc) · 1.32 KB
/
servo_control.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "stm32f05xxx.h"
#include <stdio.h>
#include <stdlib.h>
#define ON 1
#define OFF 0
// servo control variables
volatile int topServo;
volatile int bottomServo;
volatile int ISR_frc=0;
volatile int ISR_pw_top=0, ISR_pw_bottom=0;
// servo control
int egets(char *s, int Max);
void magnet(int);
void servoPulseTop(int);
void servoPulseBottom(int);
void delay_ms(int);
void delay_ms (int msecs)
{
int ticks;
ISR_frc=0;
ticks=msecs/20;
while(ISR_frc<ticks);
}
void magnet(int boolean){
if(boolean==1){
GPIOB_ODR |= BIT4;
}
if(boolean==0){
GPIOB_ODR &= ~(BIT4);
}
}
void servoPulseTop (int pw1){
ISR_pw_top = pw1;
}
void servoPulseBottom (int pw2){
ISR_pw_bottom = pw2;
}
void pickup(int topServo, int bottomServo) {
int i = 0;
bottomServo = ON;
servoPulseBottom(200);
delay_ms(800);
bottomServo = OFF;
topServo = ON;
servoPulseTop(240);
delay_ms(800);
topServo = OFF;
magnet(ON);
for(i=200; i>120; i-=2){
bottomServo = ON;
servoPulseBottom(i);
delay_ms(20);
bottomServo = OFF;
}
topServo = ON;
servoPulseTop(130);
delay_ms(800);
topServo = OFF;
bottomServo = ON;
servoPulseBottom(100);
delay_ms(400);
bottomServo = OFF;
magnet(OFF);
topServo = ON;
servoPulseTop(60);
delay_ms(400);
topServo = OFF;
bottomServo = ON;
servoPulseBottom(60);
delay_ms(400);
bottomServo = OFF;
}