Webcam Tracker  V1.0
Using openCV and an Arduino Uno
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members

Controles the pan and tilt servo motors. More...

#include <PanTiltController.h>

Public Member Functions

void setPosition (uint16_t pan, uint16_t tilt)
 Sets the position of the pan and tilt motor. More...
 
void setPositionOffSet (uint16_t pan, uint16_t tilt)
 Sets the position of the pan and tilt motor. More...
 
void home ()
 Homes the pan and tilt motors. More...
 

Static Public Member Functions

static PanTiltControllerinitialize (uint8_t panPin, uint8_t tiltPin)
 Creates a object if there isn't one already. More...
 

Private Member Functions

 PanTiltController (uint8_t panPin, uint8_t tiltPin)
 constructor of the class More...
 
void initServos ()
 attaches the pin number to the servo's and homes the servo's
 
uint8_t limit (uint8_t angle)
 Limits an angle between 0° and 180° More...
 

Private Attributes

Servo panServo
 Servo motor object for pan.
 
Servo tiltServo
 Servo motor object for tilt.
 
uint8_t panPin
 pinnumber of the pan pwm
 
uint8_t tiltPin
 pinnumber of the tilt pwm
 
uint16_t pan
 Current pan angle [°].
 
uint16_t tilt
 Current tilt angle [°].
 

Static Private Attributes

static PanTiltControllerinstance = 0
 Pointer to the current used instance.
 

Detailed Description

Controles the pan and tilt servo motors.

Constructor & Destructor Documentation

◆ PanTiltController()

PanTiltController::PanTiltController ( uint8_t  panPin,
uint8_t  tiltPin 
)
private

constructor of the class

Parameters
panPinnumber of the pan pwm-pin
tiltPinnumber of the tilt pwm-pin
15  {
16  this->panPin = panPin;
17  this->tiltPin = tiltPin;
18  this->initServos();
19 }
uint8_t tiltPin
pinnumber of the tilt pwm
Definition: PanTiltController.h:21
void initServos()
attaches the pin number to the servo's and homes the servo's
Definition: PanTiltController.cpp:21
uint8_t panPin
pinnumber of the pan pwm
Definition: PanTiltController.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ limit()

uint8_t PanTiltController::limit ( uint8_t  angle)
private

Limits an angle between 0° and 180°

If nessecary sends an error over the serial port, indicating the input angle is out of range. When the angle is out of range it is clamped to 0° or 180°. Depending on at wich end the angle is out of range.

Parameters
angleangle that needs to be checked
Returns
limit: angle between 0° and 180°
27  {
28 
29  if (angle > 180) {
30  Serial.println("ERROR: Angle can't be bigger than 180 degrees");
31  return 180;
32  }
33  if (angle < 0) {
34  Serial.println("ERROR: Angle can't be smaller than 0 degrees");
35  return 0;
36  }
37 
38 
39  return angle;
40 }
Here is the caller graph for this function:

◆ initialize()

PanTiltController * PanTiltController::initialize ( uint8_t  panPin,
uint8_t  tiltPin 
)
static

Creates a object if there isn't one already.

Note
only one instance can excist because there are only two motors available at the moment
Parameters
panPinnumber of the pan pwm-pin
tiltPinnumber of the tilt pwm-pin
Returns
: PanTiltController: Pointer to object instance
42  {
43  if (0 == instance) {
45  }
46  else {
47  Serial.println("ERROR: Pan tilt controller already initialized");
48  }
49  return instance;
50 }
static PanTiltController * instance
Pointer to the current used instance.
Definition: PanTiltController.h:26
PanTiltController(uint8_t panPin, uint8_t tiltPin)
constructor of the class
Definition: PanTiltController.cpp:15
Here is the call graph for this function:

◆ setPosition()

void PanTiltController::setPosition ( uint16_t  pan,
uint16_t  tilt 
)

Sets the position of the pan and tilt motor.

if nessecary limits both angles

See also
limit()
Parameters
panangle to set the pan motor to
tiltangle to set the tilt motor to
52  {
53  this->pan = limit(pan);
54  this->tilt = limit(tilt);
55 
56  panServo.write(this->pan);
57  tiltServo.write(this->tilt);
58 }
uint16_t pan
Current pan angle [°].
Definition: PanTiltController.h:23
Servo tiltServo
Servo motor object for tilt.
Definition: PanTiltController.h:18
uint16_t tilt
Current tilt angle [°].
Definition: PanTiltController.h:24
Servo panServo
Servo motor object for pan.
Definition: PanTiltController.h:17
uint8_t limit(uint8_t angle)
Limits an angle between 0° and 180°
Definition: PanTiltController.cpp:27
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setPositionOffSet()

void PanTiltController::setPositionOffSet ( uint16_t  pan,
uint16_t  tilt 
)

Sets the position of the pan and tilt motor.

if nessecary limits both angles

See also
limit()
Parameters
panangle to set the pan motor to
tiltangle to set the tilt motor to
61 {
62  this->pan += pan;
63  this->tilt += tilt;
64 
65  setPosition(this->pan, this->tilt);
66 }
void setPosition(uint16_t pan, uint16_t tilt)
Sets the position of the pan and tilt motor.
Definition: PanTiltController.cpp:52
Here is the call graph for this function:

◆ home()

void PanTiltController::home ( )

Homes the pan and tilt motors.

Homing is done by setting both motors to 90 degrees

68  {
69 
70  this->pan = 90;
71  this->tilt = 90;
72 
73  setPosition(this->pan, this->tilt);
74 }
Here is the call graph for this function:
Here is the caller graph for this function: