Skip to content

Add on_to_position(), on_for_XYZ accept additional speed inputs - #407

Merged
dwalton76 merged 6 commits into
ev3dev:developfrom
dwalton76:motor-speed-pct-conversions
Oct 11, 2017
Merged

dwalton76 merged 6 commits into
ev3dev:developfrom
dwalton76:motor-speed-pct-conversions

Conversation

@dwalton76

Copy link
Copy Markdown
Collaborator

No description provided.

@dwalton76

Copy link
Copy Markdown
Collaborator Author

Implements the idea floated in #406

@dwalton76

Copy link
Copy Markdown
Collaborator Author

Will fix fake-sys to have max_speed

Comment thread ev3dev/motor.py Outdated
return ("%d dps" % self)

def get_speed_pct(self, motor):
return motor.dps_to_speed(self)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't it seem a bit odd that we convert degrees-per-second into percentage of max speed just to convert it back? I think this is one of those cases where we should choose the native unit and base everything on that -- degrees per second are the reasonable "scientific" units whereas the percentage isn't.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

A little...but the fact that we set the motor speed in terms of dps and EV3-G uses percentages means there is going to be some funkyness. I can live with converting this one and then later having it converted back, since it means we treat all of these SpeedInteger classes consistently.

Comment thread ev3dev/motor.py
Speed in rotations-per-second
"""

def __str__(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

Comment thread ev3dev/motor.py Outdated
"""
Return the motor speed percentage to achieve rps (rotations-per-second)
"""
assert abs(rps) <= self._max_rps, "%s maximum rotations-per-second is %s, %s was requested" % (self, self._max_rps, rps)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you think about moving these conversions into the individual unit classes (or somewhere else)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

sounds good...I am going to change Motor._max_rps to Motor.max_rps though since SpeedRPS will be accessing it to do the conversion

Comment thread ev3dev/motor.py Outdated
"""
Return the motor speed percentage to achieve desired rotations-per-second
"""
return float(self/motor.max_rps) * 100

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Side-note: does this actually require the float conversion? As of Python 3 it'll do floating-point division anyway.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I still do this out of python2 habit...will drop the float call

@WasabiFan WasabiFan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me! Last thing: docs on the methods that accept the new speed values?

@dwalton76
dwalton76 merged commit d505bb8 into ev3dev:develop Oct 11, 2017
@dwalton76
dwalton76 deleted the motor-speed-pct-conversions branch October 12, 2017 23:13
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.

2 participants