Skip to content

Commit

Permalink
Fix python formatting everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
npentrel committed Sep 14, 2023
1 parent 1bb50b9 commit 757c505
Show file tree
Hide file tree
Showing 37 changed files with 761 additions and 454 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
extend-ignore = F704, F821, F401, F841
exclude = .git,build,dist
max-complexity = 20
11 changes: 6 additions & 5 deletions docs/components/arm/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,16 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/_modules
```python {class="line-numbers linkable-line-numbers"}
my_arm = Arm.from_robot(robot=robot, name="my_arm")

# Declare a list of values with your desired rotational value for each joint on the arm.
# Declare a list of values with your desired rotational value for each joint on
# the arm.
degrees = [0.0, 45.0, 0.0, 0.0, 0.0]

# Declare a new JointPositions with these values.
jointPos = arm.move_to_joint_positions(JointPositions(values=[0.0, 45.0, 0.0, 0.0, 0.0]))
jointPos = arm.move_to_joint_positions(
JointPositions(values=[0.0, 45.0, 0.0, 0.0, 0.0]))

# Move each joint of the arm to the position these values specify.
await my_arm.move_to_joint_positions(positions= jointPos)
await my_arm.move_to_joint_positions(positions=jointPos)
```

{{% /tab %}}
Expand Down Expand Up @@ -425,14 +427,13 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
my_arm = Arm.from_robot(robot=robot, name="my_arm")

# Get the kinematics information associated with the arm.
kinematics := await my_arm.get_kinematics()
kinematics = await my_arm.get_kinematics()

# Get the format of the kinematics file.
k_file = kinematics[0]

# Get the byte contents of the file.
k_bytes = kinematics[1]

```

{{% /tab %}}
Expand Down
28 changes: 19 additions & 9 deletions docs/components/base/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,27 @@ my_base = Base.from_robot(robot=robot, name="my_base")

# Make your wheeled base move forward. Set linear power to 75%.
print("move forward")
await my_base.set_power(linear=Vector3(x=0,y=-.75,z=0), angular=Vector3(x=0,y=0,z=0))
await my_base.set_power(
linear=Vector3(x=0, y=-.75, z=0),
angular=Vector3(x=0, y=0, z=0))

# Make your wheeled base move backward. Set linear power to -100%.
print("move backward")
await my_base.set_power(linear=Vector3(x=0,y=-1.0,z=0), angular=Vector3(x=0,y=0,z=0))
await my_base.set_power(
linear=Vector3(x=0, y=-1.0, z=0),
angular=Vector3(x=0, y=0, z=0))

# Make your wheeled base spin left. Set angular power to 100%.
print("spin left")
await my_base.set_power(linear=Vector3(x=0,y=0,z=0), angular=Vector3(x=0,y=0,z=1))
await my_base.set_power(
linear=Vector3(x=0, y=0, z=0),
angular=Vector3(x=0, y=0, z=1))

# Make your wheeled base spin right. Set angular power to -75%.
print("spin right")
await my_base.set_power(linear=Vector3(x=0,y=0,z=0), angular=Vector3(x=0,y=0,z=-.75))
await my_base.set_power(
linear=Vector3(x=0, y=0, z=0),
angular=Vector3(x=0, y=0, z=-.75))
```

{{% /tab %}}
Expand Down Expand Up @@ -309,8 +317,10 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
```python {class="line-numbers linkable-line-numbers"}
my_base = Base.from_robot(robot=robot, name="my_base")

# Set the linear velocity to 50 mm/sec and the angular velocity to 15 degree/sec.
await my_base.set_velocity(linear=Vector3(x=0,y=50,z=0), angular=Vector3(x=0,y=0,z=15))
# Set the linear velocity to 50 mm/sec and the angular velocity to
# 15 degree/sec.
await my_base.set_velocity(
linear=Vector3(x=0, y=50, z=0), angular=Vector3(x=0, y=0, z=15))
```

