X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=modules%2Fdevices%2Frobot%2Fblocking_detection_manager%2Fblocking_detection_manager.c;h=1e3808bb1d5e1ac699ae6de9b151cb8f21cfc0a6;hp=8b5f54756bffa6e5925147da645ddd0528825dda;hb=bf5060a8c2deade2516d1cfeccae7137e740b4c4;hpb=876789a372da2e93a816428649e511c2ad9e40be diff --git a/modules/devices/robot/blocking_detection_manager/blocking_detection_manager.c b/modules/devices/robot/blocking_detection_manager/blocking_detection_manager.c index 8b5f547..1e3808b 100644 --- a/modules/devices/robot/blocking_detection_manager/blocking_detection_manager.c +++ b/modules/devices/robot/blocking_detection_manager/blocking_detection_manager.c @@ -71,6 +71,15 @@ void bd_reset(struct blocking_detection * bd) IRQ_UNLOCK(flags); } +static inline uint8_t same_sign(int32_t a, int32_t b) +{ + if (a >= 0 && b >= 0) + return 1; + if (a < 0 && b < 0) + return 1; + return 0; +} + /** function to be called periodically */ void bd_manage_from_speed_cmd(struct blocking_detection * bd, int32_t speed, int32_t cmd) @@ -87,7 +96,7 @@ void bd_manage_from_speed_cmd(struct blocking_detection * bd, * has the same sign than i */ if ((uint32_t)ABS(i) > bd->i_thres && (bd->speed_thres == 0 || ABS(speed) < bd->speed_thres) && - (i * cmd > 0)) { + same_sign(i, cmd)) { if (bd->cpt == bd->cpt_thres - 1) WARNING(E_BLOCKING_DETECTION_MANAGER, "BLOCKING cmd=%ld, speed=%ld i=%ld",