-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmotorFollow.c
More file actions
79 lines (65 loc) · 1.68 KB
/
motorFollow.c
File metadata and controls
79 lines (65 loc) · 1.68 KB
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
// Include standard libraries
#include <stdio.h>
#include <wiringPi.h>
#include <stdlib.h>
#include <math.h>
// Include project libraries
#include "motorControl.h"
#include "pidMotor.h"
#define EVER ;;
//float u = 0;
int inputPower = 0;
int dir;
int dir1;
float *speed;
PI_THREAD (motor_thread){
for(EVER){
if(inputPower<0){
dir1 = 0; //Maybe the other way? Test and see
}
else{
dir1 = 1;
}
speed = calcSpeeds(1);
float u = motorRegulator(speed[0], speed[1], 0);
printf("speed 0 = %f and speed 1 = %f \n",speed[0],speed[1]);
if(u<0){
dir = 1; //Maybe the other way? Test and see
}
else{
dir = 0;
}
accuateMotor(abs(inputPower),dir1,abs(ceil(u)),dir);
delay(10);
}
}
PI_THREAD (Input_thread){
for(EVER){
//Add encoder speed as second argument to function
//Add desired speed as third argument to function
printf("Input a value from 0-1024 \n");
scanf("%d",&inputPower);
if(inputPower == 1000){
return(0);
}
delay(1000);
}
}
int main(int argc, char *argv[] ){
if( argc != 4 ){
printf("Wrong number of arguments, you had %d \n",argc);
exit(2);
}
float Kp = (float)atof(argv[1]);
float Ki = (float)atof(argv[2]);
float Kd = (float)atof(argv[3]);
wiringPiSetupGpio(); //Setup and use defult pin numbering
initMotorPins(); //Initializes pins and hardware interupts for motors
initMotRegParam( Kp, Ki, Kd);
piThreadCreate(Input_thread);
piThreadCreate(motor_thread);
for(EVER){
delay(100);
}
return 0;
}