├── .github
├── PULL_REQUEST_TEMPLATE.md
├── dependabot.yml
└── workflows
│ └── main.yml
├── .gitignore
├── LICENSE
├── README.md
├── cob_driver
├── CHANGELOG.rst
├── CMakeLists.txt
└── package.xml
├── cob_light
├── CHANGELOG.rst
├── CMakeLists.txt
├── action
│ └── SetLightMode.action
├── common
│ ├── include
│ │ ├── breathColorMode.h
│ │ ├── breathMode.h
│ │ ├── circleColorMode.h
│ │ ├── colorUtils.h
│ │ ├── concurrentQueue.h
│ │ ├── distApproxMode.h
│ │ ├── fadeColorMode.h
│ │ ├── flashMode.h
│ │ ├── glowColorMode.h
│ │ ├── kitMode.h
│ │ ├── mode.h
│ │ ├── modeExecutor.h
│ │ ├── modeFactory.h
│ │ ├── modeRunner.h
│ │ ├── sequenceMode.h
│ │ ├── serialIO.h
│ │ ├── staticMode.h
│ │ ├── sweepColorMode.h
│ │ ├── turnIndicatorMode.h
│ │ └── xmasMode.h
│ └── src
│ │ ├── modeExecutor.cpp
│ │ ├── modeFactory.cpp
│ │ └── serialIO.cpp
├── msg
│ ├── ColorRGBAArray.msg
│ ├── LightMode.msg
│ ├── LightModes.msg
│ └── Sequence.msg
├── package.xml
├── ros
│ ├── include
│ │ ├── colorO.h
│ │ ├── colorOMarker.h
│ │ ├── colorOSim.h
│ │ ├── iColorO.h
│ │ ├── ms35.h
│ │ └── stageprofi.h
│ ├── scripts
│ │ ├── light_action_test.py
│ │ ├── light_service_test.py
│ │ ├── test.py
│ │ ├── test_sprofi_circle.py
│ │ ├── test_sprofi_modes.py
│ │ └── test_sprofi_part.py
│ └── src
│ │ ├── cob_light.cpp
│ │ ├── colorO.cpp
│ │ ├── colorOMarker.cpp
│ │ ├── colorOSim.cpp
│ │ ├── ms35.cpp
│ │ └── stageprofi.cpp
└── srv
│ ├── SetLightMode.srv
│ └── StopLightMode.srv
├── cob_mimic
├── CHANGELOG.rst
├── CMakeLists.txt
├── action
│ └── SetMimic.action
├── common
│ ├── afraid.mp4
│ ├── angry.mp4
│ ├── asking.mp4
│ ├── blinking.mp4
│ ├── blinking_left.mp4
│ ├── blinking_right.mp4
│ ├── bored.mp4
│ ├── busy.mp4
│ ├── confused.mp4
│ ├── default.jpg
│ ├── default.mp4
│ ├── falling_asleep.mp4
│ ├── happy.mp4
│ ├── laughing.mp4
│ ├── no.mp4
│ ├── original
│ │ ├── afraid.mp4
│ │ ├── angry.mp4
│ │ ├── asking.mp4
│ │ ├── blinking.mp4
│ │ ├── blinking_left.mp4
│ │ ├── blinking_right.mp4
│ │ ├── bored.mp4
│ │ ├── busy.mp4
│ │ ├── confused.mp4
│ │ ├── default.mp4
│ │ ├── falling_asleep.mp4
│ │ ├── happy.mp4
│ │ ├── laughing.mp4
│ │ ├── no.mp4
│ │ ├── sad.mp4
│ │ ├── searching.mp4
│ │ ├── sleeping.mp4
│ │ ├── surprised.mp4
│ │ ├── tired.mp4
│ │ ├── waking_up.mp4
│ │ └── yes.mp4
│ ├── sad.mp4
│ ├── searching.mp4
│ ├── sleeping.jpg
│ ├── sleeping.mp4
│ ├── surprised.mp4
│ ├── tired.mp4
│ ├── waking_up.mp4
│ └── yes.mp4
├── package.xml
├── src
│ ├── mimic_node.cpp
│ └── test_mimic.py
└── srv
│ └── SetMimic.srv
├── cob_phidgets
├── CHANGELOG.rst
├── CMakeLists.txt
├── common
│ ├── include
│ │ └── cob_phidgets
│ │ │ ├── phidget.h
│ │ │ └── phidgetik.h
│ └── src
│ │ ├── phidget.cpp
│ │ └── phidgetik.cpp
├── msg
│ ├── AnalogSensor.msg
│ └── DigitalSensor.msg
├── package.xml
├── ros
│ ├── include
│ │ └── cob_phidgets
│ │ │ ├── phidget_manager.h
│ │ │ └── phidgetik_ros.h
│ └── src
│ │ ├── cob_phidgets_sim_node.cpp
│ │ ├── ifkit.c
│ │ ├── phidget_manager.cpp
│ │ ├── phidget_sensors_node.cpp
│ │ ├── phidgetik_ros.cpp
│ │ ├── phidgets_range_sensors.cpp
│ │ ├── set_device_name.cpp
│ │ ├── simulated_range_sensors.py
│ │ └── tablet_leer.c
└── srv
│ ├── SetDataRate.srv
│ ├── SetDigitalSensor.srv
│ └── SetTriggerValue.srv
├── cob_scan_unifier
├── CHANGELOG.rst
├── CMakeLists.txt
├── README.md
├── include
│ └── cob_scan_unifier
│ │ └── scan_unifier_node.h
├── package.xml
└── src
│ └── scan_unifier_node.cpp
├── cob_sick_s300
├── CHANGELOG.rst
├── CMakeLists.txt
├── README.md
├── common
│ ├── include
│ │ └── cob_sick_s300
│ │ │ ├── ScannerSickS300.h
│ │ │ ├── SerialIO.h
│ │ │ └── TelegramS300.h
│ └── src
│ │ ├── ScannerSickS300.cpp
│ │ └── SerialIO.cpp
├── package.xml
└── ros
│ ├── src
│ ├── cob_scan_filter.cpp
│ └── cob_sick_s300.cpp
│ └── test
│ ├── dummy_config.yaml
│ └── dummy_launch.xml
├── cob_sound
├── CHANGELOG.rst
├── CMakeLists.txt
├── action
│ ├── Play.action
│ └── Say.action
├── fix_swift_for_precise.sh
├── package.xml
└── ros
│ └── src
│ ├── sound.cpp
│ └── test_client.py
└── laser_scan_densifier
├── CHANGELOG.rst
├── CMakeLists.txt
├── include
└── laser_scan_densifier
│ ├── laser_scan_densifier.h
│ └── laser_scan_densifier_nodelet.h
├── laser_scan_densifier_nodelet.xml
├── package.xml
└── src
├── laser_scan_densifier.cpp
├── laser_scan_densifier_node.cpp
└── laser_scan_densifier_nodelet.cpp
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | - fixes #
2 | - new source code files added (proper [APACHE license header](https://github.com/ipa320/setup/tree/master/templates) **must** be used)
3 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | ---
2 | version: 2
3 | updates:
4 | - package-ecosystem: "github-actions"
5 | directory: "/"
6 | schedule:
7 | interval: "weekly"
8 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: GHA CI
2 |
3 | on:
4 | push:
5 | pull_request:
6 | schedule:
7 | - cron: "0 0 * * 0" # every Sunday at midnight
8 | workflow_dispatch:
9 |
10 | jobs:
11 | industrial_ci:
12 | name: GHA CI
13 | runs-on: ubuntu-latest
14 | timeout-minutes: 60
15 |
16 | env:
17 | ADDITIONAL_DEBS: 'apt-utils dialog git'
18 | CATKIN_LINT: pedantic
19 | CATKIN_LINT_ARGS: '--ignore description_boilerplate'
20 | CMAKE_ARGS: -DCMAKE_BUILD_TYPE=Release
21 | PYLINT_ARGS: '--output-format=parseable --errors-only'
22 | PYLINT_CHECK: true
23 | ROS_REPO: main
24 |
25 | strategy:
26 | matrix:
27 | include:
28 | - { ROS_DISTRO: noetic }
29 |
30 | steps:
31 | - uses: actions/checkout@v5
32 | with:
33 | submodules: true
34 | lfs: true
35 | ssh-known-hosts: ''
36 |
37 | - uses: ros-industrial/industrial_ci@master
38 | with:
39 | config: ${{toJSON(matrix)}}
40 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # default .gitignore file for ipa320 repositories
2 | # master file can be found in https://github.com/ipa320/care-o-bot/blob/indigo_dev/.gitignore
3 |
4 | build/
5 | bin/
6 | lib/
7 |
8 | # generated docs
9 | *.dox
10 | *.wikidoc
11 |
12 | # eclipse
13 | .project
14 | .cproject
15 |
16 | # qcreator
17 | qtcreator-*
18 | *.user
19 |
20 | # Emacs
21 | .#*
22 |
23 | # VI/VIM
24 | *.swp
25 |
26 | # python files
27 | *.pcd
28 | *.pyc
29 | *.pco
30 |
31 | # temporary files
32 | *~
33 |
34 | # merge conflict files
35 | *.orig
36 | *BACKUP*
37 | *BASE*
38 | *LOCAL*
39 | *REMOTE*
40 |
41 | # Catkin custom files
42 | CATKIN_IGNORE
43 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | cob_driver
2 | ===========
3 |
4 | ## GitHub Actions - Continuous Integration
5 |
6 | CI-Status ```noetic-devel```: [](https://github.com/4am-robotics/cob_driver/actions/workflows/main.yml?query=branch%3Anoetic-devel)
7 |
--------------------------------------------------------------------------------
/cob_driver/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0.2)
2 | project(cob_driver)
3 | find_package(catkin REQUIRED)
4 | catkin_metapackage()
5 |
--------------------------------------------------------------------------------
/cob_driver/package.xml:
--------------------------------------------------------------------------------
1 |
2 | cob_driver
3 | 0.8.18
4 | The cob_driver stack includes packages that provide access to the Care-O-bot hardware through ROS messages, services and actions. E.g. for mobile base, arm, camera sensors, laser scanners, etc...
5 |
6 | Apache 2.0
7 |
8 | http://ros.org/wiki/cob_driver
9 |
10 |
11 | Felix Messmer
12 | Florian Weisshardt
13 |
14 | catkin
15 |
16 | cob_light
17 | cob_mimic
18 | cob_phidgets
19 | cob_scan_unifier
20 | cob_sick_s300
21 | cob_sound
22 | laser_scan_densifier
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/cob_light/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.0.2)
2 | project(cob_light)
3 |
4 | add_compile_options(-std=c++11)
5 |
6 | find_package(catkin REQUIRED COMPONENTS
7 | actionlib
8 | actionlib_msgs
9 | diagnostic_msgs
10 | message_generation
11 | roscpp
12 | sensor_msgs
13 | std_msgs
14 | visualization_msgs)
15 |
16 | find_package(Boost REQUIRED COMPONENTS thread)
17 |
18 | ### Message Generation ###
19 | add_message_files(
20 | FILES
21 | ColorRGBAArray.msg
22 | LightMode.msg
23 | LightModes.msg
24 | Sequence.msg
25 | )
26 |
27 | add_service_files(
28 | FILES
29 | SetLightMode.srv
30 | StopLightMode.srv
31 | )
32 |
33 | add_action_files(
34 | FILES
35 | SetLightMode.action
36 | )
37 |
38 | generate_messages(
39 | DEPENDENCIES actionlib_msgs sensor_msgs std_msgs visualization_msgs
40 | )
41 |
42 | catkin_package(
43 | CATKIN_DEPENDS actionlib actionlib_msgs diagnostic_msgs message_runtime roscpp sensor_msgs std_msgs visualization_msgs
44 | )
45 |
46 | ### BUILD ###
47 | #pkg_check_modules(GTKMM REQUIRED gtkmm-3.0)
48 | #pkg_check_modules(GTHREAD REQUIRED gthread-2.0)
49 |
50 | add_compile_options(-Wno-narrowing)
51 |
52 | include_directories(${PROJECT_SOURCE_DIR}/ros/include ${PROJECT_SOURCE_DIR}/common/include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
53 | set(HEADERS
54 | ${PROJECT_SOURCE_DIR}/common/include/breathColorMode.h
55 | ${PROJECT_SOURCE_DIR}/common/include/breathMode.h
56 | ${PROJECT_SOURCE_DIR}/common/include/circleColorMode.h
57 | ${PROJECT_SOURCE_DIR}/common/include/colorUtils.h
58 | ${PROJECT_SOURCE_DIR}/common/include/concurrentQueue.h
59 | ${PROJECT_SOURCE_DIR}/common/include/fadeColorMode.h
60 | ${PROJECT_SOURCE_DIR}/common/include/flashMode.h
61 | ${PROJECT_SOURCE_DIR}/common/include/mode.h
62 | ${PROJECT_SOURCE_DIR}/common/include/modeExecutor.h
63 | ${PROJECT_SOURCE_DIR}/common/include/modeFactory.h
64 | ${PROJECT_SOURCE_DIR}/common/include/modeRunner.h
65 | ${PROJECT_SOURCE_DIR}/common/include/sequenceMode.h
66 | ${PROJECT_SOURCE_DIR}/common/include/serialIO.h
67 | ${PROJECT_SOURCE_DIR}/common/include/staticMode.h
68 | ${PROJECT_SOURCE_DIR}/common/include/sweepColorMode.h
69 | ${PROJECT_SOURCE_DIR}/common/include/distApproxMode.h
70 | ${PROJECT_SOURCE_DIR}/common/include/xmasMode.h
71 | ${PROJECT_SOURCE_DIR}/common/include/kitMode.h
72 | ${PROJECT_SOURCE_DIR}/common/include/turnIndicatorMode.h
73 | ${PROJECT_SOURCE_DIR}/ros/include/colorO.h
74 | ${PROJECT_SOURCE_DIR}/ros/include/colorOMarker.h
75 | ${PROJECT_SOURCE_DIR}/ros/include/colorOSim.h
76 | ${PROJECT_SOURCE_DIR}/ros/include/iColorO.h
77 | ${PROJECT_SOURCE_DIR}/ros/include/ms35.h
78 | ${PROJECT_SOURCE_DIR}/ros/include/stageprofi.h
79 | )
80 |
81 |
82 | add_executable(${PROJECT_NAME}
83 | common/src/modeExecutor.cpp
84 | common/src/modeFactory.cpp
85 | common/src/serialIO.cpp
86 | ros/src/${PROJECT_NAME}.cpp
87 | ros/src/colorO.cpp
88 | ros/src/colorOMarker.cpp
89 | ros/src/colorOSim.cpp
90 | ros/src/ms35.cpp
91 | ros/src/stageprofi.cpp)
92 | add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
93 | target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${Boost_LIBRARIES})
94 |
95 | ### INSTALL ###
96 | install(TARGETS ${PROJECT_NAME}
97 | ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
98 | LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
99 | RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
100 | )
101 |
102 | catkin_install_python(PROGRAMS
103 | ros/scripts/test.py
104 | ros/scripts/test_sprofi_circle.py
105 | ros/scripts/test_sprofi_modes.py
106 | ros/scripts/test_sprofi_part.py
107 | ros/scripts/light_action_test.py
108 | ros/scripts/light_service_test.py
109 | DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
110 | )
111 |
--------------------------------------------------------------------------------
/cob_light/action/SetLightMode.action:
--------------------------------------------------------------------------------
1 | # The goal
2 | cob_light/LightMode mode
3 | ---
4 | # The results
5 | uint8 active_mode
6 | uint8 active_priority
7 | uint64 track_id
8 | ---
9 | # The feedback
10 | uint8 active_mode
11 | uint8 active_priority
12 |
--------------------------------------------------------------------------------
/cob_light/common/include/breathColorMode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #ifndef BREATHCOLORMODE_H
19 | #define BREATHCOLORMODE_H
20 |
21 | #include
22 |
23 | class BreathColorMode : public Mode
24 | {
25 | public:
26 | BreathColorMode(color::rgba color, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0)
27 | :Mode(priority, freq, pulses, timeout), _timer_inc(0.0)
28 | {
29 | _color = color;
30 | h = 0.0;
31 | _inc = ((M_PI*2) / UPDATE_RATE_HZ) * _freq;
32 | }
33 |
34 | void execute()
35 | {
36 | float r = 0;
37 | float g = 0;
38 | float b = 0;
39 |
40 | color::Color::hsv2rgb(h, 1.0, 1.0, r, g, b);
41 |
42 | h += 0.001;
43 | if(h > 1.0) h = 0.0;
44 |
45 | //double fV = (exp(sin(_timer_inc))-1.0/M_E)*(1.000/(M_E-1.0/M_E));
46 | double fV = (exp(sin(_timer_inc))-0.36787944)*0.42545906411;
47 |
48 | _timer_inc += _inc;
49 | if(_timer_inc >= M_PI*2)
50 | {
51 | _timer_inc = 0.0;
52 | _pulsed++;
53 | }
54 |
55 | color::rgba col;
56 | col.r = r;
57 | col.g = g;
58 | col.b = b;
59 | col.a = fV;
60 |
61 | m_sigColorReady(col);
62 | }
63 |
64 | std::string getName(){ return std::string("BreathColorMode"); }
65 |
66 | private:
67 | double _timer_inc;
68 | double _inc;
69 | float h;
70 | };
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/cob_light/common/include/breathMode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #ifndef BREATHMODE_H
19 | #define BREATHMODE_H
20 |
21 | #include
22 |
23 | class BreathMode : public Mode
24 | {
25 | public:
26 | BreathMode(color::rgba color, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0)
27 | :Mode(priority, freq, pulses, timeout), _timer_inc(0.0)
28 | {
29 | _color = color;
30 | _init_color = color;
31 | _inc = ((M_PI*2) / UPDATE_RATE_HZ) * _freq;
32 | }
33 |
34 | void execute()
35 | {
36 | //double fV = (exp(sin(_timer_inc))-1.0/M_E)*(1.000/(M_E-1.0/M_E));
37 | double fV = (exp(-cos(_timer_inc))-0.36787944)*0.42545906411;
38 |
39 | _timer_inc += _inc;
40 | if(_timer_inc >= M_PI*2)
41 | {
42 | _timer_inc = 0.0;
43 | _pulsed++;
44 | }
45 |
46 | _color.a = fV * _init_color.a;
47 | _color.a = _color.a > 1 ? 1 : _color.a < 0 ? 0 : _color.a;
48 |
49 | m_sigColorReady(_color);
50 | }
51 |
52 | std::string getName(){ return std::string("BreathMode"); }
53 |
54 | private:
55 | double _timer_inc;
56 | double _inc;
57 | };
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/cob_light/common/include/circleColorMode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #ifndef CIRCLECOLORMODE_H
19 | #define CIRCLECOLORMODE_H
20 |
21 | #include
22 | #include
23 |
24 | class CircleColorMode : public Mode
25 | {
26 | public:
27 | CircleColorMode(std::vector colors, size_t num_leds, int priority = 0, double freq = 5, int pulses = 0, double timeout = 0)
28 | :Mode(priority, freq, pulses, timeout), _toggle(false), _timer_inc(0), _num_leds(num_leds)
29 | {
30 | _colors = colors;
31 | _colors.resize(num_leds);
32 | if(_pulses != 0)
33 | {
34 | _pulses *=2;
35 | _pulses +=1;
36 | }
37 | _inc = (1. / UPDATE_RATE_HZ) * _freq;
38 | }
39 |
40 | void execute()
41 | {
42 | if(_timer_inc >= 1.0)
43 | {
44 | std::rotate(_colors.begin(), _colors.begin()+1, _colors.end());
45 | _pulsed++;
46 | m_sigColorsReady(_colors);
47 | _timer_inc = 0.0;
48 | }
49 | else
50 | _timer_inc += _inc;
51 | }
52 |
53 | std::string getName(){ return std::string("CircleColorMode"); }
54 |
55 | private:
56 | bool _toggle;
57 | double _timer_inc;
58 | double _inc;
59 | size_t _num_leds;
60 | };
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/cob_light/common/include/colorUtils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #ifndef COLOR_UTILS_H
19 | #define COLOR_UTILS_H
20 |
21 | #include
22 | #include
23 |
24 | namespace color
25 | {
26 | struct rgba
27 | {
28 | rgba(): r(0.0), g(0.0), b(0.0), a(0.0) {}
29 | float r;
30 | float g;
31 | float b;
32 | float a;
33 | };
34 |
35 | struct rgb
36 | {
37 | rgb(): r(0.0), g(0.0), b(0.0){}
38 | float r;
39 | float g;
40 | float b;
41 | };
42 |
43 | struct hsv
44 | {
45 | hsv(): h(0.0), s(0.0), v(0.0) {}
46 | float h;
47 | float s;
48 | float v;
49 | };
50 |
51 | class Color
52 | {
53 | public:
54 | static void rgb2hsv (float r, float g, float b, float &h, float &s, float &v)
55 | {
56 | double var_R = r;
57 | double var_G = g;
58 | double var_B = b;
59 |
60 | double var_Min = std::min(std::min(var_R,var_G),var_B);
61 | double var_Max = std::max(std::max(var_R,var_G),var_B);
62 | double del_Max = var_Max - var_Min;
63 | v = var_Max;
64 | if (fabs(del_Max)<0.00001) {
65 | h = 0;
66 | s = 0;
67 | }
68 | else {
69 | s = del_Max/var_Max;
70 |
71 | if ( var_R == var_Max ) h = (var_G - var_B)/del_Max;
72 | else if ( var_G == var_Max ) h = 2.0 + (var_B - var_R)/del_Max;
73 | else if ( var_B == var_Max ) h = 4.0 + (var_R - var_G)/del_Max;
74 | h /= 6.0;
75 |
76 | if ( h < 0 ) h += 1;
77 | if ( h > 1 ) h -= 1;
78 | }
79 | }
80 |
81 | static void hsv2rgb (float h, float s, float v, float &r, float &g, float &b)
82 | {
83 | float h1 = h*6; // sector 0 to 5
84 | int i = floor( h1 );
85 | float f = h1 - i; // fractional part of h
86 |
87 | float p = v * ( 1 - s );
88 | float q = v * ( 1 - s * f );
89 | float t = v * ( 1 - s * ( 1 - f ) );
90 |
91 | if (i==0) {r = v; g = t; b = p;}
92 | else if (i==1) {r = q; g = v; b = p;}
93 | else if (i==2) {r = p; g = v; b = t;}
94 | else if (i==3) {r = p; g = q; b = v;}
95 | else if (i==4) {r = t; g = p; b = v;}
96 | else if (i==5) {r = v; g = p; b = q;}
97 | }
98 |
99 | static float linearInterpolate(float a, float b, float t)
100 | {
101 | return a * (1 - t) + b * t;
102 | }
103 |
104 | static color::rgba interpolateColor(color::rgba start, color::rgba goal, float t)
105 | {
106 | color::hsv ca;
107 | color::hsv cb;
108 | color::hsv cr;
109 | color::rgba a, b;
110 | a = start;
111 | b = goal;
112 |
113 | a.r *= a.a;
114 | a.g *= a.a;
115 | a.b *= a.a;
116 | b.r *= b.a;
117 | b.g *= b.a;
118 | b.b *= b.a;
119 | color::Color::rgb2hsv(a.r, a.g, a.b, ca.h, ca.s, ca.v);
120 | color::Color::rgb2hsv(b.r, b.g, b.b, cb.h, cb.s, cb.v);
121 |
122 | cr.h = linearInterpolate(ca.h, cb.h, t);
123 | cr.s = linearInterpolate(ca.s, cb.s, t);
124 | cr.v = linearInterpolate(ca.v, cb.v, t);
125 |
126 | color::rgba result;
127 | color::Color::hsv2rgb(cr.h, cr.s, cr.v, result.r, result.g, result.b);
128 | result.a = 1.0;
129 |
130 | return result;
131 | }
132 | };
133 | }
134 | #endif
135 |
--------------------------------------------------------------------------------
/cob_light/common/include/concurrentQueue.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #include
19 | #include
20 | #include
21 |
22 | template
23 | class ConcurrentQueue
24 | {
25 | private:
26 | boost::circular_buffer _queue;
27 | mutable boost::mutex _mutex;
28 | boost::condition_variable _condition;
29 | public:
30 | ConcurrentQueue()
31 | : _queue(2)
32 | {
33 | }
34 |
35 | bool empty() const
36 | {
37 | boost::mutex::scoped_lock lock(_mutex);
38 | return _queue.empty();
39 | }
40 |
41 | void push(T const& data)
42 | {
43 | boost::mutex::scoped_lock lock(_mutex);
44 | _queue.push_back(data);
45 | lock.unlock();
46 | _condition.notify_one();
47 | }
48 |
49 | bool pop(T& data)
50 | {
51 | boost::mutex::scoped_lock lock(_mutex);
52 | if(_queue.empty())
53 | return false;
54 |
55 | data = _queue.front();
56 | _queue.pop_front();
57 |
58 | return true;
59 | }
60 |
61 | void wait_pop(T& data)
62 | {
63 | boost::mutex::scoped_lock lock(_mutex);
64 | while(_queue.empty())
65 | _condition.wait(lock);
66 |
67 | data=_queue.front();
68 | _queue.pop_front();
69 | }
70 | };
71 |
--------------------------------------------------------------------------------
/cob_light/common/include/distApproxMode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #ifndef DISTAPPROXMODE_H
19 | #define DISTAPPROXMODE_H
20 |
21 | #include
22 | #include
23 | #include
24 |
25 | #include
26 | #include
27 | #include
28 |
29 | #include
30 | #include
31 |
32 | class DistApproxMode : public Mode
33 | {
34 | public:
35 | DistApproxMode(size_t num_leds, int priority = 0, double freq = 5, int pulses = 0, double timeout = 0)
36 | :Mode(priority, freq, pulses, timeout), _timer_inc(0), _num_leds(num_leds)
37 | {
38 | ros::NodeHandle nh;
39 | sub_scan = nh.subscribe("/scan_unified", 1, &DistApproxMode::scan_callback, this);
40 | //use static freq for this mode
41 | _inc = (1. / UPDATE_RATE_HZ) * UPDATE_FREQ;
42 |
43 | _colors.resize(_num_leds);
44 |
45 | c_red.a = 1; c_red.r = 1; c_red.g = 0; c_red.b = 0;
46 | c_green.a = 1; c_green.r = 0; c_green.g = 1; c_green.b = 0;
47 | c_off.a = 0; c_off.r = 0; c_off.g = 0; c_off.b = 0;
48 | c_default.a = 0.1; c_default.r = 0; c_default.g = 1.0; c_default.b = 0;
49 | }
50 |
51 | void scan_callback(const sensor_msgs::LaserScanConstPtr& msg)
52 | {
53 | boost::mutex::scoped_lock lock(mutex);
54 | scan = *msg;
55 | }
56 |
57 | void execute()
58 | {
59 | if(_timer_inc >= 1.0)
60 | {
61 | //rotate scan array
62 | mutex.lock();
63 | std::vector ranges = scan.ranges;
64 | mutex.unlock();
65 | float sector_size = (float)ranges.size() / (float)_num_leds;
66 | std::vector sectors;
67 | sectors.assign(_num_leds, 0.0);
68 |
69 | //calculate sector values
70 | for(int i = 0; i < _num_leds; i++)
71 | {
72 | float sum = std::numeric_limits::max();
73 | //float sum = 0;
74 | for(int j = i*(int)sector_size; j < (i+1)*(int)sector_size; j++)
75 | {
76 | if(ranges.at(j) != 0){
77 | sum = std::min(ranges.at(j), sum);
78 | }
79 | }
80 | sectors.at(i) = sum;
81 | }
82 |
83 | for(int i = 0; i < _num_leds; i++)
84 | {
85 | color::rgba col;
86 |
87 | float mean = 0;
88 | if(i == 0)
89 | {
90 | mean = sectors.back()+sectors.at(i)/2.0f;
91 | }
92 | else
93 | {
94 | mean = (sectors.at(i)+sectors.at(i-1))/2.0f;
95 | }
96 | if(mean > DIST_MAX)
97 | {
98 | col = c_default;
99 | }
100 | else
101 | {
102 | float t = (boost::algorithm::clamp(mean, DIST_MIN, DIST_MAX) - DIST_MIN)/(DIST_MAX - DIST_MIN);
103 | col = color::Color::interpolateColor(c_red, c_green, t);
104 | }
105 |
106 | _colors.at(i) = col;
107 | }
108 | _pulsed++;
109 | m_sigColorsReady(_colors);
110 | _timer_inc = 0.0;
111 | }
112 | else
113 | _timer_inc += _inc;
114 | }
115 |
116 | std::string getName(){ return std::string("DistApproxMode"); }
117 |
118 | static constexpr float DIST_MIN = 0.3f;
119 | static constexpr float DIST_MAX = 2.0f;
120 | static constexpr double UPDATE_FREQ = 50.0;
121 |
122 | private:
123 | double _timer_inc;
124 | double _inc;
125 | size_t _num_leds;
126 |
127 | sensor_msgs::LaserScan scan;
128 |
129 | ros::Subscriber sub_scan;
130 | boost::mutex mutex;
131 | color::rgba c_red;
132 | color::rgba c_green;
133 | color::rgba c_off;
134 | color::rgba c_default;
135 | };
136 |
137 | constexpr float DistApproxMode::DIST_MIN;
138 | constexpr float DistApproxMode::DIST_MAX;
139 | constexpr double DistApproxMode::UPDATE_FREQ;
140 |
141 | #endif
142 |
--------------------------------------------------------------------------------
/cob_light/common/include/fadeColorMode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #ifndef FADECOLORMODE_H
19 | #define FADECOLORMODE_H
20 |
21 | #include
22 |
23 | class FadeColorMode : public Mode
24 | {
25 | public:
26 | FadeColorMode(color::rgba color, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0)
27 | :Mode(priority, freq, pulses, timeout)
28 | {
29 | _color = color;
30 |
31 | doOnce = true;
32 | h = 0.0;
33 | h_s = 0.0;
34 | h_t = 0.0;
35 |
36 | _inc = (1. / UPDATE_RATE_HZ) * _freq;
37 | }
38 |
39 | void execute()
40 | {
41 | float r = 0;
42 | float g = 0;
43 | float b = 0;
44 | float s, v;
45 |
46 | if(doOnce == true)
47 | {
48 | color::Color::rgb2hsv(_color.r, _color.g, _color.b, h, s, v);
49 | h_s = h;
50 | h_t = h;
51 | h_s += 1;
52 | doOnce = false;
53 | }
54 |
55 | color::Color::hsv2rgb(h, 1.0, 1.0, r, g, b);
56 |
57 | h += _inc;
58 | h_t += _inc;
59 | if(h > 1.0)
60 | h = 0.0;
61 |
62 | if(h_t >= h_s)
63 | {
64 | _pulsed++; h_s+=1;
65 | }
66 |
67 | color::rgba col;
68 | col.r = r;
69 | col.g = g;
70 | col.b = b;
71 | col.a = _color.a;
72 |
73 | m_sigColorReady(col);
74 | }
75 |
76 | std::string getName(){ return std::string("FadeColorMode"); }
77 |
78 | private:
79 | bool doOnce;
80 | float h;
81 | float h_s;
82 | float h_t;
83 | double _inc;
84 | };
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/cob_light/common/include/flashMode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #ifndef FLASHMODE_H
19 | #define FLASHMODE_H
20 |
21 | #include
22 |
23 | class FlashMode : public Mode
24 | {
25 | public:
26 | FlashMode(color::rgba color, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0)
27 | :Mode(priority, freq, pulses, timeout), _toggle(false), _timer_inc(0)
28 | {
29 | _color = color;
30 | if(_pulses != 0)
31 | {
32 | _pulses *=2;
33 | _pulses +=1;
34 | }
35 | _inc = (1. / UPDATE_RATE_HZ) * _freq;
36 | }
37 |
38 | void execute()
39 | {
40 | color::rgba col;
41 | col.r = _color.r;
42 | col.g = _color.g;
43 | col.b = _color.b;
44 | if(_timer_inc >= 1.0)
45 | {
46 | col.a = _color.a * (int)_toggle;
47 | _pulsed++;
48 | _toggle = !_toggle;
49 | m_sigColorReady(col);
50 | _timer_inc = 0.0;
51 | }
52 | else
53 | _timer_inc += _inc;
54 | }
55 |
56 | std::string getName(){ return std::string("FlashMode"); }
57 |
58 | private:
59 | bool _toggle;
60 | double _timer_inc;
61 | double _inc;
62 | };
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/cob_light/common/include/glowColorMode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #ifndef GLOWCOLORMODE_H
19 | #define GLOWCOLORMODE_H
20 |
21 | #include
22 |
23 | class GlowColorMode : public Mode
24 | {
25 | public:
26 | GlowColorMode(color::rgba color, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0)
27 | :Mode(priority, freq, pulses, timeout), _timer_inc(0.0)
28 | {
29 | _color = color;
30 | h = 0.0;
31 | _inc = (1. / UPDATE_RATE_HZ) * _freq;
32 | h_inc=0;
33 | color::Color::rgb2hsv(color.r, color.g, color.b, h, s, v);
34 | }
35 |
36 | void execute()
37 | {
38 | static int sign = 1;
39 | float r = 0;
40 | float g = 0;
41 | float b = 0;
42 |
43 | if(_timer_inc >= 1.0)
44 | {
45 | double tmp = h;
46 |
47 | h_inc += 0.001 * sign;
48 | if(h_inc >= 0.01 || h_inc <= -0.01)
49 | {
50 | sign *= -1;
51 | _pulsed++;
52 | }
53 | h += h_inc;
54 | if( h < 0)
55 | h = 1 + h;
56 |
57 | //double fV = (exp(sin(_timer_inc))-1.0/M_E)*(1.000/(M_E-1.0/M_E));
58 | double fV = (exp(sin( (M_PI/2)+h_inc*60 ))-0.36787944)*0.42545906411;
59 |
60 | color::Color::hsv2rgb(h, s, v, r, g, b);
61 |
62 | color::rgba col;
63 | col.r = r;
64 | col.g = g;
65 | col.b = b;
66 | col.a = fV;
67 |
68 | _timer_inc = 0.0;
69 | m_sigColorReady(col);
70 | h = tmp;
71 | }
72 | else
73 | _timer_inc += _inc;
74 | }
75 |
76 | std::string getName(){ return std::string("GlowColorMode"); }
77 |
78 | private:
79 | double _timer_inc;
80 | double _inc;
81 | float h, s, v;
82 | double h_inc;
83 | };
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/cob_light/common/include/kitMode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 Mojin Robotics GmbH https://www.mojin-robotics.de
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #ifndef KITMODE_H
19 | #define KITMODE_H
20 |
21 | #include
22 |
23 | class KitMode : public Mode
24 | {
25 | public:
26 | KitMode(color::rgba color, size_t num_leds, int priority = 0, double freq = 0.25, int pulses = 0, double timeout = 0)
27 | :Mode(priority, freq, pulses, timeout), _num_leds(num_leds)
28 | {
29 | _inc = (1. / UPDATE_RATE_HZ) * _freq;
30 |
31 | _color = color;
32 | _colors.assign(num_leds, color::rgba());
33 | _colors[0] = color;
34 | _pos = 0;
35 | _dir = 1;
36 | _fade_fac = 0.8;
37 | }
38 |
39 | void execute()
40 | {
41 | if(_timer_inc >= 1.0)
42 | {
43 | for(int i = 0; i < _num_leds; i++)
44 | {
45 |
46 | _colors[i].a = _colors[i].a * _fade_fac;
47 | }
48 | for(int j = 0; j < 5; j++)
49 | {
50 | _pos += _dir;
51 | if(_pos == -1)
52 | {
53 | _pos = 0;
54 | _dir = 1;
55 | }
56 | else if(_pos == _num_leds)
57 | {
58 | _pos = _num_leds-1;
59 | _dir = -1;
60 | }
61 |
62 | _colors[_pos] = _color;
63 |
64 | }
65 | m_sigColorsReady(_colors);
66 |
67 | _timer_inc = 0.0;
68 | }
69 | else
70 | _timer_inc += _inc;
71 |
72 | }
73 |
74 | std::string getName(){ return std::string("KitMode"); }
75 |
76 | private:
77 | double _timer_inc;
78 | double _inc;
79 | double _pos;
80 | double _dir;
81 | int _num_leds;
82 | double _fade_fac;
83 | };
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/cob_light/common/include/mode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #ifndef MODE_H
19 | #define MODE_H
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | class Mode
27 | {
28 | public:
29 | Mode(int priority = 0, double freq = 0, int pulses = 0, double timeout = 0)
30 | : _priority(priority), _freq(freq), _pulses(pulses), _timeout(timeout),
31 | _finished(false), _pulsed(0), _isStopRequested(false), _isPauseRequested(false),
32 | _isRunning(false)
33 | {
34 | if(this->getFrequency() == 0.0)
35 | this->setFrequency(1.0);
36 | }
37 | virtual ~Mode(){}
38 |
39 | void start()
40 | {
41 | if(_thread == NULL)
42 | _thread.reset(new boost::thread(&Mode::run, this));
43 | if(isPauseRequested())
44 | {
45 | boost::mutex::scoped_lock lock(_mutex_pause);
46 | _isPauseRequested = false;
47 | _cond_pause.notify_one();
48 | }
49 | _isRunning = true;
50 | }
51 |
52 | void stop()
53 | {
54 | _mutex.lock();
55 | _isStopRequested = true;
56 | _mutex.unlock();
57 | if(isPauseRequested())
58 | {
59 | _isPauseRequested = false;
60 | boost::mutex::scoped_lock lock(_mutex_pause);
61 | _cond_pause.notify_one();
62 | }
63 | if(_thread != NULL)
64 | {
65 | _thread->join();
66 | _thread.reset();
67 | }
68 | _isStopRequested = false;
69 | _isRunning = false;
70 | }
71 |
72 | void pause()
73 | {
74 | _mutex.lock();
75 | _isPauseRequested = true;
76 | _mutex.unlock();
77 | _isRunning = false;
78 | }
79 |
80 | virtual void execute() = 0;
81 |
82 | virtual std::string getName() = 0;
83 |
84 | bool finished(){ return _finished; }
85 |
86 | void setPriority(int priority){ _priority = priority; }
87 | int getPriority(){ return _priority; }
88 |
89 | void setTimeout(double timeout){ _timeout = timeout; }
90 | double getTimeout(){ return _timeout; }
91 |
92 | void setFrequency(double freq){ _freq = freq; }
93 | double getFrequency(){ return _freq; }
94 |
95 | void setPulses(int pulses){ _pulses = pulses; }
96 | int getPulses(){ return _pulses; }
97 |
98 | int pulsed(){ return _pulsed; }
99 |
100 | void setColor(color::rgba color){ _color = color; }
101 | color::rgba getColor(){ return _color; }
102 |
103 | void setActualColor(color::rgba color){ _actualColor = color; }
104 | color::rgba getActualColor(){ return _color; }
105 |
106 | bool isRunning(){ return _isRunning; }
107 |
108 | boost::signals2::signal* signalColorReady(){ return &m_sigColorReady; }
109 | boost::signals2::signal &colors)>* signalColorsReady(){ return &m_sigColorsReady; }
110 | boost::signals2::signal* signalModeFinished(){ return &m_sigFinished; }
111 |
112 | protected:
113 | int _priority;
114 | double _freq;
115 | int _pulses;
116 | double _timeout;
117 |
118 | bool _finished;
119 | int _pulsed;
120 |
121 | color::rgba _color;
122 | std::vector _colors;
123 | color::rgba _actualColor;
124 | color::rgba _init_color;
125 |
126 | static const unsigned int UPDATE_RATE_HZ = 100;
127 |
128 | boost::signals2::signal m_sigColorReady;
129 | boost::signals2::signal &colors)> m_sigColorsReady;
130 | boost::signals2::signal m_sigFinished;
131 |
132 | private:
133 | boost::shared_ptr _thread;
134 | boost::mutex _mutex;
135 | boost::mutex _mutex_pause;
136 | bool _isStopRequested;
137 | bool _isPauseRequested;
138 | bool _isRunning;
139 |
140 | boost::condition_variable _cond_pause;
141 |
142 | bool isStopRequested()
143 | {
144 | bool ret;
145 | _mutex.lock();
146 | ret = _isStopRequested;
147 | _mutex.unlock();
148 | return ret;
149 | }
150 |
151 | bool isPauseRequested()
152 | {
153 | bool ret;
154 | _mutex.lock();
155 | ret = _isPauseRequested;
156 | _mutex.unlock();
157 | return ret;
158 | }
159 |
160 | protected:
161 | virtual void run()
162 | {
163 | ros::Rate r(UPDATE_RATE_HZ);
164 |
165 | ros::Time timeStart = ros::Time::now();
166 |
167 | while(!isStopRequested() && !ros::isShuttingDown())
168 | {
169 | while(isPauseRequested())
170 | {
171 | boost::mutex::scoped_lock lock(_mutex_pause);
172 | _cond_pause.wait(lock);
173 | }
174 | this->execute();
175 |
176 | if((this->getPulses() != 0) &&
177 | (this->getPulses() <= this->pulsed()))
178 | break;
179 |
180 | if(this->getTimeout() != 0)
181 | {
182 | ros::Duration timePassed = ros::Time::now() - timeStart;
183 | if(timePassed.toSec() >= this->getTimeout())
184 | break;
185 | }
186 | r.sleep();
187 | }
188 | ROS_DEBUG("Mode %s finished",this->getName().c_str());
189 | if(!isStopRequested())
190 | m_sigFinished(this->getPriority());
191 | }
192 | };
193 |
194 | #endif
195 |
--------------------------------------------------------------------------------
/cob_light/common/include/modeExecutor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #ifndef MODEEXECUTOR_H
19 | #define MODEEXECUTOR_H
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include