Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpRingLight.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Ring light management.
32  *
33  * Authors:
34  * Fabien Spindler
35  *
36  *****************************************************************************/
37 
38 
39 #include <visp3/core/vpConfig.h>
40 
41 #if defined(VISP_HAVE_MODULE_IO) && defined(VISP_HAVE_PARPORT)
42 
43 # include <sys/types.h>
44 # include <sys/stat.h>
45 # include <fcntl.h>
46 # include <sys/ioctl.h>
47 # include <sys/time.h>
48 # include <unistd.h>
49 
50 # include <visp3/robot/vpRingLight.h>
51 # include <visp3/core/vpDebug.h>
52 # include <visp3/core/vpTime.h>
53 
74 {
75  off();
76 }
77 
87 {
88  off();
89 }
90 
99 {
100  // Data set by the parallel port:
101  // - D1: need to send a 500us pulse width
102  // - D2: 0 }
103  // - D3: 0 } To control the light throw the NE555
104  // D2 and D3 are used to select the multiplexer output.
105  // Light must be connected to output 1+,1-
106 
107  // To activates the light we send a pulse
108  int mask_mode_pulse_d2 = 0x00; // D2 is low
109  int mask_pulse_d1 = 0x02; // we send a pulse on D1 : L, H, L
110  unsigned char data = 0x00;
111  // data = parport.getData(); // actual value of the data bus
112  // vpTRACE("Actual data 0x%x = %d\n", data, data);
113 
114  data = data | mask_pulse_d1 | mask_mode_pulse_d2;
115  //vpTRACE("Send 0x%x = %d\n", data, data);
116  parport.sendData(data); // send a 0-1 pulse
117 
118  // Wait 500 micro seconds
119  struct timeval ti, tc; // Initial and current time
120  struct timeval tempo;
121  tempo.tv_usec = 500;
122  gettimeofday(&ti,0L);
123  do {
124  gettimeofday(&tc,0L);
125  } while (tc.tv_usec < ti.tv_usec + tempo.tv_usec);
126 
127  data = data & (~mask_pulse_d1);
128  //vpTRACE("Send 0x%x = %d\n", data, data);
129  parport.sendData(data); // send a 1-0 pulse
130 }
131 
141 void vpRingLight::pulse(double time)
142 {
143  // Data set by the parallel port:
144  // - D1: a pulse with duration fixed by time
145  // - D2: 0 }
146  // - D3: 1 } To control the light directly throw the pulse comming from D1
147  // D2 and D3 are used to select the multiplexer output.
148  // Light must be connected to output 1+,1-
149 
150  // To activates the light we send a pulse
151  int mask_mode_pulse_d3 = 0x08; // D3 is hight, D2 is low
152  int mask_pulse_d1 = 0x02; // we send a pulse on D1 : L, H, L
153  unsigned char data = 0x00;
154  // data = parport.getData(); // actual value of the data bus
155  // vpTRACE("Actual data 0x%x = %d\n", data, data);
156 
157  data = data | mask_pulse_d1 | mask_mode_pulse_d3;
158  //vpTRACE("Send 0x%x = %d\n", data, data);
159  parport.sendData(data); // send a 0-1 pulse
160 
161  // Wait 500 micro seconds
162  struct timeval ti, tc; // Initial and current time
163  gettimeofday(&ti,0);
164  do {
165  gettimeofday(&tc,0);
166  } while (tc.tv_usec < ti.tv_usec + time*1000);
167 
168  data = data & (~mask_pulse_d1);
169  //vpTRACE("Send 0x%x = %d\n", data, data);
170  parport.sendData(data); // send a 1-0 pulse
171 }
172 
180 {
181  // Data set by the parallel port:
182  // - D1: 0 to turn OFF, 1 to turn ON
183  // - D2: 1 }
184  // - D3: 0 } To control the light throw D1
185  // D2 and D3 are used to select the multiplexer output.
186  // Light must be connected to output 1+,1-
187 
188  // To activates the light we send a pulse
189  int mask_mode_onoff_d2 = 0x04; // D2 is Hight
190  int mask_on_d1 = 0x02; // D1 is Hight to turn the light on
191  unsigned char data = 0x00;
192  //data = parport.getData(); // actual value of the data bus
193 
194  data = data | mask_on_d1 | mask_mode_onoff_d2;
195  //vpTRACE("Send 0x%x = %d\n", data, data);
196  parport.sendData(data);
197 }
198 
206 {
207  // Data set by the parallel port:
208  // - D1: 0 to turn OFF, 1 to turn ON
209  // - D2: 1 }
210  // - D3: 0 } To control the light throw D1
211  // D2 and D3 are used to select the multiplexer output.
212  // Light must be connected to output 1+,1-
213 
214  // To activates the light we send a pulse
215  int mask_mode_onoff_d2 = 0x04; // D2 is Hight
216  int mask_off_d1 = 0x00; // D1 is Low to turn the light off
217  unsigned char data = 0x00;
218  //data = parport.getData(); // actual value of the data bus
219 
220  data = data | mask_off_d1 | mask_mode_onoff_d2;
221  //vpTRACE("Send 0x%x = %d\n", data, data);
222  parport.sendData(data);
223 }
224 
225 #elif !defined(VISP_BUILD_SHARED_LIBS)
226 // Work arround to avoid warning: libvisp_robot.a(vpRingLight.cpp.o) has no symbols
227 void dummy_vpRingLight() {};
228 #endif
void pulse()
Definition: vpRingLight.cpp:98
void sendData(unsigned char &data)