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

Added per-motor control to Thunderscope diagnostics #3401

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

Muxite
Copy link

@Muxite Muxite commented Oct 26, 2024

Description

Added per motor control as a set of radio buttons in thunderscope diagnostic. Direct velocity and per motor control will switch depending on which radio button is pressed. The two control widgets will not appear at the same time, since both inputs are not allowed at the same time. Pressing the button for per-motor control will shut off direct-velocity control and reset those sliders, then switch the widget for per-motor control. Vice versa also applies.

Testing Done

It was tested on a robot in the mezz. Test was made on all sliders of direct-velocity, switching to per-motor without using reset, changing sliders on per-motor, and switching back to direct-velocity. Back-and-forth was done twice. The robot did all the commands it was told to on all motors. It was also tested using print() on the terminal.

Resolved Issues

resolves #3320

Length Justification and Key Files to Review

Key file: drive_and_dribbler_widget.py (relates to primitive.cpp, but primitive was not edited)
Added a function for switching between direct velocity and per motor control mode. Changed the organization of the reset_motor functions to split them up so that each could be run individually instead of having to reset all. I removed the function for enabling the motors, as it was unused (there was no way to use it via the UI).

Review Checklist

  • Function & Class comments: All function definitions (usually in the .h file) should have a javadoc style comment at the start of them. For examples, see the functions defined in thunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.
  • Remove all commented out code
  • Remove extra print statements: for example, those just used for testing
  • Resolve all TODO's: All TODO (or similar) statements should either be completed or associated with a github issue

The current max speed for per-motor speeds is the same variable in tbots_cpp.create2021RobotConstants() called robot_max_speed_m_per_s.

@Muxite Muxite marked this pull request as ready for review October 26, 2024 23:31
@Mr-Anyone
Copy link
Contributor

this looks pretty cool

@someone2060 someone2060 requested review from a team, JoshuaWu7 and ds570001 and removed request for a team October 28, 2024 21:45
Copy link
Contributor

@williamckha williamckha left a comment

Choose a reason for hiding this comment

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

Awesome work! Looked really good when you tested it out on Saturday.

Comment on lines 57 to 81
if not self.drive_mode == DriveMode.VELOCITY:
motor_control.ClearField("direct_per_wheel_control")
motor_control.direct_velocity_drive.velocity.x_component_meters = (
self.x_velocity_slider.value()
)
motor_control.direct_velocity_drive.velocity.y_component_meters = (
self.y_velocity_slider.value()
)
motor_control.direct_velocity_drive.angular_velocity.radians_per_second = (
self.angular_velocity_slider.value()
)
else:
motor_control.ClearField("direct_velocity_control")
motor_control.direct_per_wheel_drive.front_left_wheel_velocity = (
self.front_left_motor_slider.value()
)
motor_control.direct_per_wheel_drive.front_right_wheel_velocity = (
self.front_right_motor_slider.value()
)
motor_control.direct_per_wheel_drive.back_left_wheel_velocity = (
self.back_left_motor_slider.value()
)
motor_control.direct_per_wheel_drive.back_right_wheel_velocity = (
self.back_right_motor_slider.value()
)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: why structure it this way?

why not if self.drive_mode == DriveMode.MOTOR to avoid that confusing not if you are handling the else case here as well?

so

if self.drive_mode == DriveMode.MOTOR
    ...
else:

Comment on lines 46 to 48
self.drive_mode = DriveMode.VELOCITY
self.use_direct_velocity.setChecked(True)
self.toggle_drive_mode(DriveMode.VELOCITY)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you could replace this with self.use_direct_velocity.click() since it is attached with the QtSignal to toggle_drive_mode

Comment on lines 70 to 81
motor_control.direct_per_wheel_drive.front_left_wheel_velocity = (
self.front_left_motor_slider.value()
)
motor_control.direct_per_wheel_drive.front_right_wheel_velocity = (
self.front_right_motor_slider.value()
)
motor_control.direct_per_wheel_drive.back_left_wheel_velocity = (
self.back_left_motor_slider.value()
)
motor_control.direct_per_wheel_drive.back_right_wheel_velocity = (
self.back_right_motor_slider.value()
)
Copy link
Contributor

Choose a reason for hiding this comment

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

it should be motor_control.direct_per_wheel_control.front_left_wheel_velocity, etc.

Currently, this line errors out when you run it.

Copy link
Contributor

@itsarune itsarune left a comment

Choose a reason for hiding this comment

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

great work! left some feedback for you to munch on.

Comment on lines +397 to +400
def disconnect_dribbler_sliders(self) -> None:
self.dribbler_speed_rpm_slider.valueChanged.disconnect()

def disconnect_motor_sliders(self) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add some function docs

Copy link
Contributor

@itsarune itsarune left a comment

Choose a reason for hiding this comment

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

nice, one more nit from me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement per-motor robot control in Thunderscope
4 participants