PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
goto.c
1 //#define _monitor_
2 
3 #include "abdrive.h"
4 
5 volatile int abd_speedLimit[4];
6 volatile int abd_intTabSetup;
7 volatile int abd_dist[2];
8 volatile int abd_ticks[2];
9 volatile int abd_ticksf[2];
10 volatile int abd_ticksi[2];
11 volatile int abd_gotoFlag[2];
12 volatile int abd_dvFlag[2];
13 volatile int abd_rampStep[3];
14 volatile int abd_gotoRampStep[3];
15 volatile int abd_speedLimit[4];
16 volatile int abd_gotoSpeedLimit[4];
17 volatile int abd_ditherA[2];
18 volatile int abd_ditherAa[2];
19 volatile int abd_ditherAd[2];
20 volatile int abd_ditherAp[2];
21 volatile int abd_blockGoto;
22 volatile int abd_ditherV[2];
23 volatile int abd_ditherVa[2];
24 volatile int abd_ditherVd[2];
25 volatile int abd_ditherVp[2];
26 volatile int abd_stopCtr[2];
27 
28 #ifdef _monitor_
29  volatile char abd_str[128];
30 #endif
31 
32 
33 void interpolation_table_setup();
34 void set_drive_speed(int left, int right);
35 int abd_abs(int value);
36 
37 
38 void drive_goto(int left, int right)
39 {
40  // Patch to prevent certain combinations of initial speeds
41  // from putting drive_goto into a mode that doesn't terminate.
42  //
43  if( (abd_dvFlag[ABD_L] == 1) || (abd_dvFlag[ABD_R] == 1))
44  {
45  drive_speed(0, 0);
46  }
47  //
48 
49  int rampStepSave = abd_rampStep[ABD_B];
50  abd_rampStep[ABD_B] = abd_gotoRampStep[ABD_B];
51 
52  int topSpeedSave = abd_speedLimit[ABD_B];
53  abd_speedLimit[ABD_B] = abd_gotoSpeedLimit[ABD_B];
54 
55  //sprint("\r\r\rdrive_goto(%d, %d)\r\r", left, right);
56  if(!abd_intTabSetup)
57  {
58  interpolation_table_setup();
59  set_drive_speed(0, 0);
60  }
61 
62  abd_dist[ABD_L] = left;
63  abd_dist[ABD_R] = right;
64 
65  for(int lr = 0; lr <=1; lr++)
66  {
67 
68  if(abd_abs(abd_ticksf[lr] - abd_ticks[lr]) < 6)
69  {
70  abd_ticksi[lr] = abd_ticksf[lr];
71  }
72  else
73  {
74  abd_ticksi[lr] = abd_ticks[lr];
75  }
76 
77  abd_ticksf[lr] = abd_ticksi[lr] + abd_dist[lr];
78 
79  abd_speedLimit[lr] = abd_speedLimit[ABD_B];
80  abd_rampStep[lr] = abd_rampStep[ABD_B];
81  abd_ditherA[lr] = 0;
82  abd_ditherV[lr] = 0;
83 
84  abd_ditherAa[lr] = 0;
85  abd_ditherAd[lr] = 0;
86  abd_ditherAp[lr] = 0;
87 
88  abd_ditherVa[lr] = 0;
89  abd_ditherVd[lr] = 0;
90  abd_ditherVp[lr] = 0;
91 
92  abd_gotoFlag[lr] = 1;
93  abd_dvFlag[lr] = 0;
94 
95 
96  int Rp, Lp;
97  if(lr == 0) {Rp = 1; Lp = 0;} else {Rp = 0; Lp = 1;}
98 
99  if(abd_abs(abd_dist[Rp]) > abd_abs(abd_dist[Lp]))
100  {
101  abd_speedLimit[Lp] = abd_speedLimit[ABD_B] * abd_abs(abd_dist[Lp]) / abd_abs(abd_dist[Rp]);
102  abd_rampStep[Lp] = abd_rampStep[ABD_B] * abd_abs(abd_dist[Lp]) / abd_abs(abd_dist[Rp]);
103 
104  abd_ditherA[Lp] = (abd_rampStep[ABD_B] * abd_dist[Lp]) % abd_abs(abd_dist[Rp]);
105  abd_ditherA[Lp] *= 50;
106  abd_ditherA[Lp] /= abd_abs(abd_dist[Rp]);
107  abd_ditherA[Lp] = abd_abs(abd_ditherA[Lp]);
108 
109  abd_ditherV[Lp] = (abd_speedLimit[ABD_B] * abd_dist[Lp]) % abd_abs(abd_dist[Rp]);
110  abd_ditherV[Lp] *= 50;
111  abd_ditherV[Lp] /= abd_abs(abd_dist[Rp]);
112  abd_ditherV[Lp] = abd_abs(abd_ditherV[Lp]);
113  }
114  }
115 
116  #ifdef _monitor_
117  if(abd_blockGoto == 1)
118  {
119  sprint(abd_str, "\r\rddL%d, spdLimL=%d, rmpStpL=%d dthrAL=%d, dthrVL=%d | "\
120  "ddR%d, spdLimL=%d, rmpStpL=%d dthrAL=%d, dthrVL=%d\r\r",
121  left, abd_speedLimit[ABD_L], abd_rampStep[ABD_L], abd_ditherA[ABD_L], abd_ditherV[ABD_L],
122  right, abd_speedLimit[ABD_R], abd_rampStep[ABD_R], abd_ditherA[ABD_R], abd_ditherV[ABD_R]
123  );//
124  }
125  #endif
126 
127  if(abd_blockGoto == 1)
128  {
129  //19 while((abd_gotoFlag[L] != 0) || (abd_gotoFlag[R] != 0));
130  while((abd_gotoFlag[ABD_L] != 0) || (abd_gotoFlag[ABD_R] != 0) || (abd_stopCtr[ABD_L] > 0) || (abd_stopCtr[ABD_R] > 0));
131  pause(40); //19
132  while((abd_gotoFlag[ABD_L] != 0) || (abd_gotoFlag[ABD_R] != 0) || (abd_stopCtr[ABD_L] > 0) || (abd_stopCtr[ABD_R] > 0)); //19
133  }
134  #ifdef _monitor_
135  sprint(abd_str, "\r\rddL%d, spdLimL=%d, rmpStpL=%d dthrAL=%d, dthrVL=%d | "\
136  "ddR%d, spdLimR=%d, rmpStpR=%d dthrAR=%d, dthrVR=%d\r\r",
137  left, abd_speedLimit[ABD_L], abd_rampStep[ABD_L], abd_ditherA[ABD_L], abd_ditherV[ABD_L],
138  right, abd_speedLimit[ABD_R], abd_rampStep[ABD_R], abd_ditherA[ABD_R], abd_ditherV[ABD_R]
139  );//
140  #endif
141 
142  abd_rampStep[ABD_B] = rampStepSave;
143  abd_speedLimit[ABD_B] = topSpeedSave;
144 }
145 //
146 
147 
148 
149 
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
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition: libws2812.c:125
drive_goto
void drive_goto(int distLeft, int distRight)
Make each wheel go a particular distance. Recommended for straight forward, backward,...
Definition: goto.c:38
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...