Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pousseseringue-arduino
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
FabLAAS
PousseSeringue
pousseseringue-arduino
Commits
e1acfc00
Commit
e1acfc00
authored
1 year ago
by
Malaurie Bernard
Browse files
Options
Downloads
Patches
Plain Diff
Code editting : motor.h in snake case
parent
14c113fe
No related branches found
No related tags found
1 merge request
!17
Malaurie's work on UI + CLI interface + AccelStepper interface
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
motor.cpp
+18
-0
18 additions, 0 deletions
motor.cpp
motor.h
+50
-50
50 additions, 50 deletions
motor.h
with
68 additions
and
50 deletions
motor.cpp
+
18
−
0
View file @
e1acfc00
#include
"motor.h"
This diff is collapsed.
Click to expand it.
motor.h
+
50
−
50
View file @
e1acfc00
...
@@ -41,80 +41,80 @@ public:
...
@@ -41,80 +41,80 @@ public:
//CONSTRUCTORS
//CONSTRUCTORS
Motor
(
MotorHardware_t
&
stepper
)
:
stepper
(
stepper
)
Motor
(
MotorHardware_t
&
stepper
)
:
stepper
(
stepper
)
{
{
set
S
peed
MmPerS
ec
(
1
);
set
_s
peed
_mm_per_s
ec
(
1
);
set
A
ccel
MmPerSecPerS
ec
(
0.5
);
// <----- this is not yet configured by user
set
_a
ccel
_mm_per_sec_per_s
ec
(
0.5
);
// <----- this is not yet configured by user
}
}
void
set
MmPerR
ev
(
float
mm
PerR
evolution
)
void
set
_mm_per_r
ev
(
float
mm
_per_r
evolution
)
{
{
_mm
PerR
evolution
=
mm
PerR
evolution
;
_mm
_per_r
evolution
=
mm
_per_r
evolution
;
}
}
float
get
MmPerR
ev
()
const
float
get
_mm_per_r
ev
()
const
{
{
return
_mm
PerR
evolution
;
return
_mm
_per_r
evolution
;
}
}
void
set
P
hysical
(
int
steps
PerR
evolution
,
float
mm
PerR
evolution
,
bool
forward
C
lockwise
)
void
set
_p
hysical
(
int
steps
_per_r
evolution
,
float
mm
_per_r
evolution
,
bool
forward
_c
lockwise
)
{
{
_steps
PerR
evolution
=
steps
PerR
evolution
;
_steps
_per_r
evolution
=
steps
_per_r
evolution
;
set
MmPerRev
(
mmPerR
evolution
);
set
_mm_per_rev
(
mm_per_r
evolution
);
set
F
orward
C
lockwise
(
forward
C
lockwise
);
set
_f
orward
_c
lockwise
(
forward
_c
lockwise
);
}
}
void
set
F
orward
C
lockwise
(
bool
clockwise
)
void
set
_f
orward
_c
lockwise
(
bool
forward_
clockwise
)
{
{
_forward
C
lockwise
=
clockwise
;
_forward
_c
lockwise
=
forward_
clockwise
;
}
}
bool
get
F
orward
C
lockwise
()
bool
get
_f
orward
_c
lockwise
()
{
{
return
_forward
C
lockwise
;
return
_forward
_c
lockwise
;
}
}
void
set
S
peed
MmPerS
ec
(
float
mm
PerS
ec
)
void
set
_s
peed
_mm_per_s
ec
(
float
mm
_per_s
ec
)
{
{
#if !CORE_MOCK
#if !CORE_MOCK
stepper
.
setMaxSpeed
(
mm
ToS
tep
(
mm
PerS
ec
));
stepper
.
setMaxSpeed
(
mm
_to_s
tep
(
mm
_per_s
ec
));
#endif
#endif
}
}
bool
motor
IsR
unning
()
//return true if the motor is currently running
bool
motor
_is_r
unning
()
//return true if the motor is currently running
{
{
return
(
stepper
.
speed
()
!=
0
);
return
(
stepper
.
speed
()
!=
0
);
}
}
void
set
A
ccel
MmPerSecPerSec
(
float
mmPerSecPerS
ec
)
void
set
_a
ccel
_mm_per_sec_per_sec
(
float
mm_per_sec_per_s
ec
)
{
{
if
(
mm
PerSecPerS
ec
==
0
)
if
(
mm
_per_sec_per_s
ec
==
0
)
mm
PerSecPerS
ec
=
1000
;
mm
_per_sec_per_s
ec
=
1000
;
_retain
A
ccel
=
mm
PerSecPerS
ec
;
_retain
_a
ccel
=
mm
_per_sec_per_s
ec
;
#if !CORE_MOCK
#if !CORE_MOCK
stepper
.
setAcceleration
(
mm
ToS
tep
(
mm
PerSecPerS
ec
));
stepper
.
setAcceleration
(
mm
_to_s
tep
(
mm
_per_sec_per_s
ec
));
#endif
#endif
}
}
float
get
A
ccel
MmPerSecPerS
ec
()
const
float
get
_a
ccel
_mm_per_sec_per_s
ec
()
const
{
{
return
_retain
A
ccel
;
return
_retain
_a
ccel
;
}
}
float
mm
ToS
tep
(
float
mm
)
const
float
mm
_to_s
tep
(
float
mm
)
const
{
{
return
mm
*
_steps
PerR
evolution
/
_mm
PerR
evolution
;
return
mm
*
_steps
_per_r
evolution
/
_mm
_per_r
evolution
;
}
}
float
step
ToM
m
(
int
step
)
const
float
step
_to_m
m
(
int
step
)
const
{
{
return
step
*
_mm
PerR
evolution
/
_steps
PerR
evolution
;
return
step
*
_mm
_per_r
evolution
/
_steps
_per_r
evolution
;
}
}
int
where
S
tep
()
int
where
_s
tep
()
{
{
#if CORE_MOCK
#if CORE_MOCK
return
0
;
return
0
;
#else
#else
return
stepper
.
currentPosition
()
*
(
_forward
C
lockwise
?
1
:
-
1
);
return
stepper
.
currentPosition
()
*
(
_forward
_c
lockwise
?
1
:
-
1
);
#endif
#endif
}
}
...
@@ -122,20 +122,20 @@ public:
...
@@ -122,20 +122,20 @@ public:
{
{
Serial
.
printf
(
"# moving to %g mm / %g steps
\n
"
,
Serial
.
printf
(
"# moving to %g mm / %g steps
\n
"
,
mm
,
mm
,
mm
ToS
tep
(
mm
));
mm
_to_s
tep
(
mm
));
move
ToS
tep
(
mm
ToS
tep
(
mm
));
move
_to_s
tep
(
mm
_to_s
tep
(
mm
));
}
}
void
move
ToS
tep
(
int
step
)
void
move
_to_s
tep
(
int
step
)
{
{
#if !CORE_MOCK
#if !CORE_MOCK
cli
();
cli
();
set
A
ccel
MmPerSecPerS
ec
(
_retain
A
ccel
);
set
_a
ccel
_mm_per_sec_per_s
ec
(
_retain
_a
ccel
);
if
(
_mm
PerR
evolution
>
0
&&
_steps
PerR
evolution
>
0
)
if
(
_mm
_per_r
evolution
>
0
&&
_steps
_per_r
evolution
>
0
)
stepper
.
moveTo
(
_forward
C
lockwise
?
step
:
-
step
);
stepper
.
moveTo
(
_forward
_c
lockwise
?
step
:
-
step
);
sei
();
sei
();
#endif
#endif
Serial
.
printf
(
"# move to: %d step %g mm
\n
"
,
step
,
step
ToM
m
(
step
));
Serial
.
printf
(
"# move to: %d step %g mm
\n
"
,
step
,
step
_to_m
m
(
step
));
}
}
void
stop
()
void
stop
()
...
@@ -147,7 +147,7 @@ public:
...
@@ -147,7 +147,7 @@ public:
#endif
#endif
}
}
void
reset
P
osition
()
void
reset
_p
osition
()
{
{
#if !CORE_MOCK
#if !CORE_MOCK
stop
();
stop
();
...
@@ -157,40 +157,40 @@ public:
...
@@ -157,40 +157,40 @@ public:
#endif
#endif
}
}
void
stay
H
ere
()
void
stay
_h
ere
()
{
{
#if !CORE_MOCK
#if !CORE_MOCK
cli
();
cli
();
stepper
.
setAcceleration
(
1e20
);
stepper
.
setAcceleration
(
1e20
);
stepper
.
moveTo
(
stepper
.
currentPosition
());
// change target to here
stepper
.
moveTo
(
stepper
.
currentPosition
());
// change target to here
set
A
ccel
MmPerSecPerS
ec
(
_retain
A
ccel
);
set
_a
ccel
_mm_per_sec_per_s
ec
(
_retain
_a
ccel
);
sei
();
sei
();
#endif
#endif
}
}
void
show
C
onfiguration
()
void
show
_c
onfiguration
()
{
{
Serial
.
printf
(
"# %g mm/rev
\n
"
Serial
.
printf
(
"# %g mm/rev
\n
"
"# %d steps/rev
\n
"
"# %d steps/rev
\n
"
"# %g steps/mm
\n
"
"# %g steps/mm
\n
"
"# max speed: %g steps/s %g mm/s
\n
"
"# max speed: %g steps/s %g mm/s
\n
"
"# accel: %g steps/s/s %g mm/s/s
\n
"
,
"# accel: %g steps/s/s %g mm/s/s
\n
"
,
_mm
PerR
evolution
,
_mm
_per_r
evolution
,
_steps
PerR
evolution
,
_steps
_per_r
evolution
,
_steps
PerR
evolution
/
_mm
PerR
evolution
,
_steps
_per_r
evolution
/
_mm
_per_r
evolution
,
stepper
.
maxSpeed
(),
stepper
.
maxSpeed
(),
step
ToM
m
(
stepper
.
maxSpeed
()),
step
_to_m
m
(
stepper
.
maxSpeed
()),
stepper
.
acceleration
(),
stepper
.
acceleration
(),
step
ToM
m
(
stepper
.
acceleration
())
step
_to_m
m
(
stepper
.
acceleration
())
);
);
}
}
protected
:
protected
:
int
_steps
PerR
evolution
=
-
1
;
int
_steps
_per_r
evolution
=
-
1
;
float
_mm
PerR
evolution
=
-
1
;
float
_mm
_per_r
evolution
=
-
1
;
float
_retain
A
ccel
=
-
1
;
float
_retain
_a
ccel
=
-
1
;
bool
_forward
C
lockwise
;
bool
_forward
_c
lockwise
;
MotorHardware_t
&
stepper
;
MotorHardware_t
&
stepper
;
};
};
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