Skip to content

Commit

Permalink
fix data race in controlled motor test
Browse files Browse the repository at this point in the history
  • Loading branch information
martha-johnston committed Sep 30, 2024
1 parent 24b4ba4 commit 311b94e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions components/base/sensorcontrolled/velocities.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,8 @@ func (sb *sensorBase) State(ctx context.Context) ([]float64, error) {
}
return []float64{linvel.Y, angvel.Z}, nil
}

// GetType returns that the controllable type is base
func (cm *sensorBase) GetType() string {
return "base"
}
5 changes: 5 additions & 0 deletions components/motor/gpio/controlled.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func (cm *controlledMotor) State(ctx context.Context) ([]float64, error) {
return []float64{pos}, err
}

// GetType returns that the controllable type is motor
func (cm *controlledMotor) GetType() string {
return "motor"
}

// updateControlBlockPosVel updates the trap profile and the constant set point for position and velocity control.
func (cm *controlledMotor) updateControlBlock(ctx context.Context, setPoint, maxVel float64) error {
// Update the Trapezoidal Velocity Profile block with the given maxVel for velocity control
Expand Down
2 changes: 2 additions & 0 deletions control/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@ func (b *constant) Output(ctx context.Context) []*Signal {
}

func (b *constant) Config(ctx context.Context) BlockConfig {
b.mu.Lock()
defer b.mu.Unlock()
return b.cfg
}
2 changes: 2 additions & 0 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type Controllable interface {
SetState(ctx context.Context, state []*Signal) error
// Position returns the current encoder count value
State(ctx context.Context) ([]float64, error)
// Type returns if the controllable is a base or a motor
GetType() string
}

// Config configuration of the control loop.
Expand Down
2 changes: 1 addition & 1 deletion control/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (e *endpoint) Next(ctx context.Context, x []*Signal, dt time.Duration) ([]*
e.mu.Lock()
defer e.mu.Unlock()
e.logger.CDebugf(ctx, "z length %v", len(x))
e.logger.CDebugf(ctx, "controllable is %v", e.ctr)
e.logger.CDebugf(ctx, "controllable type is %v", e.ctr.GetType())
switch len(x) {
case 1, 2:
if e.ctr != nil {
Expand Down
2 changes: 2 additions & 0 deletions control/trapezoid_velocity_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,7 @@ func (s *trapezoidVelocityGenerator) Output(ctx context.Context) []*Signal {
}

func (s *trapezoidVelocityGenerator) Config(ctx context.Context) BlockConfig {
s.mu.Lock()
defer s.mu.Unlock()
return s.cfg
}

0 comments on commit 311b94e

Please sign in to comment.