Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
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 
41 #include <visp3/core/vpConfig.h>
42 
43 #if defined(VISP_HAVE_MODULE_IO) && defined(VISP_HAVE_PARPORT)
44 
45 #include <fcntl.h>
46 #include <sys/ioctl.h>
47 #include <sys/stat.h>
48 #include <sys/time.h>
49 #include <sys/types.h>
50 #include <unistd.h>
51 
52 #include <visp3/core/vpDebug.h>
53 #include <visp3/core/vpTime.h>
54 #include <visp3/robot/vpRingLight.h>
55 
56 BEGIN_VISP_NAMESPACE
71 vpRingLight::vpRingLight() : parport() { off(); }
72 
81 vpRingLight::~vpRingLight() { off(); }
82 
90 void vpRingLight::pulse()
91 {
92  // Data set by the parallel port:
93  // - D1: need to send a 500us pulse width
94  // - D2: 0 }
95  // - D3: 0 } To control the light throw the NE555
96  // D2 and D3 are used to select the multiplexer output.
97  // Light must be connected to output 1+,1-
98 
99  // To activates the light we send a pulse
100  int mask_mode_pulse_d2 = 0x00; // D2 is low
101  int mask_pulse_d1 = 0x02; // we send a pulse on D1 : L, H, L
102  unsigned char data = 0x00;
103  // data = parport.getData(); // actual value of the data bus
104  // vpTRACE("Actual data 0x%x = %d\n", data, data);
105 
106  data = data | mask_pulse_d1 | mask_mode_pulse_d2;
107  // vpTRACE("Send 0x%x = %d\n", data, data);
108  parport.sendData(data); // send a 0-1 pulse
109 
110  // Wait 500 micro seconds
111  struct timeval ti, tc; // Initial and current time
112  struct timeval tempo;
113  tempo.tv_usec = 500;
114  gettimeofday(&ti, 0L);
115  do {
116  gettimeofday(&tc, 0L);
117  } while (tc.tv_usec < ti.tv_usec + tempo.tv_usec);
118 
119  data = data & (~mask_pulse_d1);
120  // vpTRACE("Send 0x%x = %d\n", data, data);
121  parport.sendData(data); // send a 1-0 pulse
122 }
123 
133 void vpRingLight::pulse(double time)
134 {
135  // Data set by the parallel port:
136  // - D1: a pulse with duration fixed by time
137  // - D2: 0 }
138  // - D3: 1 } To control the light directly throw the pulse coming from D1
139  // D2 and D3 are used to select the multiplexer output.
140  // Light must be connected to output 1+,1-
141 
142  // To activates the light we send a pulse
143  int mask_mode_pulse_d3 = 0x08; // D3 is hight, D2 is low
144  int mask_pulse_d1 = 0x02; // we send a pulse on D1 : L, H, L
145  unsigned char data = 0x00;
146  // data = parport.getData(); // actual value of the data bus
147  // vpTRACE("Actual data 0x%x = %d\n", data, data);
148 
149  data = data | mask_pulse_d1 | mask_mode_pulse_d3;
150  // vpTRACE("Send 0x%x = %d\n", data, data);
151  parport.sendData(data); // send a 0-1 pulse
152 
153  // Wait 500 micro seconds
154  struct timeval ti, tc; // Initial and current time
155  gettimeofday(&ti, 0);
156  do {
157  gettimeofday(&tc, 0);
158  } while (tc.tv_usec < ti.tv_usec + time * 1000);
159 
160  data = data & (~mask_pulse_d1);
161  // vpTRACE("Send 0x%x = %d\n", data, data);
162  parport.sendData(data); // send a 1-0 pulse
163 }
164 
171 void vpRingLight::on()
172 {
173  // Data set by the parallel port:
174  // - D1: 0 to turn OFF, 1 to turn ON
175  // - D2: 1 }
176  // - D3: 0 } To control the light throw D1
177  // D2 and D3 are used to select the multiplexer output.
178  // Light must be connected to output 1+,1-
179 
180  // To activates the light we send a pulse
181  int mask_mode_onoff_d2 = 0x04; // D2 is Hight
182  int mask_on_d1 = 0x02; // D1 is Hight to turn the light on
183  unsigned char data = 0x00;
184  // data = parport.getData(); // actual value of the data bus
185 
186  data = data | mask_on_d1 | mask_mode_onoff_d2;
187  // vpTRACE("Send 0x%x = %d\n", data, data);
188  parport.sendData(data);
189 }
190 
197 void vpRingLight::off()
198 {
199  // Data set by the parallel port:
200  // - D1: 0 to turn OFF, 1 to turn ON
201  // - D2: 1 }
202  // - D3: 0 } To control the light throw D1
203  // D2 and D3 are used to select the multiplexer output.
204  // Light must be connected to output 1+,1-
205 
206  // To activates the light we send a pulse
207  int mask_mode_onoff_d2 = 0x04; // D2 is Hight
208  int mask_off_d1 = 0x00; // D1 is Low to turn the light off
209  unsigned char data = 0x00;
210  // data = parport.getData(); // actual value of the data bus
211 
212  data = data | mask_off_d1 | mask_mode_onoff_d2;
213  // vpTRACE("Send 0x%x = %d\n", data, data);
214  parport.sendData(data);
215 }
216 END_VISP_NAMESPACE
217 #elif !defined(VISP_BUILD_SHARED_LIBS)
218 // Work around to avoid warning: libvisp_robot.a(vpRingLight.cpp.o) has no symbols
219 void dummy_vpRingLight() { };
220 #endif