Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MarlinKimbra
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
MarlinKimbra
Commits
9d4d7643
Commit
9d4d7643
authored
Feb 10, 2016
by
MagoKimbra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Servo
parent
6bb5dd51
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
25 deletions
+31
-25
servo.cpp
MK/module/servo/servo.cpp
+13
-9
servo.h
MK/module/servo/servo.h
+18
-16
No files found.
MK/module/servo/servo.cpp
View file @
9d4d7643
...
...
@@ -299,13 +299,10 @@ void Servo::writeMicroseconds(int value)
}
}
int
Servo
::
read
()
// return the value as degrees
{
return
map
(
readMicroseconds
()
+
1
,
SERVO_MIN
(),
SERVO_MAX
(),
0
,
180
);
}
// return the value as degrees
int
Servo
::
read
()
{
return
map
(
this
->
readMicroseconds
()
+
1
,
SERVO_MIN
(),
SERVO_MAX
(),
0
,
180
);
}
int
Servo
::
readMicroseconds
()
{
int
Servo
::
readMicroseconds
()
{
unsigned
int
pulsewidth
;
if
(
this
->
servoIndex
!=
INVALID_SERVO
)
pulsewidth
=
ticksToUs
(
servos
[
this
->
servoIndex
].
ticks
)
+
TRIM_DURATION
;
...
...
@@ -315,9 +312,16 @@ int Servo::readMicroseconds()
return
pulsewidth
;
}
bool
Servo
::
attached
()
{
return
servos
[
this
->
servoIndex
].
Pin
.
isActive
;
bool
Servo
::
attached
()
{
return
servos
[
this
->
servoIndex
].
Pin
.
isActive
;
}
void
Servo
::
move
(
int
value
)
{
if
(
this
->
attach
(
0
)
>=
0
)
{
this
->
write
(
value
);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
delay
(
SERVO_DEACTIVATION_DELAY
);
this
->
detach
();
#endif
}
}
#endif
MK/module/servo/servo.h
View file @
9d4d7643
...
...
@@ -83,22 +83,24 @@ typedef struct {
volatile
unsigned
int
ticks
;
}
servo_t
;
class
Servo
{
public
:
Servo
();
uint8_t
attach
(
int
pin
);
// attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
uint8_t
attach
(
int
pin
,
int
min
,
int
max
);
// as above but also sets min and max values for writes.
void
detach
();
void
write
(
int
value
);
// if value is < 200 its treated as an angle, otherwise as pulse width in microseconds
void
writeMicroseconds
(
int
value
);
// Write pulse width in microseconds
int
read
();
// returns current pulse width as an angle between 0 and 180 degrees
int
readMicroseconds
();
// returns current pulse width in microseconds for this servo (was read_us() in first release)
bool
attached
();
// return true if this servo is attached, otherwise false
private
:
uint8_t
servoIndex
;
// index into the channel data for this servo
int8_t
min
;
// minimum is this value times 4 added to MIN_PULSE_WIDTH
int8_t
max
;
// maximum is this value times 4 added to MAX_PULSE_WIDTH
class
Servo
{
public
:
Servo
();
uint8_t
attach
(
int
pin
);
// attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
uint8_t
attach
(
int
pin
,
int
min
,
int
max
);
// as above but also sets min and max values for writes.
void
detach
();
void
write
(
int
value
);
// if value is < 200 its treated as an angle, otherwise as pulse width in microseconds
void
writeMicroseconds
(
int
value
);
// Write pulse width in microseconds
void
move
(
int
value
);
// attach the servo, then move to value
// if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
// if DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DEACTIVATION_DELAY, then detach
int
read
();
// returns current pulse width as an angle between 0 and 180 degrees
int
readMicroseconds
();
// returns current pulse width in microseconds for this servo (was read_us() in first release)
bool
attached
();
// return true if this servo is attached, otherwise false
private
:
uint8_t
servoIndex
;
// index into the channel data for this servo
int8_t
min
;
// minimum is this value times 4 added to MIN_PULSE_WIDTH
int8_t
max
;
// maximum is this value times 4 added to MAX_PULSE_WIDTH
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment