viam.components.base.client
Classes
gRPC client for the Base component. |
Module Contents
- class viam.components.base.client.BaseClient(name: str, channel: grpclib.client.Channel)[source]
Bases:
viam.components.base.Base
,viam.resource.rpc_client_base.ReconfigurableResourceRPCClientBase
gRPC client for the Base component.
- channel
- client
- async move_straight(distance: int, velocity: float, *, extra: Dict[str, Any] | None = None, timeout: float | None = None, **kwargs)[source]
Move the base in a straight line the given
distance
, expressed in millimeters, at the givenvelocity
, expressed in millimeters per second. Whendistance
orvelocity
is 0, the base will stop. This method blocks until completed or cancelled.my_base = Base.from_robot(robot=machine, name="my_base") # Move the base 40 mm at a velocity of 90 mm/s, forward. await my_base.move_straight(distance=40, velocity=90) # Move the base 40 mm at a velocity of -90 mm/s, backward. await my_base.move_straight(distance=40, velocity=-90)
- Parameters:
distance (int) – The distance (in millimeters) to move. Negative implies backwards.
velocity (float) – The velocity (in millimeters per second) to move. Negative implies backwards.
For more information, see Base component.
- async spin(angle: float, velocity: float, *, extra: Dict[str, Any] | None = None, timeout: float | None = None, **kwargs)[source]
Spin the base in place
angle
degrees, at the given angularvelocity
, expressed in degrees per second. Whenvelocity
is 0, the base will stop. This method blocks until completed or cancelled.my_base = Base.from_robot(robot=machine, name="my_base") # Spin the base 10 degrees at an angular velocity of 15 deg/sec. await my_base.spin(angle=10, velocity=15)
- Parameters:
angle (float) – The angle (in degrees) to spin.
velocity (float) – The angular velocity (in degrees per second) to spin. Given a positive angle and a positive velocity, the base will turn to the left.
For more information, see Base component.
- async set_power(linear: viam.components.base.Vector3, angular: viam.components.base.Vector3, *, extra: Dict[str, Any] | None = None, timeout: float | None = None, **kwargs)[source]
Set the linear and angular velocity of the Base When
linear
is 0, the base will spin. Whenangular
is 0, the base will move in a straight line. When bothlinear
andangular
are 0, the base will stop. Whenlinear
andangular
are both nonzero, the base will move in an arc, with a tighter radius if angular power is greater than linear power.my_base = Base.from_robot(robot=machine, 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)) # 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)) # 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)) # 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))
- Parameters:
For more information, see Base component.
- async set_velocity(linear: viam.components.base.Vector3, angular: viam.components.base.Vector3, *, extra: Dict[str, Any] | None = None, timeout: float | None = None, **kwargs)[source]
Set the linear and angular velocities of the base.
my_base = Base.from_robot(robot=machine, 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))
For more information, see Base component.
- async stop(*, extra: Dict[str, Any] | None = None, timeout: float | None = None, **kwargs)[source]
Stop the base.
my_base = Base.from_robot(robot=machine, name="my_base") # Move the base forward 10 mm at a velocity of 50 mm/s. await my_base.move_straight(distance=10, velocity=50) # Stop the base. await my_base.stop()
For more information, see Base component.
- async is_moving(*, timeout: float | None = None, **kwargs) bool [source]
Get if the base is currently moving.
my_base = Base.from_robot(robot=machine, name="my_base") # Check whether the base is currently moving. moving = await my_base.is_moving() print('Moving: ', moving)
- Returns:
Whether the base is moving.
- Return type:
bool
For more information, see Base component.
- async get_properties(*, extra: Dict[str, Any] | None = None, timeout: float | None = None, **kwargs) viam.components.base.Base.Properties [source]
Get the base width and turning radius
my_base = Base.from_robot(robot=machine, name="my_base") # Get the width and turning radius of the base properties = await my_base.get_properties() # Get the width print(f"Width of base: {properties.width_meters}") # Get the turning radius print(f"Turning radius of base: {properties.turning_radius_meters}") # Get the wheel circumference print(f"Wheel circumference of base: {properties.wheel_circumference_meters}")
- Returns:
The properties of the base
- Return type:
For more information, see Base component.
- async do_command(command: Mapping[str, viam.utils.ValueTypes], *, timeout: float | None = None, **kwargs) Mapping[str, viam.utils.ValueTypes] [source]
Send/Receive arbitrary commands to the Resource
command = {"cmd": "test", "data1": 500} result = await component.do_command(command)
- Parameters:
command (Mapping[str, ValueTypes]) – The command to execute
- Raises:
NotImplementedError – Raised if the Resource does not support arbitrary commands
- Returns:
Result of the executed command
- Return type:
Mapping[str, ValueTypes]
- async get_geometries(*, extra: Dict[str, Any] | None = None, timeout: float | None = None, **kwargs) List[viam.proto.common.Geometry] [source]
Get all geometries associated with the component, in their current configuration, in the frame of the component.
geometries = await component.get_geometries() if geometries: # Get the center of the first geometry print(f"Pose of the first geometry's centerpoint: {geometries[0].center}")
- Returns:
The geometries associated with the Component.
- Return type:
List[Geometry]
- classmethod from_robot(robot: viam.robot.client.RobotClient, name: str) typing_extensions.Self
Get the component named
name
from the provided robot.- Parameters:
robot (RobotClient) – The robot
name (str) – The name of the component
- Returns:
The component, if it exists on the robot
- Return type:
Self
- classmethod get_resource_name(name: str) viam.proto.common.ResourceName
Get the ResourceName for this Resource with the given name
# Can be used with any resource, using an arm as an example my_arm_name = Arm.get_resource_name("my_arm")
- Parameters:
name (str) – The name of the Resource
- Returns:
The ResourceName of this Resource
- Return type:
- get_operation(kwargs: Mapping[str, Any]) viam.operations.Operation
Get the
Operation
associated with the currently running function.When writing custom resources, you should get the
Operation
by calling this function and check to see if it’s cancelled. If theOperation
is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc. ).- Parameters:
kwargs (Mapping[str, Any]) – The kwargs object containing the operation
- Returns:
The operation associated with this function
- Return type:
- async close()
Safely shut down the resource and prevent further use.
Close must be idempotent. Later configuration may allow a resource to be “open” again. If a resource does not want or need a close function, it is assumed that the resource does not need to return errors when future non-Close methods are called.
await component.close()