Fawkes API Fawkes Development Version
sony_evid100p.cpp
1
2/***************************************************************************
3 * sony_evid100p_control.cpp - Controller for Sony EVI-D100P
4 *
5 * Created: Tue Jun 07 19:27:20 2005
6 * Copyright 2005-2009 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#include <fvcams/control/sony_evid100p.h>
25#include <fvcams/control/visca.h>
26#include <fvutils/system/camargp.h>
27#include <utils/math/angle.h>
28
29#include <cstdlib>
30#include <cstring>
31#include <termios.h>
32
33using namespace std;
34using namespace fawkes;
35
36namespace firevision {
37
38/** Maximum pan. */
39const int SonyEviD100PControl::MAX_PAN = 1440;
40/** Minimum pan. */
41const int SonyEviD100PControl::MIN_PAN = -1439;
42/** Max Tilt. */
43const int SonyEviD100PControl::MAX_TILT = 360;
44/** Min tilt .*/
45const int SonyEviD100PControl::MIN_TILT = -359;
46
47/** Max pan in degrees. */
48const float SonyEviD100PControl::MAX_PAN_DEG = 100.f;
49/** Min pan in degrees. */
50const float SonyEviD100PControl::MIN_PAN_DEG = -100.f;
51/** Max tilt in degrees. */
52const float SonyEviD100PControl::MAX_TILT_DEG = 25.f;
53/** Min tilt in degrees. */
54const float SonyEviD100PControl::MIN_TILT_DEG = -25.f;
55
56/** Max pan in rad. */
57const float SonyEviD100PControl::MAX_PAN_RAD = deg2rad(MAX_PAN_DEG);
58/** Min pan in rad. */
59const float SonyEviD100PControl::MIN_PAN_RAD = deg2rad(MIN_PAN_DEG);
60/** Max tilt in rad. */
61const float SonyEviD100PControl::MAX_TILT_RAD = deg2rad(MAX_TILT_DEG);
62/** Min tilt in rad. */
63const float SonyEviD100PControl::MIN_TILT_RAD = deg2rad(MIN_TILT_DEG);
64
65/** Pan steps per degree */
66const float SonyEviD100PControl::PAN_STEPS_PER_DEG = MAX_PAN / MAX_PAN_DEG;
67/** Tilt steps per degree */
68const float SonyEviD100PControl::TILT_STEPS_PER_DEG = MAX_TILT / MAX_TILT_DEG;
69
70/** Pan steps per rad */
71const float SonyEviD100PControl::PAN_STEPS_PER_RAD = MAX_PAN / MAX_PAN_RAD;
72/** Tilt steps per rad */
73const float SonyEviD100PControl::TILT_STEPS_PER_RAD = MAX_TILT / MAX_TILT_RAD;
74
75/** Pastel effect. */
76const unsigned int SonyEviD100PControl::EFFECT_PASTEL = 1;
77/** Negative effect. */
78const unsigned int SonyEviD100PControl::EFFECT_NEGATIVE = 2;
79/** Sepia effect. */
80const unsigned int SonyEviD100PControl::EFFECT_SEPIA = 3;
81/** B/W effect. */
82const unsigned int SonyEviD100PControl::EFFECT_BW = 4;
83/** Solarize effect. */
84const unsigned int SonyEviD100PControl::EFFECT_SOLARIZE = 5;
85/** Mosaic effect. */
86const unsigned int SonyEviD100PControl::EFFECT_MOSAIC = 6;
87/** Slim effect. */
88const unsigned int SonyEviD100PControl::EFFECT_SLIM = 7;
89/** Stretch effect. */
90const unsigned int SonyEviD100PControl::EFFECT_STRETCH = 8;
91
92/** @class SonyEviD100PControl <fvcams/control/sony_evid100p.h>
93 * Sony Evi D100P pan/tilt control.
94 * Internally uses Visca.
95 * @author Tim Niemueller
96 */
97
98/** Constructor.
99 * @param tty_port serial port (e.g. /dev/ttyS0)
100 */
102{
103 this->tty_port = strdup(tty_port);
104 visca = new ViscaControl(/* non-blocking */ false);
105 opened = false;
106 pan_target = 0;
107 tilt_target = 0;
108 _effect = EFFECT_NONE;
109
110 open();
111}
112
113/** Constructor.
114 * Uses camera argument parser to gather arguments. The ID that the camera argument
115 * parser returns is used as the serial port (like /dev/ttyS0).
116 * @param cap camera argument parser
117 */
119{
120 tty_port = strdup(cap->cam_id().c_str());
121
122 visca = new ViscaControl(/* non-blocking */ false);
123 opened = false;
124 pan_target = 0;
125 tilt_target = 0;
126 _effect = EFFECT_NONE;
127
128 open();
129}
130
131/** Destructor. */
133{
134 close();
135 delete visca;
136 free(tty_port);
137}
138
139/** Open visca device.
140 */
141void
143{
144 if (opened)
145 return;
146
147 try {
148 visca->open(tty_port);
149 visca->set_address(1);
150 visca->clear();
151 } catch (ViscaControlException &e) {
152 visca->close();
153 e.append("Sony EviD100PControl failed");
154 throw;
155 }
156
157 opened = true;
158}
159
160/** Close Visca device.
161 */
162void
164{
165 if (!opened)
166 return;
167 visca->close();
168}
169
170void
172{
173 visca->process();
174}
175
176bool
178{
179 return true;
180}
181
182bool
184{
185 return true;
186}
187
188void
190{
191 pan_target = pan;
192 visca->setPanTilt(pan, tilt_target);
193}
194
195void
197{
198 tilt_target = tilt;
199 visca->setPanTilt(pan_target, tilt);
200}
201
202void
204{
205 pan_target = pan;
206 tilt_target = tilt;
207 visca->setPanTilt(pan, tilt);
208}
209
210void
212{
213 int tpan = 0, ttilt = 0;
214
215 tpan = (int)rint(pan * PAN_STEPS_PER_RAD);
216 ttilt = (int)rint(tilt * TILT_STEPS_PER_RAD);
217
218 set_pan_tilt(tpan, ttilt);
219}
220
221void
223{
224 visca->startGetPanTilt();
225}
226
227void
229{
230 int tpan, ttilt;
231 visca->getPanTilt(&tpan, &ttilt);
232 pan = tpan;
233 tilt = ttilt;
234}
235
236void
237SonyEviD100PControl::pan_tilt_rad(float &pan, float &tilt)
238{
239 int tpan = 0, ttilt = 0;
240 visca->getPanTilt(&tpan, &ttilt);
241
242 pan = tpan / PAN_STEPS_PER_RAD;
243 tilt = ttilt / PAN_STEPS_PER_RAD;
244}
245
246int
248{
249 int pan = 0, tilt = 0;
250 visca->getPanTilt(&pan, &tilt);
251 return pan;
252}
253
254int
256{
257 int pan = 0, tilt = 0;
258 visca->getPanTilt(&pan, &tilt);
259 return tilt;
260}
261
262int
264{
265 return MAX_PAN;
266}
267
268int
270{
271 return MIN_PAN;
272}
273
274int
276{
277 return MAX_TILT;
278}
279
280int
282{
283 return MIN_TILT;
284}
285
286void
288{
289 visca->resetPanTilt();
290}
291
292void
293SonyEviD100PControl::set_pan_tilt_limit(int pan_left, int pan_right, int tilt_up, int tilt_down)
294{
295 visca->setPanTiltLimit(pan_left, pan_right, tilt_up, tilt_down);
296}
297
298void
300{
301 visca->resetPanTiltLimit();
302}
303
304void
306{
307 visca->resetZoom();
308}
309
310void
312{
313 visca->setZoom(zoom);
314}
315
316unsigned int
318{
319 unsigned int zoom;
320 visca->getZoom(&zoom);
321 return zoom;
322}
323
324unsigned int
326{
327 return 0;
328}
329
330unsigned int
332{
333 return 0x4000;
334}
335
336void
338{
339 visca->setZoomSpeedTele(speed);
340}
341
342void
344{
345 visca->setZoomSpeedWide(speed);
346}
347
348void
350{
351 visca->setZoomDigitalEnabled(enabled);
352}
353
354bool
356{
357 if (effect_ == EFFECT_NONE) {
358 return true;
359 }
360
361 switch (effect_) {
362 case EFFECT_PASTEL:
363 case EFFECT_NEGATIVE:
364 case EFFECT_SEPIA:
365 case EFFECT_BW:
366 case EFFECT_SOLARIZE:
367 case EFFECT_MOSAIC:
368 case EFFECT_SLIM:
369 case EFFECT_STRETCH: return true; break;
370 default: return false;
371 }
372}
373
374void
376{
377 this->_effect = effect_;
378 if (effect_ == EFFECT_NONE) {
379 visca->resetEffect();
380 }
381 switch (effect_) {
382 case EFFECT_PASTEL: visca->applyEffectPastel(); break;
383 case EFFECT_NEGATIVE: visca->applyEffectNegArt(); break;
384 case EFFECT_SEPIA: visca->applyEffectSepia(); break;
385 case EFFECT_BW: visca->applyEffectBnW(); break;
386 case EFFECT_SOLARIZE: visca->applyEffectSolarize(); break;
387 case EFFECT_MOSAIC: visca->applyEffectMosaic(); break;
388 case EFFECT_SLIM: visca->applyEffectSlim(); break;
389 case EFFECT_STRETCH: visca->applyEffectStretch(); break;
390 default: break;
391 }
392}
393
394unsigned int
396{
397 return _effect;
398}
399
400void
402{
403 visca->resetEffect();
404}
405
406/** Get current white balance mode.
407 * @return white balance mode
408 */
409unsigned int
411{
412 return visca->getWhiteBalanceMode();
413}
414
415} // end namespace firevision
void append(const char *format,...) noexcept
Append messages to the message list.
Definition: exception.cpp:333
Camera argument parser.
Definition: camargp.h:36
std::string cam_id() const
Get camera ID.
Definition: camargp.cpp:133
static const unsigned int EFFECT_NONE
No effect constant.
Definition: effect.h:35
static const int MAX_TILT
Max Tilt.
Definition: sony_evid100p.h:98
static const unsigned int EFFECT_SEPIA
Sepia effect.
Definition: sony_evid100p.h:43
void set_zoom_speed_tele(unsigned int speed)
Set speed in tele range.
static const int MIN_TILT
Min tilt .
Definition: sony_evid100p.h:99
void set_zoom_digital_enabled(bool enabled)
Set if digital zoom may be used.
void set_tilt(int tilt)
Set tilt value.
void process_pantilt()
Process pan/tilt information.
void start_get_pan_tilt()
Start asynchronous fetch operation for pan and tilt values.
void set_effect(unsigned int effect)
Enable effect.
static const float TILT_STEPS_PER_DEG
Tilt steps per degree.
bool supports_tilt()
Check whether this controller supports tilting.
static const unsigned int EFFECT_PASTEL
Pastel effect.
Definition: sony_evid100p.h:41
static const float MAX_PAN_RAD
Max pan in rad.
static const float TILT_STEPS_PER_RAD
Tilt steps per rad.
void reset_pan_tilt()
Bring camera into home position.
unsigned int white_balance_mode()
Get current white balance mode.
bool supports_pan()
Check whether this controller supports panning.
void pan_tilt(int &pan, int &tilt)
Get pan and tilt at the same time.
static const unsigned int EFFECT_NEGATIVE
Negative effect.
Definition: sony_evid100p.h:42
static const float MAX_TILT_RAD
Max tilt in rad.
void set_pan_tilt_rad(float pan, float tilt)
Set pan and tilt as float value.
static const unsigned int EFFECT_SOLARIZE
Solarize effect.
Definition: sony_evid100p.h:45
static const float MAX_TILT_DEG
Max tilt in degrees.
unsigned int zoom_max()
Maximum zoom value.
void set_pan(int pan)
Set pan value.
void set_zoom(unsigned int zoom)
Set new camera-specific zoom value.
int min_tilt()
Get minimum tilt value.
SonyEviD100PControl(const CameraArgumentParser *cap)
Constructor.
static const int MAX_PAN
Maximum pan.
Definition: sony_evid100p.h:96
void pan_tilt_rad(float &pan, float &tilt)
Get pan and tilt at the same time in radiant.
static const int MIN_PAN
Minimum pan.
Definition: sony_evid100p.h:97
int max_tilt()
Get maximum tilt value.
void open()
Open visca device.
static const unsigned int EFFECT_STRETCH
Stretch effect.
Definition: sony_evid100p.h:48
void set_pan_tilt_limit(int pan_left, int pan_right, int tilt_up, int tilt_down)
Set pan/tilt limits.
int max_pan()
Get maximum pan value.
bool supports_effect(unsigned int effect)
Check if camera control supports desired effect.
static const float MAX_PAN_DEG
Max pan in degrees.
unsigned int zoom_min()
Minimum zoom value.
unsigned int zoom()
Get current zoom value.
void reset_effect()
Reset effect.
virtual ~SonyEviD100PControl()
Destructor.
static const float MIN_PAN_RAD
Min pan in rad.
void set_zoom_speed_wide(unsigned int speed)
Set speed in wide range.
static const unsigned int EFFECT_BW
B/W effect.
Definition: sony_evid100p.h:44
void close()
Close Visca device.
static const float PAN_STEPS_PER_DEG
Pan steps per degree.
void reset_pan_tilt_limit()
Reset pan/tilt limits.
void set_pan_tilt(int pan, int tilt)
Set pan and tilt in one go.
unsigned int effect()
Current effect.
static const float PAN_STEPS_PER_RAD
Pan steps per rad.
static const float MIN_PAN_DEG
Min pan in degrees.
int min_pan()
Get minimum pan value.
static const float MIN_TILT_DEG
Min tilt in degrees.
static const unsigned int EFFECT_SLIM
Slim effect.
Definition: sony_evid100p.h:47
static const unsigned int EFFECT_MOSAIC
Mosaic effect.
Definition: sony_evid100p.h:46
static const float MIN_TILT_RAD
Min tilt in rad.
Visca control protocol implementation over a serial line.
Definition: visca.h:54
void setZoomSpeedTele(unsigned int speed)
Set zoom speed in tele.
Definition: visca.cpp:805
void clear()
Clear.
Definition: visca.cpp:216
void setPanTiltLimit(int pan_left, int pan_right, int tilt_up, int tilt_down)
Set pan tilt limit.
Definition: visca.cpp:724
void process()
Process incoming data.
Definition: visca.cpp:482
void setPanTilt(int pan, int tilt)
Set pan tilt.
Definition: visca.cpp:502
void getPanTilt(int *pan, int *tilt)
Get pan and tilt values.
Definition: visca.cpp:584
void applyEffectNegArt()
Apply negative art effect.
Definition: visca.cpp:974
unsigned int getWhiteBalanceMode()
Get white balance mode.
Definition: visca.cpp:1060
void close()
Close port.
Definition: visca.cpp:183
void applyEffectSolarize()
Apply solarize effect.
Definition: visca.cpp:1010
void resetPanTilt()
Reset pan/tilt.
Definition: visca.cpp:768
void applyEffectSepia()
Apply sepia effect.
Definition: visca.cpp:986
void set_address(unsigned int num_cameras)
Set addresses of cameras.
Definition: visca.cpp:195
void resetZoom()
Reset zoom.
Definition: visca.cpp:785
void applyEffectPastel()
Apply pastel effect.
Definition: visca.cpp:962
void setZoomSpeedWide(unsigned int speed)
Set zoom speed in wide angle.
Definition: visca.cpp:827
void applyEffectSlim()
Apply slim effect.
Definition: visca.cpp:1034
void resetPanTiltLimit()
Reset pan/tilt limit.
Definition: visca.cpp:688
void open(const char *port)
Open serial port.
Definition: visca.cpp:103
void applyEffectStretch()
Apply stretch effect.
Definition: visca.cpp:1046
void applyEffectBnW()
Apply B/W effect.
Definition: visca.cpp:998
void startGetPanTilt()
Query for pan/tilt but do not wait until finished This will send an inquire to the camera that asks f...
Definition: visca.cpp:556
void setZoom(unsigned int zoom)
Set zoom.
Definition: visca.cpp:849
void getZoom(unsigned int *zoom)
Get zoom.
Definition: visca.cpp:874
void resetEffect()
Reset effects.
Definition: visca.cpp:950
void applyEffectMosaic()
Apply mosaic effect.
Definition: visca.cpp:1022
void setZoomDigitalEnabled(bool enabled)
Enable or disable digital zoome.
Definition: visca.cpp:908
Fawkes library namespace.
float deg2rad(float deg)
Convert an angle given in degrees to radians.
Definition: angle.h:36