Skip to content

Commit

Permalink
Rsdk 4495 integration tests (Updating comments) (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyrhyde authored Sep 11, 2023
1 parent d4c1ac2 commit 8c5d8ca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
28 changes: 14 additions & 14 deletions sensorprocess/imusensorprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// StartIMU polls the IMU to get the next sensor reading and adds it to the cartofacade.
// stops when the context is Done.
// Stops when the context is Done.
func (config *Config) StartIMU(ctx context.Context) bool {
for {
select {
Expand All @@ -29,7 +29,7 @@ func (config *Config) StartIMU(ctx context.Context) bool {
}
}

// addIMUReading adds a imu reading to the cartofacade, using the lidar's data rate to determine whether to run in
// addIMUReading adds an IMU reading to the cartofacade, using the lidar's data rate to determine whether to run in
// offline or online mode.
func (config *Config) addIMUReading(ctx context.Context) bool {
if config.LidarDataRateMsec != 0 {
Expand All @@ -38,40 +38,40 @@ func (config *Config) addIMUReading(ctx context.Context) bool {
return config.addIMUReadingInOffline(ctx)
}

// addIMUReadingInOnline ensure the most recent imu scan, after corresponding lidar scans, gets processed by cartographer.
// addIMUReadingInOnline ensures the most recent IMU scan, after corresponding lidar scans, gets processed by cartographer.
func (config *Config) addIMUReadingInOnline(ctx context.Context) bool {
// get next imu data response
// get next IMU data response
tsr, status, err := getTimedIMUSensorReading(ctx, config)
if err != nil {
return status
}

// parse imu reading
// parse IMU reading
sr := cartofacade.IMUReading{
LinearAcceleration: tsr.LinearAcceleration,
AngularVelocity: tsr.AngularVelocity,
}

// update stored imu time
// update stored IMU time
config.updateMutexProtectedIMUData(tsr.ReadingTime, sr)

// add imu data to cartographer and sleep remainder of time interval
// add IMU data to cartographer and sleep remainder of time interval
timeToSleep := config.tryAddIMUReading(ctx, sr, tsr.ReadingTime)
time.Sleep(time.Duration(timeToSleep) * time.Millisecond)
config.Logger.Debugf("imu sleep for %vms", timeToSleep)

return false
}

// addIMUReadingInOffline ensures imu scans get added in a time ordered series with any desired lidar scans without skipping any.
// addIMUReadingInOffline ensures IMU scans get added in a time ordered series with any desired lidar scans without skipping any.
func (config *Config) addIMUReadingInOffline(ctx context.Context) bool {
// extract current lidar reading time for ordering data ingestion
config.Mutex.Lock()
sensorProcessStartTime := config.sensorProcessStartTime
config.Mutex.Unlock()

if sensorProcessStartTime != defaultTime && config.currentIMUData.time != defaultTime {
// skip adding measurement if imu data has been defined but occurs before first lidar data
// skip adding measurement if IMU data has been defined but occurs before first lidar data
if sensorProcessStartTime.Sub(config.currentIMUData.time).Milliseconds() >= 0 {
time.Sleep(10 * time.Millisecond)
return false
Expand All @@ -81,21 +81,21 @@ func (config *Config) addIMUReadingInOffline(ctx context.Context) bool {
config.tryAddIMUReadingUntilSuccess(ctx, config.currentIMUData.data, config.currentIMUData.time)
}

// get next imu data response
// get next IMU data response
tsr, status, err := getTimedIMUSensorReading(ctx, config)
if err != nil {
return status
}

// parse imu reading
// parse IMU reading
sr := cartofacade.IMUReading{
LinearAcceleration: tsr.LinearAcceleration,
AngularVelocity: tsr.AngularVelocity,
}

// TODO: Remove dropping out of order imu readings after DATA-1812 has been complete
// TODO: Remove dropping out of order IMU readings after DATA-1812 has been complete
// JIRA Ticket: https://viam.atlassian.net/browse/DATA-1812
// update current imu data and time
// update current IMU data and time
if config.currentIMUData.time.Sub(tsr.ReadingTime).Milliseconds() < 0 {
config.updateMutexProtectedIMUData(tsr.ReadingTime, sr)
} else {
Expand Down Expand Up @@ -144,7 +144,7 @@ func (config *Config) tryAddIMUReading(ctx context.Context, reading cartofacade.
return int(math.Max(0, float64(config.IMUDataRateMsec-timeElapsedMs)))
}

// getTimedIMUSensorReading returns the next imu reading if available along with a status denoting if the end of dataset has been reached.
// getTimedIMUSensorReading returns the next IMU reading if available along with a status denoting if the end of dataset has been reached.
func getTimedIMUSensorReading(ctx context.Context, config *Config) (sensors.TimedIMUSensorReadingResponse, bool, error) {
tsr, err := config.IMU.TimedIMUSensorReading(ctx)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions sensorprocess/lidarsensorprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

// StartLidar polls the lidar to get the next sensor reading and adds it to the cartofacade.
// stops when the context is Done.
// Stops when the context is Done.
func (config *Config) StartLidar(ctx context.Context) bool {
for {
select {
Expand Down Expand Up @@ -43,7 +43,7 @@ func (config *Config) addLidarReading(ctx context.Context) bool {
return config.addLidarReadingsInOffline(ctx)
}

// addLidarReadingsInOnline ensure the most recent lidar scan, after any corresponding imu scans, gets processed by cartographer.
// addLidarReadingsInOnline ensures the most recent lidar scan, after any corresponding IMU scans, gets processed by cartographer.
func (config *Config) addLidarReadingsInOnline(ctx context.Context) bool {
// get next lidar data response
tsr, status, err := getTimedLidarSensorReading(ctx, config)
Expand All @@ -62,14 +62,14 @@ func (config *Config) addLidarReadingsInOnline(ctx context.Context) bool {
return false
}

// addLidarReadingsInOffline ensures lidar scans get added in a time ordered series with any desired imu scans without skipping any.
// addLidarReadingsInOffline ensures lidar scans get added in a time ordered series with any desired IMU scans without skipping any.
func (config *Config) addLidarReadingsInOffline(ctx context.Context) bool {
// Extract current imu reading time for ordering data ingestion
// Extract current IMU reading time for ordering data ingestion
config.Mutex.Lock()
currentIMUTime := config.currentIMUData.time
config.Mutex.Unlock()

// If an IMU exists, skip adding measurement until the current lidar time is after the current imu timestamp
// If an IMU exists, skip adding measurement until the current lidar time is after the current IMU timestamp
if config.IMUName != "" && config.currentLidarData.time.Sub(currentIMUTime).Milliseconds() > 0 {
time.Sleep(10 * time.Millisecond)
return false
Expand Down
8 changes: 4 additions & 4 deletions testhelper/integrationtesthelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type TimeTracker struct {
// ReadingTime incremented by the sensorReadingInterval.
// The Replay sensor field of the mock readings will match the replay parameter.
// When the end of the mock lidar readings is reached, the done channel
// is written to once so the caller can detect all lidar readings have been emitted
// is written to once so the caller can detect when all lidar readings have been emitted
// from the mock. This is intended to match the same "end of dataset" behavior of a
// replay sensor.
// It is important to provide deterministic time information to cartographer to
Expand All @@ -76,7 +76,7 @@ func IntegrationTimedLidarSensor(
done chan struct{},
timeTracker *TimeTracker,
) (sensors.TimedLidarSensor, error) {
// Check required amount of lidar data is present
// Check that the required amount of lidar data is present
err := mockLidarReadingsValid()
if err != nil {
return nil, err
Expand Down Expand Up @@ -143,7 +143,7 @@ func IntegrationTimedLidarSensor(
// ReadingTime incremented by the sensorReadingInterval.
// The Replay sensor field of the mock readings will match the replay parameter.
// When the end of the mock IMU readings is reached, the done channel
// is written to once so the caller can detect all IMU readings have been emitted
// is written to once so the caller can detect when all IMU readings have been emitted
// from the mock. This is intended to match the same "end of dataset" behavior of a
// replay sensor.
// It is important to provide deterministic time information to cartographer to
Expand All @@ -162,7 +162,7 @@ func IntegrationTimedIMUSensor(
return nil, nil
}

// Check required amount of IMU data is present and creates mock dataset from provided mock data artifact file.
// Check that the required amount of IMU data is present and create a mock dataset from provided mock data artifact file.
mockDataset, err := mockIMUReadingsValid(t)
if err != nil {
return nil, err
Expand Down

0 comments on commit 8c5d8ca

Please sign in to comment.