Servo
Create connection to servo motor
Add-On Required: This feature requires the MATLAB Support Package for Raspberry Pi Hardware add-on.
Description
servo(
creates a servo motor object connected to the specified pin on the Raspberry Pi®.mypi
, pinNumber
)
servo(
creates a servo motor object with additional options specified by one or more Name, Value
pair arguments.mypi
, pinNumber
, Name,Value
)
Input Arguments
mypi
— Connection to Raspberry Pi hardware board
raspi
object
Connection to the Raspberry Pi hardware board, specified as a raspi
object.
pinNumber
— GPIO pin number
scalar
GPIO pin number, specified as a scalar. This argument does not accept vectors because the hardware cannot access multiple pins simultaneously.
To get a list of valid pin numbers, enter
.mypi
.AvailableDigitalPins
Example: 12
Data Types: double
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: s= servo(a, 7, 'MaxPulseDuration', 2e-3, 'MinPulseDuration',
1e-3);
MinPulseDuration
— Minimum pulse duration
1.00e-03 seconds (default) | numeric
Minimum pulse duration specified as the comma-separated pair consisting of
'MinPulseDuration'
and a number, which represents the duration
in seconds. Specified value must be equal to the width of the pulse the motor needs
to be at the minimum angle. Refer to your device data sheet for valid values. The
value can lie in between the range 5.00e-04 and 1.50e-03.
MaxPulseDuration
— Maximum pulse duration
2.00e-03 seconds (default) | numeric
Maximum pulse duration specified as the comma-separated pair consisting of
'MaxPulseDuration'
and a number, which represents the duration
in seconds. Specified value must be equal to width of the pulse the motor needs to
be at the maximum angle. Refer to your device data sheet for valid values. The value
can lie in between the range 1.50e-03 and 2.50e-03.
Output Arguments
s
— Servo object
object
Servo object returned as an object.
Examples
Create a Servo Object
Create an raspi
object, and attach the servo
object to pin 12.
mypi = raspi() s = servo(mypi,12)
s = Servo with properties: Pin: 12 MinPulseDuration: 5.44e-04 (s) MaxPulseDuration: 2.40e-03 (s)
Specify Minimum and Maximum Pulse Duration for a Servo
Set the minimum duration to 7e-4 and maximum to 2.3e-3 seconds.
Create an raspi
object and attach the servo
object to digital pin 12 and specify
mypi = raspi() s = servo(mypi,12,'MinPulseDuration',7.00e-4,'MaxPulseDuration',2.3e-3)
s = Servo with properties: Pin: 12 MinPulseDuration: 7.00e-04 (s) MaxPulseDuration: 2.30e-03 (s)
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
You can also deploy
servo
on the Raspberry Pi hardware in MATLAB® Online™.
Version History
Introduced in R2016b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)