Skip to content

Commit

Permalink
Add ChassisSpeedLevelType.
Browse files Browse the repository at this point in the history
- Also add some comments.
  • Loading branch information
brunoga committed May 18, 2024
1 parent c30c97b commit f929955
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
20 changes: 20 additions & 0 deletions module/robot/chassis_speed_level_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package robot

// ChassisSpeedLevelType represents the speed level of the chassis.
type ChassisSpeedLevelType int8

const (
// ChassisSpeedLevelFast is the fast speed level.
ChassisSpeedLevelFast ChassisSpeedLevelType = iota
// ChassisSpeedLevelMedium is the medium speed level.
ChassisSpeedLevelMedium
// ChassisSpeedLevelSlow is the slow speed level.
ChassisSpeedLevelSlow
// ChassisSpeedLevelCustom is the custom speed level. This enables
// individually setting speeds for each direction/axis. This is not
// supported yet.
//
// TODO(bga): Add support for this.
ChassisSpeedLevelCustom
ChassisSpeedLevelTypeCount
)
12 changes: 7 additions & 5 deletions module/robot/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,24 @@ func (r *Robot) BatteryPowerPercent() uint8 {
return *r.batteryPowerPercent.Load()
}

func (r *Robot) ChassisSpeedLevel() (uint8, error) {
// ChassisSpeedLevel returns the current chassis speed level.
func (r *Robot) ChassisSpeedLevel() (ChassisSpeedLevelType, error) {
res, err := r.UB().GetKeyValueSync(key.KeyRobomasterSystemChassisSpeedLevel, true)
if err != nil {
return 0, err
}

return uint8(res.Value().(*value.Uint64).Value), nil
return ChassisSpeedLevelType(res.Value().(*value.Uint64).Value - 1), nil
}

func (r *Robot) SetChassisSpeedLevel(speedLevel uint8) error {
if speedLevel < 1 || speedLevel > 4 {
// SetChassisSpeedLevel sets the chassis speed level.
func (r *Robot) SetChassisSpeedLevel(speedLevel ChassisSpeedLevelType) error {
if speedLevel >= ChassisSpeedLevelTypeCount {
return fmt.Errorf("invalid chassis speed level: %d", speedLevel)
}

return r.UB().SetKeyValueSync(key.KeyRobomasterSystemChassisSpeedLevel,
&value.Uint64{Value: uint64(speedLevel)})
&value.Uint64{Value: uint64(speedLevel + 1)})
}

// Stop stops the Robot module.
Expand Down

0 comments on commit f929955

Please sign in to comment.