Skip to content
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

Mimo pid updates #4290

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
24 changes: 18 additions & 6 deletions control/control_loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,29 @@ func (l *Loop) GetConfig(ctx context.Context) Config {
func (l *Loop) MonitorTuning(ctx context.Context) {
// wait until tuning has started
for {
tuning := l.GetTuning(ctx)
if tuning {
break
// 100 Hz is probably faster than we need, but we needed at least a small delay because
// GetTuning will lock the PID block
if utils.SelectContextOrWait(ctx, 10*time.Millisecond) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try to remove these if ya want. Was worried that calling GetTuning was affecting things at the time when I added this.

Copy link
Contributor

@martha-johnston martha-johnston Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine and probably safer. happy with leaving it.

tuning := l.GetTuning(ctx)
if tuning {
break
}
continue
}
l.logger.Error("error starting tuner")
return
}
// wait until tuning is done
for {
tuning := l.GetTuning(ctx)
if !tuning {
break
if utils.SelectContextOrWait(ctx, 10*time.Millisecond) {
tuning := l.GetTuning(ctx)
if !tuning {
break
}
continue
}
l.logger.Error("error waiting for tuner")
return
}
}

Expand Down
20 changes: 17 additions & 3 deletions control/control_signal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package control

import "sync"
import (
"sync"
)

// Signal holds any data passed between blocks.
type Signal struct {
Expand All @@ -23,11 +25,23 @@ func makeSignal(name string, blockType controlBlockType) *Signal {
return &s
}

// Make Signals returns a Signal object where the length of its signal[] array is dependent
// on the number of PIDSets from the config.
func makeSignals(name string, blockType controlBlockType, dimension int) *Signal {
var s Signal
s.dimension = dimension
s.signal = make([]float64, dimension)
s.time = make([]int, dimension)
s.name = name
s.blockType = blockType
return &s
}

// GetSignalValueAt returns the value of the signal at an index, threadsafe.
func (s *Signal) GetSignalValueAt(i int) float64 {
s.mu.Lock()
defer s.mu.Unlock()
if i > len(s.signal)-1 {
if !(i < len(s.signal)) {
return 0.0
}
return s.signal[i]
Expand All @@ -37,7 +51,7 @@ func (s *Signal) GetSignalValueAt(i int) float64 {
func (s *Signal) SetSignalValueAt(i int, val float64) {
s.mu.Lock()
defer s.mu.Unlock()
if i > len(s.signal)-1 {
if !(i < len(s.signal)) {
return
}
s.signal[i] = val
Expand Down
Loading
Loading