ArdEV3
Use EV3 peripherals from Arduino microcontrollers.
Toggle main menu visibility
Loading...
Searching...
No Matches
EV3Motor.h
1
#pragma once
2
#include <stdint.h>
3
#include <EV3Peripheral.h>
4
8
12
16
17
18
#define ev3Motor_EncoderGlobal(motor) void ev3Motor_STATIC_##motor##__EncoderWrapper() {motor._CountPulse();}
19
20
#define ev3Motor_SetupEncoder(motor) attachInterrupt(digitalPinToInterrupt(motor.Ports().EncoderA), ev3Motor_STATIC_##motor##__EncoderWrapper, RISING);
21
22
namespace
ev3 {
23
42
struct
MotorPortConfig
{
43
uint8_t Enable, In1, In2, EncoderA, EncoderB;
44
};
45
46
enum
MotorDirection {
47
FORWARD, REVERSE
48
};
49
60
class
Motor
:
public
_::Peripheral
<MotorPortConfig> {
61
MotorPortConfig
ports;
62
volatile
unsigned
long
encoder = 0;
63
bool
encoding =
false
;
64
bool
runningToPosition =
false
;
65
unsigned
long
target = 0;
66
67
void
checkDistance();
68
public
:
69
EV3_PERIPHERAL_CONSTRUCT(
Motor
)
70
71
void
SetPower
(uint8_t power);
72
void
SetDirection
(MotorDirection direction);
73
void
StartEncoder
();
74
void
StopEncoder
();
75
void
ResetEncoder
();
76
void
RunToPosition
(uint8_t power,
unsigned
long
position);
77
78
void
_CountPulse();
79
80
virtual
void
Setup
();
81
virtual
void
Loop
();
82
};
83
}
ev3::Motor
Definition
EV3Motor.h:60
ev3::Motor::ResetEncoder
void ResetEncoder()
Reset the encoder to zero.
Definition
EV3Motor.cc:20
ev3::Motor::RunToPosition
void RunToPosition(uint8_t power, unsigned long position)
Set the motor running to the specified position at the specified power. This will complete asynchrono...
Definition
EV3Motor.cc:33
ev3::Motor::Loop
virtual void Loop()
Run once per cycle – call this in your global loop function.
Definition
EV3Motor.cc:61
ev3::Motor::Setup
virtual void Setup()
Initialize the motor. Call this in your global setup function.
Definition
EV3Motor.cc:48
ev3::Motor::StartEncoder
void StartEncoder()
Start tracking the encoder position.
Definition
EV3Motor.cc:12
ev3::Motor::SetPower
void SetPower(uint8_t power)
Set the power of the motor. This writes a PWM signal to the enable pin.
Definition
EV3Motor.cc:24
ev3::Motor::SetDirection
void SetDirection(MotorDirection direction)
Set the direction of the motor. This writes digital signals to the input 1 and 2 pins.
Definition
EV3Motor.cc:28
ev3::Motor::StopEncoder
void StopEncoder()
Stop tracking the encoder position.
Definition
EV3Motor.cc:16
ev3::_::Peripheral
Definition
EV3Peripheral.h:9
ev3::MotorPortConfig
Definition
EV3Motor.h:42
src
EV3Motor.h
Generated by
1.17.0