comparison Discovery/Src/motion.c @ 378:834e087505ec MotionDetection

Incremented "idle window" for scroll detection Already small changes in the position of the arm cause scroll event => increased window which will cause no events +Code cleanup
author ideenmodellierer
date Mon, 16 Sep 2019 22:46:24 +0200
parents 7b981f8bdd41
children 695434a6dcf6
comparison
equal deleted inserted replaced
377:939bc4da6812 378:834e087505ec
24 #define SECTOR_WINDOW 80.0 /* Pitch window which is used for custom view projection */ 24 #define SECTOR_WINDOW 80.0 /* Pitch window which is used for custom view projection */
25 #define SECTOR_HYSTERY 3 /* Additional offset to avoid fast changing displays */ 25 #define SECTOR_HYSTERY 3 /* Additional offset to avoid fast changing displays */
26 #define SECTOR_BORDER 400.0 /* Define a value which is out of limit to avoid not wanted key events */ 26 #define SECTOR_BORDER 400.0 /* Define a value which is out of limit to avoid not wanted key events */
27 #define SECTOR_FILTER 10 /* Define speed for calculated angle to follow real value */ 27 #define SECTOR_FILTER 10 /* Define speed for calculated angle to follow real value */
28 28
29 #define SECTOR_MAX 20 /* maximum number of sectors */ 29 #define SECTOR_MAX 19 /* maximum number of sectors */
30 #define SECTOR_SCROLL 6 /* number of sectors used for scroll detection */ 30 #define SECTOR_SCROLL 7 /* number of sectors used for scroll detection */
31 31
32 detectionState_t detectionState = DETECT_NOTHING; 32 detectionState_t detectionState = DETECT_NOTHING;
33 33
34 uint8_t curSector; 34 uint8_t curSector;
35 static uint8_t targetSector; 35 static uint8_t targetSector;
153 } 153 }
154 154
155 /* Check if pitch is not in center position and trigger a button action if needed */ 155 /* Check if pitch is not in center position and trigger a button action if needed */
156 detectionState_t detectScrollButtonEvent(float curPitch) 156 detectionState_t detectScrollButtonEvent(float curPitch)
157 { 157 {
158 static uint8_t delayscroll = 0; /* slow dow the number of scroll events */ 158 static uint8_t delayscroll = 0; /* slow down the number of scroll events */
159 159
160 uint8_t PitchEvent = DETECT_NOTHING; 160 uint8_t PitchEvent = DETECT_NOTHING;
161 uint8_t newSector; 161 uint8_t newSector;
162 162
163 if(delayscroll == 0) 163 if(delayscroll == 0)
167 switch(newSector) 167 switch(newSector)
168 { 168 {
169 case 0: 169 case 0:
170 case 1: PitchEvent = DETECT_POS_PITCH; 170 case 1: PitchEvent = DETECT_POS_PITCH;
171 break; 171 break;
172 case 4: 172 case 5:
173 case 5: PitchEvent = DETECT_NEG_PITCH; 173 case 6: PitchEvent = DETECT_NEG_PITCH;
174 break; 174 break;
175 default: 175 default:
176 break; 176 break;
177 } 177 }
178 if(PitchEvent != DETECT_NOTHING) 178 if(PitchEvent != DETECT_NOTHING)
244 } 244 }
245 else 245 else
246 { 246 {
247 stableCnt++; /* reset start sector in case of slow movement */ 247 stableCnt++; /* reset start sector in case of slow movement */
248 } 248 }
249 // startPitch = lastPitch;
250 } 249 }
251 break; 250 break;
252 case DETECT_NEG_MOVE: 251 case DETECT_NEG_MOVE:
253 case DETECT_POS_MOVE: if(curSector != lastSector) /* still moving? */ 252 case DETECT_POS_MOVE: if(curSector != lastSector) /* still moving? */
254 { 253 {
255 stableCnt++; 254 stableCnt++;
256 } 255 }
257 else 256 else
258 { 257 {
259 // if(stableCnt >= 1) /* debounce movement */ 258 if(abs(startSector - curSector) > 2)
260 { 259 {
261 if(abs(startSector - curSector) > 2) 260 detectionState++;
262 { 261 stableCnt = 0;
263 detectionState++; 262 }
264 stableCnt = 0; 263 else
265 } 264 {
266 else
267 {
268 // detectionState = DETECT_NOTHING;
269 stableCnt++; /* maybe on the boundary of a sector => handle as stable */ 265 stableCnt++; /* maybe on the boundary of a sector => handle as stable */
270 } 266 }
271 }
272 #if 0
273 else
274 {
275 // detectionState = DETECT_NOTHING;
276 stableCnt++; /* maybe on the boundary of a sector => handle as stable */
277 }
278 #endif
279 } 267 }
280 break; 268 break;
281 case DETECT_MINIMA: 269 case DETECT_MINIMA:
282 case DETECT_MAXIMA: /* stay at maximum for short time to add a pattern for user interaction */ 270 case DETECT_MAXIMA: /* stay at maximum for short time to add a pattern for user interaction */
283 if(curSector == lastSector) 271 if(curSector == lastSector)
291 detectionState++; 279 detectionState++;
292 stableCnt = 0; 280 stableCnt = 0;
293 } 281 }
294 else 282 else
295 { 283 {
296 // detectionState = DETECT_NOTHING;
297 stableCnt++; /* maybe on the boundary of a sector => handle as stable */ 284 stableCnt++; /* maybe on the boundary of a sector => handle as stable */
298 } 285 }
299 } 286 }
300 break; 287 break;
301 case DETECT_RISEBACK: 288 case DETECT_RISEBACK:
306 detectionState++; 293 detectionState++;
307 stableCnt = 0; 294 stableCnt = 0;
308 } 295 }
309 else 296 else
310 { 297 {
311 // detectionState = DETECT_NOTHING; 298 stableCnt++; /* maybe on the boundary of a sector => handle as stable */
312 stableCnt++; /* maybe on the boundary of a sector => handle as stable */
313 } 299 }
314 } 300 }
315 else 301 else
316 { 302 {
317 stableCnt++; 303 stableCnt++;
327 { 313 {
328 detectionState = DETECT_NOTHING; 314 detectionState = DETECT_NOTHING;
329 stableCnt = 0; 315 stableCnt = 0;
330 } 316 }
331 317
332 #if 0
333 curSpeed = currentPitch - lastPitch;
334
335 /* feed value into state machine */
336 switch (detectionState)
337 {
338 case DETECT_NOTHING: if(fabsf(curSpeed) < MOVE_DELTA_SPEED) /* detect a stable condition before evaluating for the next move */
339 {
340 stableCnt++;
341 }
342 else
343 {
344 stableCnt=0;
345 }
346
347 if(stableCnt > STABLE_STATE_COUNT)
348 {
349 detectionState = DETECT_START;
350 stableCnt = 0;
351 }
352 break;
353 case DETECT_START: if(fabsf(curSpeed) > MOVE_DELTA_SPEED)
354 {
355 if(curSpeed > 0)
356 {
357 detectionState = DETECT_POS_MOVE;
358 }
359 else
360 {
361 detectionState = DETECT_NEG_MOVE;
362 }
363 stableCnt = 0;
364 startPitch = lastPitch;
365 }
366 break;
367 case DETECT_NEG_MOVE:
368 case DETECT_POS_MOVE: if(fabsf(curSpeed) > MOVE_DELTA_SPEED )
369 {
370 stableCnt++;
371 }
372 else
373 {
374 if(stableCnt >= STABLE_STATE_COUNT) /* debounce movement */
375 {
376 if(fabsf(startPitch - currentPitch) > PITCH_DELTA_COUNT)
377 {
378 detectionState++;
379 }
380 else
381 {
382 detectionState = DETECT_NOTHING;
383 }
384 }
385 else
386 {
387 detectionState = DETECT_NOTHING;
388 }
389 stableCnt = 0;
390 }
391 break;
392 case DETECT_MINIMA:
393 case DETECT_MAXIMA: /* stay at maximum for short time to add a pattern for user interaction */
394 if(fabsf(curSpeed) < MOVE_DELTA_SPEED )
395 {
396 stableCnt++;
397 }
398 else
399 {
400 if(stableCnt > 0)
401 {
402 detectionState++;
403 }
404 else
405 {
406 detectionState = DETECT_NOTHING;
407 }
408 stableCnt = 0;
409 }
410 break;
411 case DETECT_RISEBACK:
412 case DETECT_FALLBACK: if(fabsf(curSpeed) < MOVE_DELTA_SPEED)
413 {
414 if(fabsf(startPitch - currentPitch) < PITCH_DELTA_END)
415 {
416 detectionState++;
417 }
418 }
419 stableCnt++;
420 break;
421 default:
422 detectionState = DETECT_NOTHING;
423 break;
424
425 }
426 if(stableCnt > STABLE_STATE_TIMEOUT)
427 {
428 detectionState = DETECT_NOTHING;
429 stableCnt = 0;
430 }
431
432 lastPitch = currentPitch;
433 #endif
434 return detectionState; 318 return detectionState;
435 } 319 }