-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RSDK-1617 - fix interrupt bug in ultrasonic sensor #1764
RSDK-1617 - fix interrupt bug in ultrasonic sensor #1764
Conversation
case <-time.After(time.Millisecond * time.Duration(s.timeoutMs)): | ||
return nil, errors.New("ultrasonic timeout") | ||
return errors.New("ultrasonic timeout 1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the "1" supposed to be there? typo maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
// on the time interval between the sound and its echo | ||
// and the speed of sound (343 m/s) | ||
distMeters := timeA.Sub(timeB).Seconds() * 343.0 / 2.0 | ||
distMillis := math.Round((distMeters*1000.0)*1000.0) / 1000.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit : distMilli (otherwise sounds like millisecond :P
) | ||
} | ||
|
||
func (s *Sensor) sendDistance(ctx context.Context) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: measureDistance
s.activeBackgroundWorkers.Add(1) | ||
rdkutils.ManagedGo( | ||
func() { | ||
defer s.echoInterrupt.RemoveCallback(s.intChan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if you do the remove here I think you should register the callback here as well
if err := s.sendDistance(ctx); err != nil { | ||
s.errChan <- err | ||
} | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it needed here? we could just wait forever on intChan/readingChan/cancelCtx
s.isReading = false | ||
s.mu.Unlock() | ||
}() | ||
s.isReading = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you use this struct field for anything else? if not I would remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple of minor things but otherwise LGTM!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We tested this with my setup and LGTM! The value is a LOT more correct. Thanks!
No description provided.