+ initial version (not working yet)

This commit is contained in:
Rob Tillaart 2013-09-30 18:46:09 +02:00
parent d9f0dab217
commit 24edf387aa
3 changed files with 172 additions and 0 deletions

99
libraries/Radar/radar.cpp Normal file
View File

@ -0,0 +1,99 @@
//
// FILE: radar.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE: pan tilt radar framework
// URL:
//
// Released to the public domain
//
#include "radar.h"
////////////////////////////////////////////////////////////
//
// CONSTRUCTOR
//
RADAR::RADAR(int pinPan, int pinTilt)
{
_pinPan = pinPan;
_pinTilt = pinTilt;
}
// PUBLIC
void RADAR::setPan(int pan)
{
_prevPan = _pan; // remember last postion // TODO should in fact be getPan() to get current position.
_pan = pan;
digitalWrite(_pinPan, pan);
_lastPanTime = millis();
}
int RADAR::getPan()
{
// ESTIMATE current pan on time it takes to go from _prevPan to _pan
// and the time since setPan ==> millis() - _lastPanTime
//
// TODO CHECK MATH
unsigned long duration = millis() - lastPanTime;
int pan = 0;
if (duration >= abs(_pan - _prevPan) * PAN_PER_SEC/1000) pan = _pan;
else if (_pan > _prevpan) pan = _pan - duration * PAN_PER_SEC/1000;
else pan = _pan - duration * PAN_PER_SEC/1000;
return pan;
}
void RADAR::setTilt(int tilt)
{
_prevTilt = _tilt;
_tilt = tilt;
digitalWrite(_pinTilt, tilt);
_lastTiltTime = millis();
}
int RADAR::getTilt()
{
// TODO see pan
return 0;
}
// TODO extend this to an array of 10 memory positions
void setHomePosition(int pan, int tilt)
{
_homePan = pan;
_homeTilt = tilt;
}
void home()
{
setPan(_homePan);
setTilt(_homeTilt);
}
bool RADAR::ready()
{
return ((getPan() == _pan) && (getTilt == _tilt));
}
unsigned long RADAR::ping()
{
// TODO ping code here - playground or teckel's improved ping)))
return 0;
}
unsigned long RADAR::ping(int pan, int tilt)
{
setPan(pan);
setTilt(tilt);
while (!ready());
return ping();
}
// PRIVATE
// TODO distill private parts (getPan and getTilt share a lot
// -- END OF FILE --

61
libraries/Radar/radar.h Normal file
View File

@ -0,0 +1,61 @@
//
// FILE: radar.h
// AUTHOR: Rob Tillaart
// VERSION: see RADAR_LIB_VERSION
// PURPOSE: pan tilt radar framework
// URL:
//
// Released to the public domain
//
#ifndef Radar_h
#define Radar_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "SoftwareSerial.h"
#else
#include "WProgram.h"
#include "NewSoftSerial.h"
#endif
#define RADAR_LIB_VERSION "0.1.00"
#define PAN_PER_SEC 20 // TODO determine emperically
#define TILT_PER_SEC 10 // TODO determine emperically
class RADAR
{
public:
RADAR(int, int);
void setPan(int pan);
int getPan();
void setTilt(int tilt);
int getTilt();
void setHomePosition(int pan, int tilt);
void home();
bool ready();
unsigned long ping();
unsigned long ping(int pan, int tilt);
private:
int _pinPan;
int _pinTilt;
int _prevPan;
int _pan;
int _homePan;
unsigned long _lastPanTime
int _prevTilt;
int _tilt;
int _homeTilt;
unsigned long _lastTiltTime
};
#endif
// -- END OF FILE --

View File

@ -0,0 +1,12 @@
WARNING: not working version !!!
radar is a concept library not elaborated yet that implements a Ping))) based Radar
with the use of a pan/tilt servo's. Was written after a question on the forum but
never finished it. Still, it has some interesting concepts wrt determine the position of
pan/tilt while in progress.
In short a lot todo