Open-STEM / XRP_MicroPython

The main programming tool for use with your Experiential Robotics Platform (XRP) Robots!
https://open-stem.github.io/XRP_MicroPython/
10 stars 2 forks source link

Drivetrain.straight indefinitely #20

Closed milespearlman closed 1 year ago

milespearlman commented 1 year ago

Noting that performing drivetrain.set_effort with the same effort in each wheel doesn't actually effectively go straight, it's more effective to use the drivetrain.straight function which isn't always ideal since it takes in a set distance. In the sample code below, replacing the set_effort function with the straight function would cause the robot to not drive smoothly because of the sleep function afterwards. If it's possible to implement the straight function with it going indefinitely rather than a set distance, it could be useful.

image

camearle20 commented 1 year ago

I think based on what we are trying to do with the curriculum there are really 3 new methods of interest in drivetrain:

Do these changes make sense? Having these three available would make a lot of the lessons easier to write.

camearle20 commented 1 year ago

It also may be worth having a default speed (maybe 50% of max speed) for all of these for true beginners to get started with. Doing that would really simplify the amount of code needed to just get the robot moving

ksiegall commented 1 year ago

I've just pushed a change related to this so i will note a few things here:

camearle20 commented 1 year ago

I agree that the new functions would be functionally redundant if ‘set_speed’ exists, but I’m thinking of this more from an intuitive standpoint. In the curriculum we don’t introduce the concept of wheels going different speeds until over halfway through, so it would be nice from a beginners perspective to have a simpler method which just goes a speed.

camearle20 commented 1 year ago

Also, is there a reason that the straight and turn functions can’t use the actual speed controllers in the EncodedMotor? Just curious here, I don’t think it matters either way if you nest those control loops or not.

ksiegall commented 1 year ago

For straight and turn, just setting a speed for a time isn't precise; You're much better off using a controller and P-controlling your way to the target.

To clarify your previous point, if we already have them doing drivetrain.set_effort(1,1) to try to go straight, how is drivetrain.set_speed(10,10) any different?

When making an older version of the DifferentialDrive class, we discussed the possibility of allowing you to pass in only 1 value into set_effort to set both motors, but we had eventually decided against it because it meant there would be a loss in clarity when explaining why it doesn't go perfectly straight. I think it is much more explicit to explain that you set the speeds for the left and right sides separately, but that's my personal bias

camearle20 commented 1 year ago

Makes sense. I have no strong opinions either way, so I’ll just work this into the lessons. Thanks for adding set_speed though!