Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpRingLight.cpp
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See https://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Ring light management.
33 *
34*****************************************************************************/
35
36#include <visp3/core/vpConfig.h>
37
38#if defined(VISP_HAVE_MODULE_IO) && defined(VISP_HAVE_PARPORT)
39
40#include <fcntl.h>
41#include <sys/ioctl.h>
42#include <sys/stat.h>
43#include <sys/time.h>
44#include <sys/types.h>
45#include <unistd.h>
46
47#include <visp3/core/vpDebug.h>
48#include <visp3/core/vpTime.h>
49#include <visp3/robot/vpRingLight.h>
50
70vpRingLight::vpRingLight() : parport() { off(); }
71
81
90{
91 // Data set by the parallel port:
92 // - D1: need to send a 500us pulse width
93 // - D2: 0 }
94 // - D3: 0 } To control the light throw the NE555
95 // D2 and D3 are used to select the multiplexer output.
96 // Light must be connected to output 1+,1-
97
98 // To activates the light we send a pulse
99 int mask_mode_pulse_d2 = 0x00; // D2 is low
100 int mask_pulse_d1 = 0x02; // we send a pulse on D1 : L, H, L
101 unsigned char data = 0x00;
102 // data = parport.getData(); // actual value of the data bus
103 // vpTRACE("Actual data 0x%x = %d\n", data, data);
104
105 data = data | mask_pulse_d1 | mask_mode_pulse_d2;
106 // vpTRACE("Send 0x%x = %d\n", data, data);
107 parport.sendData(data); // send a 0-1 pulse
108
109 // Wait 500 micro seconds
110 struct timeval ti, tc; // Initial and current time
111 struct timeval tempo;
112 tempo.tv_usec = 500;
113 gettimeofday(&ti, 0L);
114 do {
115 gettimeofday(&tc, 0L);
116 } while (tc.tv_usec < ti.tv_usec + tempo.tv_usec);
117
118 data = data & (~mask_pulse_d1);
119 // vpTRACE("Send 0x%x = %d\n", data, data);
120 parport.sendData(data); // send a 1-0 pulse
121}
122
132void vpRingLight::pulse(double time)
133{
134 // Data set by the parallel port:
135 // - D1: a pulse with duration fixed by time
136 // - D2: 0 }
137 // - D3: 1 } To control the light directly throw the pulse comming from D1
138 // D2 and D3 are used to select the multiplexer output.
139 // Light must be connected to output 1+,1-
140
141 // To activates the light we send a pulse
142 int mask_mode_pulse_d3 = 0x08; // D3 is hight, D2 is low
143 int mask_pulse_d1 = 0x02; // we send a pulse on D1 : L, H, L
144 unsigned char data = 0x00;
145 // data = parport.getData(); // actual value of the data bus
146 // vpTRACE("Actual data 0x%x = %d\n", data, data);
147
148 data = data | mask_pulse_d1 | mask_mode_pulse_d3;
149 // vpTRACE("Send 0x%x = %d\n", data, data);
150 parport.sendData(data); // send a 0-1 pulse
151
152 // Wait 500 micro seconds
153 struct timeval ti, tc; // Initial and current time
154 gettimeofday(&ti, 0);
155 do {
156 gettimeofday(&tc, 0);
157 } while (tc.tv_usec < ti.tv_usec + time * 1000);
158
159 data = data & (~mask_pulse_d1);
160 // vpTRACE("Send 0x%x = %d\n", data, data);
161 parport.sendData(data); // send a 1-0 pulse
162}
163
171{
172 // Data set by the parallel port:
173 // - D1: 0 to turn OFF, 1 to turn ON
174 // - D2: 1 }
175 // - D3: 0 } To control the light throw D1
176 // D2 and D3 are used to select the multiplexer output.
177 // Light must be connected to output 1+,1-
178
179 // To activates the light we send a pulse
180 int mask_mode_onoff_d2 = 0x04; // D2 is Hight
181 int mask_on_d1 = 0x02; // D1 is Hight to turn the light on
182 unsigned char data = 0x00;
183 // data = parport.getData(); // actual value of the data bus
184
185 data = data | mask_on_d1 | mask_mode_onoff_d2;
186 // vpTRACE("Send 0x%x = %d\n", data, data);
187 parport.sendData(data);
188}
189
197{
198 // Data set by the parallel port:
199 // - D1: 0 to turn OFF, 1 to turn ON
200 // - D2: 1 }
201 // - D3: 0 } To control the light throw D1
202 // D2 and D3 are used to select the multiplexer output.
203 // Light must be connected to output 1+,1-
204
205 // To activates the light we send a pulse
206 int mask_mode_onoff_d2 = 0x04; // D2 is Hight
207 int mask_off_d1 = 0x00; // D1 is Low to turn the light off
208 unsigned char data = 0x00;
209 // data = parport.getData(); // actual value of the data bus
210
211 data = data | mask_off_d1 | mask_mode_onoff_d2;
212 // vpTRACE("Send 0x%x = %d\n", data, data);
213 parport.sendData(data);
214}
215
216#elif !defined(VISP_BUILD_SHARED_LIBS)
217// Work around to avoid warning: libvisp_robot.a(vpRingLight.cpp.o) has no
218// symbols
219void dummy_vpRingLight(){};
220#endif
void sendData(unsigned char &data)
virtual ~vpRingLight()