Skip to content

Commit 0480723

Browse files
committed
Method name refactor
1 parent 7f2a1b3 commit 0480723

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

SampleCode/sample_drive_methods.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,35 @@ def circle():
3737
# Follow the perimeter of a square with variable sidelength
3838
def square(sidelength):
3939
for sides in range(4):
40-
drivetrain.go_straight(sidelength)
41-
drivetrain.go_turn(90)
40+
drivetrain.straight(sidelength)
41+
drivetrain.turn(90)
4242
# Alternatively:
4343
# polygon(sidelength, 4)
4444

4545
# Follow the perimeter of an arbitrary polygon with variable side length and number of sides
4646
# Side length in centimeters
4747
def polygon(side_length, number_of_sides):
4848
for s in range(number_of_sides):
49-
drivetrain.go_straight(side_length)
50-
drivetrain.go_turn(360/number_of_sides)
49+
drivetrain.straight(side_length)
50+
drivetrain.turn(360/number_of_sides)
5151

5252
# A slightly longer example program showing how a robot may follow a simple path
5353
def test_drive():
5454
# Drive forward cm
55-
drivetrain.go_straight(25, 0.8)
55+
drivetrain.straight(25, 0.8)
5656

5757
time.sleep(1)
5858

5959
# turn 90 degrees clockwise
60-
drivetrain.go_turn(90,0.8)
60+
drivetrain.turn(90,0.8)
6161

6262
time.sleep(1)
6363

6464
# turn 90 degrees counter clockwise by setting speed negative
65-
drivetrain.go_turn(90, -0.8)
65+
drivetrain.turn(90, -0.8)
6666

6767
time.sleep(1)
6868

6969
# drive backwards 25 cm by setting distance negative.
7070
# There is no difference between setting speed or distance negative, both work
71-
drivetrain.go_straight(-25,0.8)
71+
drivetrain.straight(-25,0.8)

SampleCode/sample_sensor_access.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def line_track():
5050
base_effort = 0.6
5151
KP = 0.6
5252
while True:
53-
error = reflectance.get_left_reflectance() - reflectance.get_right_reflectance()
53+
error = reflectance.get_left() - reflectance.get_right()
5454
print(error)
5555
drivetrain.set_effort(base_effort - error * KP, base_effort + error * KP)
5656
time.sleep(0.01)

WPILib/_analog_reflectance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def _get_value(self, sensor: AnalogIn) -> float:
1616
return sensor.value / MAX_ANALOG_VALUE
1717

1818
# Implements AbstractReflectance
19-
def get_left_reflectance(self) -> float:
19+
def get_left(self) -> float:
2020
"""
2121
Gets the the reflectance of the left reflectance sensor
2222
:return: The reflectance ranging from 0 (white) to 1 (black)
@@ -25,7 +25,7 @@ def get_left_reflectance(self) -> float:
2525
return self._get_value(self._leftReflectance)
2626

2727
# Implements AbstractReflectance
28-
def get_right_reflectance(self) -> float:
28+
def get_right(self) -> float:
2929
"""
3030
Gets the the reflectance of the right reflectance sensor
3131
:return: The reflectance ranging from 0 (white) to 1 (black)

WPILib/_drivetrain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def set_legacy_mode(self, is_legacy: bool = True):
7474

7575
# Go forward the specified distance in centimeters, and exit function when distance has been reached.
7676
# Speed is bounded from -1 (reverse at full speed) to 1 (forward at full speed)
77-
def go_straight(self, distance: float, speed: float = 0.5, timeout: float = None) -> bool:
77+
def straight(self, distance: float, speed: float = 0.5, timeout: float = None) -> bool:
7878
"""
7979
Go forward the specified distance in centimeters, and exit function when distance has been reached.
8080
Speed is bounded from -1 (reverse at full speed) to 1 (forward at full speed)
@@ -124,7 +124,7 @@ def go_straight(self, distance: float, speed: float = 0.5, timeout: float = None
124124
else:
125125
return time.time() < startTime+timeout
126126

127-
def go_turn(self, turn_degrees: float, speed: float = 0.5, timeout: float = None) -> bool:
127+
def turn(self, turn_degrees: float, speed: float = 0.5, timeout: float = None) -> bool:
128128
"""
129129
Turn the robot some relative heading given in turnDegrees, and exit function when the robot has reached that heading.
130130
Speed is bounded from -1 (turn counterclockwise the relative heading at full speed) to 1 (turn clockwise the relative heading at full speed)

WPILib/_grove_reflectance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, leftPin, rightPin):
1212
self._rightReflectance = _grove_ultrasonic.GroveUltrasonic(rightPin, timeout = 1)
1313

1414
# Implements AbstractReflectance
15-
def get_left_reflectance(self) -> float:
15+
def get_left(self) -> float:
1616
"""
1717
Gets the the reflectance of the left reflectance sensor
1818
:return: The reflectance ranging from 0 (white) to 1 (black)
@@ -21,7 +21,7 @@ def get_left_reflectance(self) -> float:
2121
return self._leftReflectance.get_distance()
2222

2323
# Implements AbstractReflectance
24-
def get_right_reflectance(self) -> float:
24+
def get_right(self) -> float:
2525
"""
2626
Gets the the reflectance of the right reflectance sensor
2727
:return: The reflectance ranging from 0 (white) to 1 (black)

WPILib/_reflectance_wrapper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ def _possibly_instantiate_object(self):
3636
self._reflectanceObject = _analog_reflectance.AnalogReflectance(board.GP27, board.GP26)
3737

3838

39-
def get_left_reflectance(self) -> float:
39+
def get_left(self) -> float:
4040
"""
4141
Gets the the reflectance of the left reflectance sensor
4242
:return: The reflectance ranging from 0 (white) to 1 (black)
4343
:rtype: float
4444
"""
4545
self._possibly_instantiate_object()
46-
return self._reflectanceObject.get_left_reflectance()
46+
return self._reflectanceObject.get_left()
4747

4848

49-
def get_right_reflectance(self) -> float:
49+
def get_right(self) -> float:
5050
"""
5151
Gets the the reflectance of the right reflectance sensor
5252
:return: The reflectance ranging from 0 (white) to 1 (black)
5353
:rtype: float
5454
"""
5555
self._possibly_instantiate_object()
56-
return self._reflectanceObject.get_right_reflectance()
56+
return self._reflectanceObject.get_right()

0 commit comments

Comments
 (0)