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