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

RSDK-6282 [part 1]: add PID values to the gpio motor config #3435

Merged
merged 6 commits into from
Jan 25, 2024

Conversation

martha-johnston
Copy link
Contributor

@martha-johnston martha-johnston commented Jan 12, 2024

starting with just the motor config and will replicate in the sensor-controlled base

edit: also mildly fixes the RSDK-6308 bug. you can now run multiple motors with control loops at the same time, but it's still not blocking so you have to add sleeps if you want it to work as expected. going to fix that issue in another PR

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Jan 12, 2024
@martha-johnston martha-johnston changed the title RSDK-6282: add PID values to the gpio motor config RSDK-6282 [part 1]: add PID values to the gpio motor config Jan 12, 2024
@martha-johnston martha-johnston requested review from a team, randhid and susmitaSanyal and removed request for a team January 12, 2024 18:13
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 12, 2024
Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

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

A few suggestions, and I'd like to observe behaviour given your description of what was happening.

Comment on lines 162 to 186
if p == 0.0 && i == 0.0 && d == 0.0 {
// when tuning (all PID are zero), the loop has to exclude the trapz block, so the sum block is
// temporarily changed to depend on the constant block instead of the trapz block to pass over trapz
sumBlock := control.BlockConfig{
Name: "sum",
Type: "sum",
Attribute: rdkutils.AttributeMap{
"sum_string": "+-",
},
DependsOn: []string{"set_point", "derivative"},
}
conf.Blocks = append(conf.Blocks, sumBlock)
} else {
// if not tuning, set the sum block to once again depend
// on the trapz block instead of the constant bloc
sumBlock := control.BlockConfig{
Name: "sum",
Type: "sum",
Attribute: rdkutils.AttributeMap{
"sum_string": "+-",
},
DependsOn: []string{"trapz", "derivative"},
}
conf.Blocks = append(conf.Blocks, sumBlock)
}
Copy link
Member

Choose a reason for hiding this comment

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

We can go ahead and try to make this a helper function from the package. Might help with semantically calling that function from outside packages. What do you think?

Okay to do in a follow up PR.

Copy link
Member

Choose a reason for hiding this comment

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

+1 , this portion can be a function.

blk, err := createBlock(bcfg, logger)
if err != nil {
return nil, err
}
l.blocks[bcfg.Name] = &controlBlockInternal{blk: blk, blockType: bcfg.Type}
l.blocks[bcfg.Name].blockIndex = i
Copy link
Member

Choose a reason for hiding this comment

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

[q] Why are you adding the block index?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also don't think this is necessary any longer with new changes

if motorConfig.ControlParameters.P == 0.0 &&
motorConfig.ControlParameters.I == 0.0 &&
motorConfig.ControlParameters.D == 0.0 {
em.loop.SetTuning(context.Background(), true)
Copy link
Member

Choose a reason for hiding this comment

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

Is this background context canceled by anything in the loop? Or will it continue returning nil and blocking on a done call in the controls package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it's canceled by anything... I'm not sure it's necessary to even have a context for this function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this function should be removed in a future pr

Copy link
Member

@susmitaSanyal susmitaSanyal left a comment

Choose a reason for hiding this comment

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

Approving with the assumption that it passed testing!

Comment on lines 162 to 186
if p == 0.0 && i == 0.0 && d == 0.0 {
// when tuning (all PID are zero), the loop has to exclude the trapz block, so the sum block is
// temporarily changed to depend on the constant block instead of the trapz block to pass over trapz
sumBlock := control.BlockConfig{
Name: "sum",
Type: "sum",
Attribute: rdkutils.AttributeMap{
"sum_string": "+-",
},
DependsOn: []string{"set_point", "derivative"},
}
conf.Blocks = append(conf.Blocks, sumBlock)
} else {
// if not tuning, set the sum block to once again depend
// on the trapz block instead of the constant bloc
sumBlock := control.BlockConfig{
Name: "sum",
Type: "sum",
Attribute: rdkutils.AttributeMap{
"sum_string": "+-",
},
DependsOn: []string{"trapz", "derivative"},
}
conf.Blocks = append(conf.Blocks, sumBlock)
}
Copy link
Member

Choose a reason for hiding this comment

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

+1 , this portion can be a function.

type motorPIDConfig struct {
P float64 `json:"p"`
I float64 `json:"i"`
D float64 `json:"d"`
Copy link
Member

Choose a reason for hiding this comment

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

Love this struct <3

if err := blk.blk.UpdateConfig(ctx, config); err != nil {
return err
}
l.cfg.Blocks[blk.blockIndex] = blk.blk.Config(ctx)
Copy link
Contributor Author

@martha-johnston martha-johnston Jan 18, 2024

Choose a reason for hiding this comment

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

@randhid block index used here because UpdateConfig was not actually updating the config it was just updating the blocks , and the blocks aren't a map so I can't just use the name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wait no other way. it updates the config but not the actual blocks

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 18, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 24, 2024
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 24, 2024
Copy link
Member

@randhid randhid left a comment

Choose a reason for hiding this comment

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

LGTM!

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 24, 2024
@martha-johnston martha-johnston merged commit a817114 into viamrobotics:main Jan 25, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants