MyroC Project: MyroC-utilities-with-getcurrentDirectory.h Source File

MyroC Project Package to control Scribbler 2 robots via Bluetooth

MyroC-utilities-with-getcurrentDirectory.h
1 /* * * * * * * * * * * * * * * * * * * * * *
2 * @file MyroC-utilities.h
3 * @brief Header for implementation utilities used by several MyroC functions
4 *
5 * helper functions for an individual user function are included in the
6 * implementation file for that function
7 *
8 * Revision History
9 *
10 * Version 1.0 based on a C++ package by April O'Neill, David Cowden,
11 * Dilan Ustek, Erik Opavsky, and Henry M. Walker
12 *
13 * Developers of the C package for Linux:
14 * Creators Version 2.0 (C functions for utilities,general,sensors,movement):
15 * Spencer Liberto
16 * Dilan Ustek
17 * Jordan Yuan
18 * Henry M. Walker
19 * Contributors Version 2.2-2.3: (C functions for image processing)
20 * Anita DeWitt
21 * Jason Liu
22 * Nick Knoebber
23 * Vasilisa Bashlovkina
24 * Revision for Version 2.4: (image row/column made to match matrix notation)
25 * Henry M. Walker
26 *
27 * Revisions for Version 3.0
28 * Henry M. Walker
29 *
30 * C ported to Macintosh
31 * Linux/Mac differences required for connections — otherwise same code
32 * OpenGL used to display images, replacing ImageMagick
33 * same [new] code used for both Linux and Macintosh
34 * 1 process for robot control
35 * 1 process needed for each titled window (not each image, as in 2.2-2.4)
36 * Blocking options (negative duration parameter)
37 * utilize separate thread timer
38 * MyroC implementation files organized by user function as follows:
39 *
40 * Revisions for Version 3.1
41 * Henry M. Walker
42 *
43 * Picture struct and image functions revised to allow
44 * 192 by 256 images from origial Fluke camera
45 * 266 x 427 low-resolution images from Fluke 2
46 * (high-resolution (800 x 1280) too large for more than 2-4
47 * variables on run-time stack)
48 * storage , retrieval, and display of any images up to 266 x 427
49 *
50 * Revisions for Version 3.2
51 * Henry M. Walker
52 *
53 * Practical range of rBeep duration identified as <= 3.0014 seconds
54 * Image display and processing resolves several matters and adds functionality
55 * function rDisplayPicture completely rewritten
56 * over time OpenGL rountines had encountered troubles
57 * on Linux, specifically glutHideWindow() hid images, but could not be
58 * restored, with difficulties depending on the graphics card
59 * on Mac, High Sierra generated compile warnings and
60 * restricted threads that could display images
61 * function rDisplayImageProcessingErrors added
62 * function rWaitTimedImageDisplay updated substantially
63 *
64 * This program and all MyroC software is licensed under the Creative Commons
65 * Attribution-Noncommercial-Share Alike 3.0 United States License.
66 * Details available at http://creativecommons.org/licenses/by-nc-sa/3.0/us/
67 *
68 ********************** implementation overview *************************
69
70 0. LOW-LEVEL UTILITY (prototypes in MyroC-utilities.h
71 implemented in * MyroC-connect.c)
72 > rSend
73 > rReceive
74 > rSetOpeningExchange
75 > rSetBluetoothEcho
76 > rSetEchoMode
77 > rCheckHardwareVersionSetCameraSize
78
79 1. GENERAL (mostly MyroC-general.c) 2. SENSOR (MyroC-sensors.c)
80 > rConnect (* MyroC-connect.c) a.Scribbler Sensors
81 > rDisconnect (* MyroC-connect.c) rGetLightsAll
82 rSetConnection rGetLightTxt
83 rFinishProcessing rGetIRAll
84 rSetVolume rGetIRTxt
85 rBeep rGetLine
86 rBeep2
87 rSetName b.Fluke Sensors
88 rGetName rGetObstacleAll
89 rSetForwardness rGetObstacleTxt
90 rGetForwardness rGetBrightAll
91 rSetLEDFront rGetBrightTxt
92 rSetLEDBack rSetIRPower
93 rGetBattery
94 rGetStall
95
96 Note:
97 * MyroC-connect requires special
98 knowledge of a Mac or Linux
99 environment, yielding two versions:
100 MyroC-connect-mac.c
101 MyroC-connect-linux.c
102
103 3. MOVEMENT (MyroC-movement.c) 4. PICTURES (files as indicated)
104 rTurnLeft rGetCameraSize (MyroC-camera.c)
105 rTurnRight rTakePicture (MyroC-camera.c)
106 rTurnSpeed rDisplayPicture (MyroC-display.c)
107 rForward rDisplayImageProcessingErrors (MyroC-display.c)
108 rFastForward rWaitTimedImageDisplay(MyroC-display.c)
109 rBackward rSavePicture (MyroC-image-file.c)
110 rMotors rLoadPicture (MyroC-image-file.c)
111 rStop
112 rHardStop
113
114
115 ************************************************************************
116 */
117
118 #ifndef _MyroC_utilities
119 #define _MyroC_utilities
120
121
122 /*
123 ************************** macros **************************************
124 */
125
126 #define BYTES_OF_SENSOR_DATA 11
127 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
128 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
129
130 /*
131 ***********************global definitions ******************************
132 */
133
134 /*
135 definitions to specify if Scribbler echoes a command
136 (most or all do)
137 */
138 #define ECHO_COMMAND_ON 1
139 #define ECHO_COMMAND_OFF 0
140
141 /*
142 flags to specify if Scribbler echoes all sensor data
143 */
144 #define ECHO_SENSOR_ON 1
145 #define ECHO_SENSOR_OFF 0
146
147 // definitions for Bluetooth communications with sockets
148 // basic
149 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
150 // set following variable to the directory of the image handler (e.g., /usr/local/bin)
151 #define DIRECTORY_FOR_IMAGE_HANDLER /usr/local/bin
152 #include <winsock2.h>
153 #include <ws2bth.h>
154 #define SOCKET_TYPE SOCKET
155 // current socket used for Bluetooth communications
156 extern SOCKET_TYPE socket_num; // a Windows 10 SOCKET is a long, long int
157
158 #else
159 #define SOCKET_TYPE int
160 // current socket used for Bluetooth communications
161 extern SOCKET_TYPE socket_num;
162 #endif
163
164 /* ********************** Declarations for MyroC internals ****************
165 */
166 #include <pthread.h>
167
171 typedef struct
172 {
173 SOCKET_TYPE robot_socket_num;
174 int camera_height;
175 int camera_width;
176 char * fluke_type; /* values: "unknown", robot not yet consulted
177 "unecognized", query gave neither Fluke 1/2
178 "original fluke"
179 "Fluke 2"
180 */
181 int motion_seq_num;
182 pthread_t thread_motion_timer_id;
183 } robot_motion_camera_record;
184
188 typedef struct
189 {
190 double duration_time;
191 SOCKET_TYPE robot_socket_num;
192 int motion_seq_num;
193 } motion_timing_data;
194
195
196 /*
197 ************************ global variables ******************************
198
199 variables identifed as external here; variables allocated in MyroC-utilities.c
200 */
201
202 /* version specification
203 */
204 extern char * version;
205 extern int version_printed; // 0 - version not yet printed; 1 - version printed
206
207 // baudrate for Bluetooth communication
208 extern const int baudrate; // = 38400;
209
210 // debug flag for communications
211 extern int debug; // 1 == echo all communications; 0 no extra printing
212
213 // allow beeps and data exchange during opening connect
214 extern int followOpeningExchange; // 1==robot beeps, exchanges data at connect;
215 // 0==no beeps or data exchange
216
217 extern pthread_mutex_t bluetooth_lock; // mutex to prevent concurrent
218 // communication over
219 // socket for robot communication
220
221 /*
222 variables for counting motion commands per robot, based on socket number
223 variables referenced in connections (rConnect, rDisconnect) and motion commands
224 variable for whether or not to display error messages from image processes
225 */
226
227 #define max_number_robots 20
228
229 extern int current_num_robots;
230
231 extern int displayImageErrors;
232
233 extern robot_motion_camera_record robot_sock_array [];
234
235 /*
236 ************************ utility procedures ****************************
237 */
238
248 void rSend_protected (char message[], int numberOfBytes, int echo,
249 int sensor_echo, char * commandText);
250
260 void rSend (char message[], int numberOfBytes, int echo,
261 int sensor_echo, char * commandText);
262
269 void rReceive (unsigned char * message, int numberOfBytes);
270
278 void rSetOpeningExchange (char onOff);
279
288 void rSetEchoMode (char onOff);
289
296 void rCheckHardwareVersionSetCameraSize (char printYorN);
297
307 void rSetCameraSize (char * resolution);
308
322 const char * rGetCameraSize (int *height, int *width);
323
336 const char * rGetCameraSize (int *height, int *width);
337
338 #endif
339
motion_timing_data
Definition: MyroC-utilities-with-getcurrentDirectory.h:188
robot_motion_camera_record
Definition: MyroC-utilities-with-getcurrentDirectory.h:171