{{% /tab %}}
Expand Down Expand Up @@ -469,10 +479,10 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
```python {class="line-numbers linkable-line-numbers"}
my_base = Base.from_robot(robot=robot, name="my_base")

# Get the width and turning radius of the base
# Get the width and turning radius of the base
properties = await my_base.get_properties()

# Get the width
# Get the width
print(f"Width of base in meters: {properties.width}")

# Get the turning radius
Expand All @@ -497,7 +507,7 @@ For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/c
```go {class="line-numbers linkable-line-numbers"}
myBase, err := base.FromRobot(robot, "my_base")

// Get the width and turning radius of the base
// Get the width and turning radius of the base
properties, err := myBase.Properties(context.Background(), nil)

// Get the width
Expand Down
38 changes: 25 additions & 13 deletions docs/components/board/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,11 @@ Get an [`DigitalInterrupt`](#digital_interrupts) by `name.`
For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/board/index.html#viam.components.board.Board.digital_interrupt_by_name).

```python
my_board = Board.from_robot(robot=robot, name=)
my_board = Board.from_robot(robot=robot, name="my_board")

# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
interrupt = await my_board.digital_interrupt_by_name(
name="my_example_digital_interrupt")
```

{{% /tab %}}
Expand Down Expand Up @@ -1047,7 +1048,8 @@ my_board = Board.from_robot(robot=robot, name="my_board")
# Get the GPIOPin with pin number 15.
pin = await my_board.GPIO_pin_by_name(name="15")

# Set the duty cycle to .6, meaning that this pin will be in the high state for 60% of the duration of the PWM interval period.
# Set the duty cycle to .6, meaning that this pin will be in the high state for
# 60% of the duration of the PWM interval period.
await pin.set_pwm(cycle=.6)
```

Expand Down Expand Up @@ -1225,9 +1227,11 @@ pin = await my_board.GPIO_pin_by_name(name="15")
duty_cycle = await pin.get_pwm()

# Get the AnalogReader "my_example_analog_reader".
reader = await my_board.analog_reader_by_name(name="my_example_analog_reader")
reader = await my_board.analog_reader_by_name(
name="my_example_analog_reader")

# Get the value of the digital signal "my_example_analog_reader" has most recently measured.
# Get the value of the digital signal "my_example_analog_reader" has most
# recently measured.
reading = reader.read()
```

Expand Down Expand Up @@ -1288,9 +1292,11 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
my_board = Board.from_robot(robot=robot, name="my_board")

# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
interrupt = await my_board.digital_interrupt_by_name(
name="my_example_digital_interrupt")

# Get the amount of times this DigitalInterrupt has been interrupted with a tick.
# Get the amount of times this DigitalInterrupt has been interrupted with a
# tick.
count = await interrupt.value()
```

Expand Down Expand Up @@ -1341,9 +1347,11 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
my_board = Board.from_robot(robot=robot, name="my_board")

# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
interrupt = await my_board.digital_interrupt_by_name(
name="my_example_digital_interrupt")

# Get the rolling average of the pulse width across each time the DigitalInterrupt is interrupted with a tick.
# Get the rolling average of the pulse width across each time the
# DigitalInterrupt is interrupted with a tick.
rolling_avg = await interrupt.value()
```

Expand Down Expand Up @@ -1407,7 +1415,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
my_board = Board.from_robot(robot=robot, name="my_board")
# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
interrupt = await my_board.digital_interrupt_by_name(
name="my_example_digital_interrupt")
# Record an interrupt and notify any interested callbacks.
await interrupt.tick(high=true, nanos=12345)
Expand All @@ -1431,7 +1440,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
my_board = Board.from_robot(robot=robot, name="my_board")
# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
interrupt = await my_board.digital_interrupt_by_name(
name="my_example_digital_interrupt")
# Record an interrupt and notify any interested callbacks.
await interrupt.tick(high=true, nanos=12345)
Expand Down Expand Up @@ -1524,7 +1534,8 @@ pin = await my_board.GPIO_pin_by_name(name="15")
callback_queue = Queue(maxsize=10)
# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
interrupt = await my_board.digital_interrupt_by_name(
name="my_example_digital_interrupt")
# Add a queue to the interrupt.
interrupt.add_callback(callback_queue)
Expand Down Expand Up @@ -1618,7 +1629,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
my_board = Board.from_robot(robot=robot, name="my_board")
# Get the DigitalInterrupt "my_example_digital_interrupt".
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
interrupt = await my_board.digital_interrupt_by_name(
name="my_example_digital_interrupt")
```
``` -->

Expand Down
8 changes: 4 additions & 4 deletions docs/components/camera/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ frame = await my_cam.get_image()

# Convert "frame" to a standard 2D image representation.
# Remove the 1st 3x8 bytes and reshape the raw bytes to List[List[Int]].
standard_frame frame.bytes_to_depth_array()
standard_frame = frame.bytes_to_depth_array()
```

{{% alert title="Tip" color="tip" %}}
Expand Down Expand Up @@ -253,7 +253,7 @@ To deserialize the returned information into a numpy array, use the Open3D libra
import numpy as np
import open3d as o3d

my_camera= Camera.from_robot(robot=robot, name="my_camera")
my_camera = Camera.from_robot(robot=robot, name="my_camera")

data, _ = await my_camera.get_point_cloud()

Expand Down Expand Up @@ -306,7 +306,7 @@ Get the camera intrinsic parameters and camera distortion, as well as whether th
- [(Properties)](https://python.viam.dev/autoapi/viam/components/camera/index.html#viam.components.camera.Camera.Properties): The properties of the camera.

```python {class="line-numbers linkable-line-numbers"}
my_camera= Camera.from_robot(robot=robot, name="my_camera")
my_camera = Camera.from_robot(robot=robot, name="my_camera")

properties = await my_camera.get_properties()
```
Expand Down Expand Up @@ -356,7 +356,7 @@ If you are implementing your own camera and adding features that have no native
- [(Dict[str, Any])](https://docs.python.org/3/library/stdtypes.html#typesmapping): Result of the executed command.

```python {class="line-numbers linkable-line-numbers"}
my_camera= Camera.from_robot(robot, "my_camera")
my_camera = Camera.from_robot(robot, "my_camera")

command = {"cmd": "test", "data1": 500}
result = my_camera.do(command)
Expand Down
12 changes: 8 additions & 4 deletions docs/components/gantry/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/_modules
```python
my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")

# Create a list of positions for the axes of the gantry to move to. Assume in this example that the gantry is multi-axis, with 3 axes.
# Create a list of positions for the axes of the gantry to move to. Assume in
# this example that the gantry is multi-axis, with 3 axes.
examplePositions = [1, 2, 3]

exampleSpeeds = [3, 9, 12]

# Move the axes of the gantry to the positions specified.
await my_gantry.move_to_position(positions=examplePositions, speeds=exampleSpeeds)
await my_gantry.move_to_position(
positions=examplePositions, speeds=exampleSpeeds)
```

{{% /tab %}}
Expand Down Expand Up @@ -315,7 +317,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/_modules
```python
my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")

# Stop all motion of the gantry. It is assumed that the gantry stops immediately.
# Stop all motion of the gantry. It is assumed that the gantry stops
# immediately.
await my_gantry.stop()
```

Expand Down Expand Up @@ -363,7 +366,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/_modules
```python
my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")

# Stop all motion of the gantry. It is assumed that the gantry stops immediately.
# Stop all motion of the gantry. It is assumed that the gantry stops
# immediately.
await my_gantry.stop()

# Print if the gantry is currently moving.
Expand Down
34 changes: 23 additions & 11 deletions docs/components/input-controller/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,31 +112,38 @@ Doing so registers the same callback to both `ButtonPress` and `ButtonRelease`,
For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/input/index.html#viam.components.input.Controller.register_control_callback).

```python {class="line-numbers linkable-line-numbers"}
# Define a function to handle pressing the Start Menu Button "BUTTON_START" on your controller, printing out the start time.
# Define a function to handle pressing the Start Menu Button "BUTTON_START" on
# your controller, printing out the start time.
def print_start_time(event):
print(f"Start Menu Button was pressed at this time:\n{event.time}")


# Define a function that handles the controller.
async def handle_controller(controller):

# Get the list of Controls on the controller.
controls = await controller.get_controls()

# If the "BUTTON_START" Control is found, register the function print_start_time to fire when "BUTTON_START" has the event "ButtonPress" occur.
# If the "BUTTON_START" Control is found, register the function
# print_start_time to fire when "BUTTON_START" has the event "ButtonPress"
# occur.
if Control.BUTTON_START in controls:
controller.register_control_callback(Control.BUTTON_START, [EventType.BUTTON_PRESS], print_start_time)
controller.register_control_callback(
Control.BUTTON_START, [EventType.BUTTON_PRESS], print_start_time)
else:
print("Oops! Couldn't find the start button control! Is your controller connected?")
print("Oops! Couldn't find the start button control! Is your "
"controller connected?")
exit()

while True:
await asyncio.sleep(1.0)


async def main():
# ... < INSERT CONNECTION CODE FROM ROBOT'S CODE SAMPLE TAB >

# Get your controller from the robot.
my_controller = Controller.from_robot(robot=myRobotWithController, name="my_controller")
my_controller = Controller.from_robot(
robot=myRobotWithController, name="my_controller")

# Run the handleController function.
await handleController(my_controller)
Expand Down Expand Up @@ -236,7 +243,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/_modules

```python {class="line-numbers linkable-line-numbers"}
# Get the controller from the robot.
my_controller = Controller.from_robot(robot=myRobotWithController, name="my_controller")
my_controller = Controller.from_robot(
robot=myRobotWithController, name="my_controller")

# Get the most recent Event for each Control.
recent_events = await my_controller.get_events()
Expand Down Expand Up @@ -294,7 +302,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/_modules

```python {class="line-numbers linkable-line-numbers"}
# Get the controller from the robot.
my_controller = Controller.from_robot(robot=myRobotWithController, name="my_controller")
my_controller = Controller.from_robot(
robot=myRobotWithController, name="my_controller")

# Get the list of Controls provided by the controller.
controls = await my_controller.get_controls()
Expand Down Expand Up @@ -357,9 +366,11 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/_modules
```python {class="line-numbers linkable-line-numbers"}
# Define a "Button is Pressed" event for the control BUTTON_START.
button_is_pressed_event = Event(time(), EventType.BUTTON_PRESS, Control.BUTTON_START, 1.0)
button_is_pressed_event = Event(
time(), EventType.BUTTON_PRESS, Control.BUTTON_START, 1.0)
# Trigger the event on your controller. Set this trigger to timeout if it has not completed in 7 seconds.
# Trigger the event on your controller. Set this trigger to timeout if it has
# not completed in 7 seconds.
await myController.trigger_event(event=my_event, timeout=7.0)
```
Expand Down Expand Up @@ -414,7 +425,8 @@ If you are implementing your own input controller and add features that have no

```python {class="line-numbers linkable-line-numbers"}
# Get the controller from the robot.
my_controller = Controller.from_robot(robot=myRobotWithController, name="my_controller")
my_controller = Controller.from_robot(
robot=myRobotWithController, name="my_controller")

command = {"cmd": "test", "data1": 500}
result = my_controller.do(command)
Expand Down
5 changes: 3 additions & 2 deletions docs/components/motor/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
my_motor = Motor.from_robot(robot=robot, name="my_motor")

# Set the power to 40% forwards.
await my_motor.set_power(power = 0.4)
await my_motor.set_power(power=0.4)
```

{{% /tab %}}
Expand Down Expand Up @@ -370,7 +370,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
```python
my_motor = Motor.from_robot(robot=robot, name="my_motor")

# Report a dictionary mapping optional properties to whether it is supported by this motor.
# Report a dictionary mapping optional properties to whether it is supported by
# this motor.
properties = await my_motor.get_properties()

# Print out the properties.
Expand Down
Loading

0 comments on commit 757c505

Please sign in to comment.