PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
speed.c
1 //#define _monitor_
2 
3 #include "abdrive.h"
4 
5 volatile int abd_speedd[2];
6 volatile int abd_speedi[2];
7 volatile int abd_speedT[2];
8 volatile int abd_speed[2];
9 volatile int abd_speedLimit[4];
10 
11 volatile int abd_rampStep[3];
12 volatile int abd_stopCtr[2];
13 volatile unsigned int _servoPulseReps;
14 volatile int speedPrev[2];
15 volatile int abd_cog;
16 
17 
18 volatile int abd_dvFlag[2];
19 
20 #ifdef _monitor_
21  volatile char abd_str[128];
22 #endif
23 
24 //volatile unsigned int abd_stack[44 + 128];
25 //volatile unsigned int abd_stack[44 + 128];
26 unsigned int abd_stack[44 + 128];
27 
28 volatile int abd_ditherA[2];
29 volatile int abd_ditherAa[2];
30 volatile int abd_ditherAd[2];
31 volatile int abd_ditherAp[2];
32 
33 volatile int abd_ditherV[2];
34 volatile int abd_ditherVa[2];
35 volatile int abd_ditherVd[2];
36 volatile int abd_ditherVp[2];
37 
38 volatile int abd_gotoFlag[2];
39 volatile int abd_intTabSetup;
40 
41 
42 void abd_encoders(void *par);
43 void interpolation_table_setup(void);
44 int abd_abs(int value);
45 
46 
47 void set_drive_speed(int left, int right)
48 {
49  //low(26); low(27);
50  /*
51  if(encoderFeedback)
52  {
53  if(left > abd_speedLimit[B]) left = abd_speedLimit[B];
54  if(left < -abd_speedLimit[B]) left = -abd_speedLimit[B];
55  if(right > abd_speedLimit[B]) right = abd_speedLimit[B];
56  if(right < -abd_speedLimit[B]) right = -abd_speedLimit[B];
57  }
58  */
59 
60 
61  abd_speedT[ABD_L] = left;
62  abd_speedT[ABD_R] = right;
63 
64  abd_speedi[ABD_L] = abd_speed[ABD_L];
65  abd_speedi[ABD_R] = abd_speed[ABD_R];
66  abd_speedd[ABD_L] = abd_speedT[ABD_L] - abd_speedi[ABD_L];
67  abd_speedd[ABD_R] = abd_speedT[ABD_R] - abd_speedi[ABD_R];
68 
69  for(int lr = ABD_L; lr <= ABD_R; lr++)
70  {
71  input(14);
72  //abd_speedi[lr] = abd_speed[lr];
73  //abd_speedd[lr] = abd_speedT[lr] - abd_speedi[lr];
74  //abd_speedLimit[lr] = abd_speedLimit[ABD_B];
75  abd_ditherAa[lr] = 0;
76  abd_ditherAd[lr] = 0;
77  abd_ditherAp[lr] = 0;
78 
79  abd_ditherVa[lr] = 0;
80  abd_ditherVd[lr] = 0;
81  abd_ditherVp[lr] = 0;
82 
83  abd_gotoFlag[lr] = 0;
84  abd_dvFlag[lr] = 1;
85  abd_speedLimit[lr] = abd_speedLimit[ABD_B];
86  abd_rampStep[lr] = abd_rampStep[ABD_B];
87  abd_ditherA[lr] = 0;
88  abd_ditherV[lr] = 0;
89  int Rp, Lp;
90  if(lr == 0) {Rp = 1; Lp = 0;} else {Rp = 0; Lp = 1;}
91  //
92  //sprint(abd_str, "\r\rsdd %d %d\r\r", abd_speedd[Rp], abd_speedd[Lp]);
93  if(abd_abs(abd_speedd[Rp]) > abd_abs(abd_speedd[Lp]))
94  {
95  //if(Rp == 1) {high(26); low(27);}
96  //if(Rp == 0) {high(27); low(26);}
97  //abd_speedLimit[Lp] = abd_speedLimit[B] * abd_abs(abd_speedd[Lp]) / abd_abs(abd_speedd[Rp]);
98  abd_rampStep[Lp] = abd_rampStep[ABD_B] * abd_abs(abd_speedd[Lp]) / abd_abs(abd_speedd[Rp]);
99 
100  abd_ditherA[Lp] = (abd_rampStep[ABD_B] * abd_speedd[Lp]) % abd_abs(abd_speedd[Rp]);
101  abd_ditherA[Lp] *= 50;
102  abd_ditherA[Lp] /= abd_abs(abd_speedd[Rp]);
103  abd_ditherA[Lp] = abd_abs(abd_ditherA[Lp]);
104  }
105  }
106 
107  #ifdef _monitor_
108  sprint(
109  abd_str, "\rvL%d, rspdLimL=%d, rmpStpL=%d dthrAL=%d, dthrVL=%d | "\
110  "vR%d, spdLimR=%d, rmpStpR=%d dthrAR=%d, dthrVR=%d\r\r",
111  abd_speedT[ABD_L], abd_speedLimit[ABD_L], abd_rampStep[ABD_L], abd_ditherA[ABD_L], abd_ditherV[ABD_L],
112  abd_speedT[ABD_R], abd_speedLimit[ABD_R], abd_rampStep[ABD_R], abd_ditherA[ABD_R], abd_ditherV[ABD_R]
113  );
114  #endif
115  //
116  if(!abd_cog)
117  {
119  abd_cog = 1 + cogstart(abd_encoders, NULL, abd_stack, sizeof(abd_stack)-1);
120  }
121 
122  //
123  if(abd_stopCtr[ABD_L] || abd_stopCtr[ABD_R])
124  {
125  while(abd_stopCtr[ABD_L] || abd_stopCtr[ABD_R]);
126  }
127  //int n = _servoPulseReps + 6;
128  int n = _servoPulseReps + 6;
129  while(_servoPulseReps != n);
130  if(abd_stopCtr[ABD_L] || abd_stopCtr[ABD_R])
131  {
132  while(abd_stopCtr[ABD_L] || abd_stopCtr[ABD_R]);
133  }
134  //
135 }
136 //
137 
138 void drive_speed(int left, int right) // driveSpeeds function
139 {
140  if(!abd_intTabSetup)
141  {
142  interpolation_table_setup();
143  set_drive_speed(0, 0);
144  }
145 
146  if((left != speedPrev[ABD_L]) || (right != speedPrev[ABD_R]))
147  {
148 
149  set_drive_speed(left, right);
150 
151  }
152 
153  speedPrev[ABD_L] = abd_speedT[ABD_L];
154  speedPrev[ABD_R] = abd_speedT[ABD_R];
155 }
156 
157 
drive_speed
void drive_speed(int left, int right)
Set wheel speeds in encoder ticks per second. An encoder tick is 1/64th of a revolution,...
Definition: speed.c:138
input
int input(int pin)
Set an I/O pin to input and return 1 if pin detects a high signal, or 0 if it detects low.
Definition: input.c:19
sprint
int int int sprint(char *buffer, const char *format,...) __attribute__((format(printf
Print format "..." args to the output buffer. The output buffer must be big enough for the output.
abdrive.h
This library takes care of encoder monitoring and servo signaling, and provides a simple set of funct...
cogstart
int cogstart(void(*func)(void *), void *par, void *stack, size_t stacksize)
Start a new propeller LMM function/thread in another COG.