-
Notifications
You must be signed in to change notification settings - Fork 0
/
camviz.gen
144 lines (121 loc) · 5.63 KB
/
camviz.gen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*/
* Copyright (c) 2020 LAAS/CNRS
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice and this list of conditions.
* 2. Redistributions in binary form must reproduce the above copyright
* notice and this list of conditions in the documentation and/or
* other materials provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Martin Jacquet - September 2020
*/
/* ---- Includes ---------------------------------------------------------- */
#pragma require "openrobots2-idl >= 2.0"
#pragma require "vision-idl"
#include "or/sensor/camera.gen"
#include "or/sensor/pixel.idl"
/* ---- Component declaration --------------------------------------------- */
component camviz {
version "1.0";
email "martin.jacquet@laas.fr";
lang "c";
require "genom3 >= 2.99.26";
codels-require "opencv";
/* ---- Exceptions ---------------------------------------------------- */
exception e_sys { short code; string<64> what; };
/* ---- Ports --------------------------------------------------------- */
port multiple in or::sensor::frame frame;
port multiple in or::sensor::pixel pixel;
/* ---- Types --------------------------------------------------------- */
native recorder;
typedef string<64> port_info;
struct pixel_info_s {
port_info name;
sequence<octet,3> color;
};
struct camera_s {
port_info name;
recorder rec;
sequence<pixel_info_s> pixels;
unsigned short orientation; // orientation of image to display
};
/* ---- IDS ----------------------------------------------------------- */
ids {
sequence<camera_s> cameras;
float ratio; // rescaling ratio, 0 is not showing
string<64> prefix; // recording file prefix, '\0' is no record
unsigned short pix_size; // size of pixels to display
};
/* ---- Display task -------------------------------------------------- */
task main {
period 40 ms;
throw e_sys;
codel<start> viz_start(out ::ids)
yield ether;
};
/* ---- Services ------------------------------------------------------ */
activity add_camera(in string<64> port_name = : "Frame input subport") {
doc "Starts the monitoring of a given camera frame stream.";
task main;
local unsigned short cam_id;
codel<start> camera_start(in port_name, out cameras, out cam_id)
yield main;
codel<main> camera_main(in cam_id, in prefix, in ratio, in frame, in pixel, inout cameras, in pix_size)
yield pause::main;
codel<stop> camera_stop(in cam_id, out cameras)
yield ether;
};
attribute show(in ratio = 1 : "Ratio of image display") {
doc "Set display ratio. Set to 0 to disable display.";
throw e_sys;
validate display_validate(local in ratio);
};
attribute record(in prefix = : "Prefix of recording files") {
doc "Set recording prefix ratio, eg the path of the target folder.";
doc "Video file names are automatically set to the name of the cameras.";
doc "Env variables or ~ are not recognized.";
};
function stop_rec() {
doc "Stops the recording of videos.";
codel stop_rec(out prefix, out cameras);
};
activity add_pixel_display(in string<64> pixel_name = : "Name of the pixel input port",
in string<64> cam_name = : "Name of camera for the display",
in sequence<octet,3> color = {255,0,0} : "Color of pixel to display (RGB)") {
doc "Add a subport to the pixels subport, in order to display it in the frame.";
task main;
throw e_sys;
codel<start> add_pixel(in pixel_name, in cam_name, in color, inout cameras)
yield ether;
};
function remove_pixel_display(in string<64> pixel_name = : "Name of the pixel input port",
in string<64> cam_name = : "Name of camera for the display") {
doc "Remove a pixel to the list of pixels to display in the frame.";
throw e_sys;
codel remove_pixel(in pixel_name, in cam_name, inout cameras);
};
attribute set_pix_size(in pix_size = 3 : "(Positive) size of displayed pixel (radius of dot)");
function set_orientation(in string<64> cam_name = : "Name of camera for the orientation",
in unsigned short orientation = 0 : "0: 0°; 1: 90°; 2: 180°; 3: 270°") {
doc "Set the rotation (clockwise) to apply to image before display.";
codel set_orientation(in cam_name, in orientation, out cameras);
throw e_sys;
};
function stop() {
doc "Stops current running monitoring activities";
interrupt all;
codel stop(out prefix, out ratio);
};
};