Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
thk_motor_driver
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thk_libs
microcontrollers
thk_motor_driver
Commits
bb874760
Commit
bb874760
authored
Feb 11, 2022
by
Orhan-Timo Altan
Browse files
Options
Downloads
Patches
Plain Diff
Kleine Änderungen und neue Funktion hinzugefügt (drive)
parent
bce2e75b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
DCMotor.cpp
+19
-30
19 additions, 30 deletions
DCMotor.cpp
DCMotor.h
+8
-7
8 additions, 7 deletions
DCMotor.h
README.md
+2
-2
2 additions, 2 deletions
README.md
examples/drive/drive.ino
+13
-1
13 additions, 1 deletion
examples/drive/drive.ino
keywords.txt
+1
-1
1 addition, 1 deletion
keywords.txt
with
43 additions
and
41 deletions
DCMotor.cpp
+
19
−
30
View file @
bb874760
...
...
@@ -31,75 +31,64 @@ DCMotor::DCMotor(const String& NAME, uint8_t MOTOR_COUNT, uint8_t PIN_STBY, uint
}
}
void
DCMotor
::
forward
(
uint16_t
VEL
)
void
DCMotor
::
forward
(
byte
vel
)
{
if
(
NAME
==
"TB6612FNG"
)
{
if
(
MOTOR_COUNT
==
1
)
{
digitalWrite
(
PIN_STBY
,
HIGH
);
analogWrite
(
PIN_PWM1
,
VEL
);
analogWrite
(
PIN_PWM1
,
vel
);
digitalWrite
(
PIN_IN1
,
LOW
);
digitalWrite
(
PIN_IN2
,
HIGH
);
}
if
(
MOTOR_COUNT
==
2
)
{
digitalWrite
(
PIN_STBY
,
HIGH
);
analogWrite
(
PIN_PWM1
,
VEL
);
analogWrite
(
PIN_PWM1
,
vel
);
digitalWrite
(
PIN_IN1
,
LOW
);
digitalWrite
(
PIN_IN2
,
HIGH
);
analogWrite
(
PIN_PWM2
,
VEL
);
analogWrite
(
PIN_PWM2
,
vel
);
digitalWrite
(
PIN_IN3
,
LOW
);
digitalWrite
(
PIN_IN4
,
HIGH
);
}
}
}
void
DCMotor
::
backward
(
uint16_t
VEL
){
void
DCMotor
::
backward
(
byte
vel
){
if
(
NAME
==
"TB6612FNG"
)
{
if
(
MOTOR_COUNT
==
1
)
{
digitalWrite
(
PIN_STBY
,
HIGH
);
analogWrite
(
PIN_PWM1
,
VEL
);
analogWrite
(
PIN_PWM1
,
vel
);
digitalWrite
(
PIN_IN1
,
HIGH
);
digitalWrite
(
PIN_IN2
,
LOW
);
}
if
(
MOTOR_COUNT
==
2
)
{
digitalWrite
(
PIN_STBY
,
HIGH
);
analogWrite
(
PIN_PWM1
,
VEL
);
analogWrite
(
PIN_PWM1
,
vel
);
digitalWrite
(
PIN_IN1
,
HIGH
);
digitalWrite
(
PIN_IN2
,
LOW
);
analogWrite
(
PIN_PWM2
,
VEL
);
analogWrite
(
PIN_PWM2
,
vel
);
digitalWrite
(
PIN_IN3
,
HIGH
);
digitalWrite
(
PIN_IN4
,
LOW
);
}
}
}
// void DCMotor::drive(int16_t VEL){
// if (NAME == "TB6612FNG")
// {
// if (MOTOR_COUNT == 1)
// {
// digitalWrite(PIN_STBY, HIGH);
// analogWrite(PIN_PWM1, VEL);
// digitalWrite(PIN_IN1, HIGH);
// digitalWrite(PIN_IN2, LOW);
// }
// if (MOTOR_COUNT == 2)
// {
// digitalWrite(PIN_STBY, HIGH);
// analogWrite(PIN_PWM1, VEL);
// digitalWrite(PIN_IN1, HIGH);
// digitalWrite(PIN_IN2, LOW);
// analogWrite(PIN_PWM2, VEL);
// digitalWrite(PIN_IN3, HIGH);
// digitalWrite(PIN_IN4, LOW);
// }
// }
// }
void
DCMotor
::
drive
(
int
direction
,
byte
vel
){
if
(
NAME
==
"TB6612FNG"
)
{
if
(
direction
<
0
){
DCMotor
::
backward
(
vel
);
}
else
{
DCMotor
::
forward
(
vel
);
}
}
}
void
DCMotor
::
stop
(){
if
(
NAME
==
"TB6612FNG"
)
...
...
This diff is collapsed.
Click to expand it.
DCMotor.h
+
8
−
7
View file @
bb874760
/*
* Klasse: DCM
* Klasse: DCM
otor
*
* Zur ansteuerung von Gleichstrommotoren mit verschiedenen Motortreibern
*
...
...
@@ -7,8 +7,8 @@
*
*/
#ifndef DCM_H
#define DCM_H
#ifndef
BITS
DCM_H
#define
BITS
DCM_H
#include
<Arduino.h>
...
...
@@ -16,15 +16,16 @@ class DCMotor
{
public:
DCMotor
(
const
String
&
NAME
,
const
uint8_t
MOTOR_COUNT
,
const
uint8_t
PIN_STBY
,
const
uint8_t
PIN_PWM1
,
const
uint8_t
PIN_IN1
,
const
uint8_t
PIN_IN2
,
const
uint8_t
PIN_PWM2
=
0
,
const
uint8_t
PIN_IN3
=
0
,
const
uint8_t
PIN_IN4
=
0
);
void
forward
(
uint16_t
VEL
);
void
backward
(
uint16_t
VEL
);
void
drive
(
int16_t
t_VEL
);
void
forward
(
byte
vel
);
void
backward
(
byte
vel
);
void
drive
(
int16_t
direction
,
byte
vel
);
void
stop
();
private:
const
String
&
NAME
;
uint8_t
MOTOR_COUNT
,
PIN_STBY
,
PIN_PWM1
,
PIN_IN1
,
PIN_IN2
,
PIN_PWM2
,
PIN_IN3
,
PIN_IN4
;
uint16_t
VEL
;
int16_t
direction
;
byte
vel
;
};
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
README.md
+
2
−
2
View file @
bb874760
# **DC
-
Motor**
# **
BITs
DCMotor**
Eine Klasse zur Ansteuerung von Gleichstrommotoren für unterschiedliche Motortreiber.
...
...
@@ -22,7 +22,7 @@ Es wird für jeden Motortreiber nur ein Objekt benötigt, der beim instanziieren
Einbinden der Libraries:
`#include <DCM.h>`
<br
/>
`#include <DCM
otor
.h>`
<br
/>
<br
/>
Instanziieren eines Motortreiber-Objektes:
...
...
This diff is collapsed.
Click to expand it.
examples/drive/drive.ino
+
13
−
1
View file @
bb874760
...
...
@@ -6,7 +6,7 @@ const int Motor_IN1 = 40;
const
int
Motor_IN2
=
42
;
const
int
Motor_Count
=
1
;
const
String
Motor_driver_name
=
"TB6612FNG"
;
int
velocity
=
150
;
byte
velocity
=
150
;
DCMotor
Motor
(
Motor_driver_name
,
Motor_Count
,
Motor_STBY
,
Motor_PWM
,
Motor_IN1
,
Motor_IN2
);
...
...
@@ -28,4 +28,16 @@ void loop()
Motor
.
stop
();
delay
(
1000
);
Motor
.
drive
(
1
,
velocity
);
// Vorwärts
delay
(
2000
);
Motor
.
stop
();
delay
(
1000
);
Motor
.
drive
(
-
1
,
velocity
);
// Rückwärts
delay
(
2000
);
Motor
.
stop
();
delay
(
1000
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
keywords.txt
+
1
−
1
View file @
bb874760
...
...
@@ -2,7 +2,7 @@
# Datatypes (KEYWORD1)
#######################################
DCM
KEYWORD1
DCM
otor
KEYWORD1
#######################################
...
...
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