Viam C++ SDK current
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
viam::sdk::Motor Class Referenceabstract

A Motor represents physical hardware that controls the rotation of an axle. More...

#include "components/motor.hpp"

+ Inheritance diagram for viam::sdk::Motor:

Classes

struct  power_status
 Information about power-state of the motor. More...
 
struct  properties
 Features that the specific motor supports. More...
 

Public Types

typedef double position
 

Public Member Functions

void set_power (double power_pct)
 Sets the percentage of the motor's total power that should be employed.
 
virtual void set_power (double power_pct, const ProtoStruct &extra)=0
 Sets the percentage of the motor's total power that should be employed.
 
void go_for (double rpm, double revolutions)
 Instructs the motor to turn at a specified speed, which is expressed in RPM, for a specified number of rotations relative to its starting position.
 
virtual void go_for (double rpm, double revolutions, const ProtoStruct &extra)=0
 Instructs the motor to turn at a specified speed, which is expressed in RPM, for a specified number of rotations relative to its starting position.
 
void go_to (double rpm, double position_revolutions)
 Move the motor to a specific position that is relative to its home position at a specified speed which is expressed in RPM.
 
virtual void go_to (double rpm, double position_revolutions, const ProtoStruct &extra)=0
 Move the motor to a specific position that is relative to its home position at a specified speed which is expressed in RPM.
 
void set_rpm (double rpm)
 Move the motor indefinitely at a specified speed which is expressed in RPM.
 
virtual void set_rpm (double rpm, const ProtoStruct &extra)=0
 Move the motor indefinitely at a specified speed which is expressed in RPM.
 
void reset_zero_position (double offset)
 Sets the current position of the motor as the new zero position.
 
virtual void reset_zero_position (double offset, const ProtoStruct &extra)=0
 Sets the current position of the motor as the new zero position.
 
position get_position ()
 Reports the position of the robot's motor relative to its zero position.
 
virtual position get_position (const ProtoStruct &extra)=0
 Reports the position of the robot's motor relative to its zero position.
 
properties get_properties ()
 Returns the properties of the motor which comprises the booleans indicating which optional features the robot's motor supports.
 
virtual properties get_properties (const ProtoStruct &extra)=0
 Returns the properties of the motor which comprises the booleans indicating.
 
power_status get_power_status ()
 
virtual power_status get_power_status (const ProtoStruct &extra)=0
 
virtual bool is_moving ()=0
 Reports if a component is in motion.
 
virtual ProtoStruct do_command (const ProtoStruct &command)=0
 Send/receive arbitrary commands to the resource.
 
std::vector< GeometryConfigget_geometries ()
 Returns GeometryConfigs associated with the calling motor.
 
virtual std::vector< GeometryConfigget_geometries (const ProtoStruct &extra)=0
 Returns GeometryConfigs associated with the calling motor.
 
API api () const override
 Returns the API associated with a particular resource.
 
- Public Member Functions inherited from viam::sdk::Component
viam::common::v1::ResourceName get_resource_name (std::string name) const override
 Returns a ResourceName for a particular resource name.
 
- Public Member Functions inherited from viam::sdk::Resource
 Resource (std::string name)
 
virtual std::string name () const
 Return the resource's name.
 
- Public Member Functions inherited from viam::sdk::Stoppable
virtual void stop (const ProtoStruct &extra)=0
 Stops a resource from running.
 
void stop ()
 Stops a resource from running.
 

Static Public Member Functions

static position from_proto (const viam::component::motor::v1::GetPositionResponse &proto)
 Creates a position struct from its proto representation.
 
static power_status from_proto (const viam::component::motor::v1::IsPoweredResponse &proto)
 Creates a power_status struct from its proto representation.
 
static properties from_proto (const viam::component::motor::v1::GetPropertiesResponse &proto)
 Creates a properties struct from its proto representation.
 
static viam::component::motor::v1::GetPositionResponse to_proto (const position &position)
 Converts a position struct to its proto representation.
 
static viam::component::motor::v1::IsPoweredResponse to_proto (const power_status &power_status)
 Converts a power_status struct to its proto representation.
 
static viam::component::motor::v1::GetPropertiesResponse to_proto (const properties &properties)
 Converts a properties struct to its proto representation.
 
- Static Public Member Functions inherited from viam::sdk::Stoppable
static void stop_if_stoppable (const std::shared_ptr< Resource > &resource, const ProtoStruct &extra)
 Stops a Resource if it is Stoppable.
 
static void stop_if_stoppable (const std::shared_ptr< Resource > &resource)
 Stops a Resource if it is Stoppable.
 

Protected Member Functions

 Motor (std::string name)
 
- Protected Member Functions inherited from viam::sdk::Component
 Component (std::string name)
 

Detailed Description

A Motor represents physical hardware that controls the rotation of an axle.

This acts as an abstract base class to be inherited from by any drivers representing specific motor implementations. This class cannot be used on its own.

Member Function Documentation

◆ api()

API viam::sdk::Motor::api ( ) const
overridevirtual

Returns the API associated with a particular resource.

Implements viam::sdk::Resource.

◆ do_command()

virtual ProtoStruct viam::sdk::Motor::do_command ( const ProtoStruct & command)
pure virtual

Send/receive arbitrary commands to the resource.

Parameters
Commandthe command to execute.
Returns
The result of the executed command.

Implemented in viam::sdk::impl::MotorClient.

◆ get_geometries() [1/2]

std::vector< GeometryConfig > viam::sdk::Motor::get_geometries ( )
inline

Returns GeometryConfigs associated with the calling motor.

Returns
The requested GeometryConfigs associated with the component.

◆ get_geometries() [2/2]

virtual std::vector< GeometryConfig > viam::sdk::Motor::get_geometries ( const ProtoStruct & extra)
pure virtual

Returns GeometryConfigs associated with the calling motor.

Parameters
extraAny additional arguments to the method.
Returns
The requested GeometryConfigs associated with the component.

Implemented in viam::sdk::impl::MotorClient, and viam::sdk::impl::MotorClient.

◆ get_position() [1/2]

position viam::sdk::Motor::get_position ( )
inline

Reports the position of the robot's motor relative to its zero position.

Exceptions
`Exception`if position reporting is not supported

◆ get_position() [2/2]

virtual position viam::sdk::Motor::get_position ( const ProtoStruct & extra)
pure virtual

Reports the position of the robot's motor relative to its zero position.

Parameters
extraAny additional arguments to the method
Exceptions
`Exception`if position reporting is not supported

Implemented in viam::sdk::impl::MotorClient, and viam::sdk::impl::MotorClient.

◆ get_power_status() [1/2]

power_status viam::sdk::Motor::get_power_status ( )
inline
Returns
The motor's current power_status

◆ get_power_status() [2/2]

virtual power_status viam::sdk::Motor::get_power_status ( const ProtoStruct & extra)
pure virtual
Returns
The motor's current power_status
Parameters
extraAny additional arguments to the method

Implemented in viam::sdk::impl::MotorClient, and viam::sdk::impl::MotorClient.

◆ get_properties()

virtual properties viam::sdk::Motor::get_properties ( const ProtoStruct & extra)
pure virtual

Returns the properties of the motor which comprises the booleans indicating.

Parameters
extraAny additional arguments to the method which optional features the robot's motor supports

Implemented in viam::sdk::impl::MotorClient, and viam::sdk::impl::MotorClient.

◆ go_for() [1/2]

void viam::sdk::Motor::go_for ( double rpm,
double revolutions )
inline

Instructs the motor to turn at a specified speed, which is expressed in RPM, for a specified number of rotations relative to its starting position.

Parameters
rpmSpeed of motor travel in rotations per minute
revolutionsNumber of revolutions relative to motor's start position. If revolutions == 0, this will run the motor at rpm indefinetely. If revolutions != 0, this will block until the number of revolutions has been completed or another operation comes in.
Exceptions
`Exception`if position reporting is not supported

◆ go_for() [2/2]

virtual void viam::sdk::Motor::go_for ( double rpm,
double revolutions,
const ProtoStruct & extra )
pure virtual

Instructs the motor to turn at a specified speed, which is expressed in RPM, for a specified number of rotations relative to its starting position.

Parameters
rpmSpeed of motor travel in rotations per minute
revolutionsNumber of revolutions relative to motor's start position. If revolutions == 0, this will run the motor at rpm indefinetely. If revolutions != 0, this will block until the number of revolutions has been completed or another operation comes in.
extraAny additional arguments to the method.
Exceptions
`Exception`if position reporting is not supported

Implemented in viam::sdk::impl::MotorClient, and viam::sdk::impl::MotorClient.

◆ go_to() [1/2]

void viam::sdk::Motor::go_to ( double rpm,
double position_revolutions )
inline

Move the motor to a specific position that is relative to its home position at a specified speed which is expressed in RPM.

Parameters
rpmSpeed of motor travel in rotations per minute
position_revolutionsNumber of revolutions relative to motor's home home/zero
Exceptions
`Exception`if position reporting is not supported

◆ go_to() [2/2]

virtual void viam::sdk::Motor::go_to ( double rpm,
double position_revolutions,
const ProtoStruct & extra )
pure virtual

Move the motor to a specific position that is relative to its home position at a specified speed which is expressed in RPM.

Parameters
rpmSpeed of motor travel in rotations per minute
position_revolutionsNumber of revolutions relative to motor's home home/zero
extraAny additional arguments to the method.
Exceptions
`Exception`if position reporting is not supported

Implemented in viam::sdk::impl::MotorClient, and viam::sdk::impl::MotorClient.

◆ is_moving()

virtual bool viam::sdk::Motor::is_moving ( )
pure virtual

Reports if a component is in motion.

Implemented in viam::sdk::impl::MotorClient.

◆ reset_zero_position() [1/2]

void viam::sdk::Motor::reset_zero_position ( double offset)
inline

Sets the current position of the motor as the new zero position.

Parameters
offsetMotor position
Exceptions
`Exception`if position reporting is not supported

◆ reset_zero_position() [2/2]

virtual void viam::sdk::Motor::reset_zero_position ( double offset,
const ProtoStruct & extra )
pure virtual

Sets the current position of the motor as the new zero position.

Parameters
offsetMotor position
extraAny additional arguments to the method
Exceptions
`Exception`if position reporting is not supported

Implemented in viam::sdk::impl::MotorClient, and viam::sdk::impl::MotorClient.

◆ set_power() [1/2]

void viam::sdk::Motor::set_power ( double power_pct)
inline

Sets the percentage of the motor's total power that should be employed.

Parameters
power_pctPercentage of motor's power, between -1 and 1, where negative values indicate a backwards direction and positive values, a forward direction.

◆ set_power() [2/2]

virtual void viam::sdk::Motor::set_power ( double power_pct,
const ProtoStruct & extra )
pure virtual

Sets the percentage of the motor's total power that should be employed.

Parameters
power_pctPercentage of motor's power, between -1 and 1, where negative values indicate a backwards direction and positive values, a forward direction.
extraAny additional arguments to the method.

Implemented in viam::sdk::impl::MotorClient, and viam::sdk::impl::MotorClient.

◆ set_rpm() [1/2]

void viam::sdk::Motor::set_rpm ( double rpm)
inline

Move the motor indefinitely at a specified speed which is expressed in RPM.

Parameters
rpmSpeed of motor travel in rotations per minute
Exceptions
`Exception`if position reporting is not supported

◆ set_rpm() [2/2]

virtual void viam::sdk::Motor::set_rpm ( double rpm,
const ProtoStruct & extra )
pure virtual

Move the motor indefinitely at a specified speed which is expressed in RPM.

Parameters
rpmSpeed of motor travel in rotations per minute
extraAny additional arguments to the method.
Exceptions
`Exception`if position reporting is not supported

Implemented in viam::sdk::impl::MotorClient, and viam::sdk::impl::MotorClient.


The documentation for this class was generated from the following file: