Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
e2a8bcb8
Commit
e2a8bcb8
authored
10 years ago
by
Hauke Petersen
Browse files
Options
Downloads
Patches
Plain Diff
drivers: added servo motor driver
parent
1fd762d3
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
drivers/Makefile
+3
-0
3 additions, 0 deletions
drivers/Makefile
drivers/include/servo.h
+86
-0
86 additions, 0 deletions
drivers/include/servo.h
drivers/servo/Makefile
+3
-0
3 additions, 0 deletions
drivers/servo/Makefile
drivers/servo/servo.c
+46
-0
46 additions, 0 deletions
drivers/servo/servo.c
with
138 additions
and
0 deletions
drivers/Makefile
+
3
−
0
View file @
e2a8bcb8
...
@@ -34,5 +34,8 @@ endif
...
@@ -34,5 +34,8 @@ endif
ifneq
(,$(filter rgbled,$(USEMODULE)))
ifneq
(,$(filter rgbled,$(USEMODULE)))
DIRS
+=
rgbled
DIRS
+=
rgbled
endif
endif
ifneq
(,$(filter servo,$(USEMODULE)))
DIRS
+=
servo
endif
include
$(RIOTBASE)/Makefile.base
include
$(RIOTBASE)/Makefile.base
This diff is collapsed.
Click to expand it.
drivers/include/servo.h
0 → 100644
+
86
−
0
View file @
e2a8bcb8
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @defgroup driver_servo Servo Motor Driver
* @ingroup drivers
* @brief High-level driver for servo motors
* @{
*
* @file
* @brief High-level driver for easy handling of servo motors
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/
#ifndef __SERVO_H
#define __SERVO_H
#include
"periph/pwm.h"
/**
* @name Descriptor struct for a servo
*/
typedef
struct
{
pwm_t
device
;
/**< the PWM device driving the servo */
int
channel
;
/**< the channel the servo is connected to */
unsigned
int
min
;
/**< minimum pulse width, in us */
unsigned
int
max
;
/**< maximum pulse width, in us */
}
servo_t
;
/**
* @brief Initialize a servo motor by assigning it a PWM device and channel
*
* Digital servos are controlled by regular pulses sent to them. The width
* of a pulse determines the position of the servo. A pulse width of 1.5ms
* puts the servo in the center position, a pulse width of about 1.0ms and
* about 2.0ms put the servo to the maximum angles. These values can however
* differ slightly from servo to servo, so the min and max values are
* parameterized in the init function.
*
* The servo is initialized with fixed PWM values:
* - frequency: 100Hz (10ms interval)
* - resolution: 10000 (1000 steps per ms)
*
* Caution: When initializing a servo, the PWM device will be reconfigured to
* new frequency/resolution values. It is however fine to use multiple servos
* with the same PWM device, just on different channels.
*
* @param[out] dev struct describing the servo
* @param[in] pwm the PWM device the servo is connected to
* @param[in] pwm_channel the PWM channel the servo is connected to
* @param[in] min minimum pulse width in us
* @param[in] max maximum pulse width in us
*
* @return 0 on success
* @return <0 on error
*/
int
servo_init
(
servo_t
*
dev
,
pwm_t
pwm
,
int
pwm_channel
,
unsigned
int
min
,
unsigned
int
max
);
/**
* @brief Set the servo motor to a specified position
*
* The position of the servo is specified in the pulse width that controls the
* servo. A value of 1500 means a pulse width of 1.5 ms, which is the center
* position on most servos.
*
* In case pos is larger/smaller then the max/min values, pos will be set to
* these values.
*
* @param[in] dev the servo to set
* @param[in] pos the position to set the servo in us
*
* @return 0 on success
* @return -1 on invalid configured channel
* @return -2 on invalid position
*/
int
servo_set
(
servo_t
*
dev
,
unsigned
int
pos
);
#endif
/* __SERVO_H */
/** @} */
This diff is collapsed.
Click to expand it.
drivers/servo/Makefile
0 → 100644
+
3
−
0
View file @
e2a8bcb8
MODULE
=
servo
include
$(RIOTBASE)/Makefile.base
This diff is collapsed.
Click to expand it.
drivers/servo/servo.c
0 → 100644
+
46
−
0
View file @
e2a8bcb8
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup driver_servo
* @{
*
* @file
* @brief Servo motor driver implementation
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include
"servo.h"
#include
"periph/pwm.h"
#define FREQUENCY (100U)
#define RESOLUTION (10000U)
int
servo_init
(
servo_t
*
dev
,
pwm_t
pwm
,
int
pwm_channel
,
unsigned
int
min
,
unsigned
int
max
)
{
dev
->
device
=
pwm
;
dev
->
channel
=
pwm_channel
;
dev
->
min
=
min
;
dev
->
max
=
max
;
return
pwm_init
(
dev
->
device
,
PWM_LEFT
,
FREQUENCY
,
RESOLUTION
);
}
int
servo_set
(
servo_t
*
dev
,
unsigned
int
pos
)
{
if
(
pos
>
dev
->
max
)
{
pos
=
dev
->
max
;
}
else
(
pos
<
dev
->
min
)
{
pos
=
dev
->
min
;
}
return
pwm_set
(
dev
->
device
,
dev
->
channel
,
pos
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment