fadeColorMode.h
Go to the documentation of this file.
00001 /****************************************************************
00002  *
00003  * Copyright (c) 2010
00004  *
00005  * Fraunhofer Institute for Manufacturing Engineering   
00006  * and Automation (IPA)
00007  *
00008  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00009  *
00010  * Project name: care-o-bot
00011  * ROS stack name: cob_driver
00012  * ROS package name: cob_light
00013  * Description: Switch robots led color by sending data to
00014  * the led-µC over serial connection.
00015  *                                                              
00016  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00017  *                      
00018  * Author: Benjamin Maidel, email:benjamin.maidel@ipa.fraunhofer.de
00019  * Supervised by: Benjamin Maidel, email:benjamin.maidel@ipa.fraunhofer.de
00020  *
00021  * Date of creation: August 2012
00022  * ToDo:
00023  *
00024  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00025  *
00026  * Redistribution and use in source and binary forms, with or without
00027  * modification, are permitted provided that the following conditions are met:
00028  *
00029  *     * Redistributions of source code must retain the above copyright
00030  *       notice, this list of conditions and the following disclaimer.
00031  *     * Redistributions in binary form must reproduce the above copyright
00032  *       notice, this list of conditions and the following disclaimer in the
00033  *       documentation and/or other materials provided with the distribution.
00034  *     * Neither the name of the Fraunhofer Institute for Manufacturing 
00035  *       Engineering and Automation (IPA) nor the names of its
00036  *       contributors may be used to endorse or promote products derived from
00037  *       this software without specific prior written permission.
00038  *
00039  * This program is free software: you can redistribute it and/or modify
00040  * it under the terms of the GNU Lesser General Public License LGPL as 
00041  * published by the Free Software Foundation, either version 3 of the 
00042  * License, or (at your option) any later version.
00043  * 
00044  * This program is distributed in the hope that it will be useful,
00045  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00046  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00047  * GNU Lesser General Public License LGPL for more details.
00048  * 
00049  * You should have received a copy of the GNU Lesser General Public 
00050  * License LGPL along with this program. 
00051  * If not, see <http://www.gnu.org/licenses/>.
00052  *
00053  ****************************************************************/
00054 
00055 #ifndef FADECOLORMODE_H
00056 #define FADECOLORMODE_H
00057 
00058 #include <mode.h>
00059 
00060 class FadeColorMode : public Mode
00061 {
00062 public:
00063         FadeColorMode(color::rgba color, int priority = 0, double freq = 25, int pulses = 0, double timeout = 0)
00064                 :Mode(priority, freq, pulses, timeout)
00065         {
00066                 _color = color;
00067 
00068                 doOnce = true;
00069                 h = 0.0;
00070                 h_s = 0.0;
00071                 h_t = 0.0;
00072         }
00073 
00074         void execute()
00075         {
00076                 float r = 0;
00077                 float g = 0;
00078                 float b = 0;
00079                 float s, v;
00080 
00081                 if(doOnce == true)
00082                 {
00083                         color::Color::rgb2hsv(_color.r, _color.g, _color.b, h, s, v);
00084                         h_s = h;
00085                         h_t = h;
00086                         h_s += 1;
00087                         doOnce = false;
00088                 }
00089 
00090                 color::Color::hsv2rgb(h, 1.0, 1.0, r, g, b);
00091 
00092                 h += 0.0025;
00093                 h_t += 0.0025;
00094                 if(h > 1.0)
00095                         h = 0.0;
00096 
00097                 if(h_t >= h_s)
00098                 {
00099                         _pulsed++; h_s+=1;
00100                 }
00101 
00102                 color::rgba col;
00103                 col.r = r;
00104                 col.g = g;
00105                 col.b = b;
00106                 col.a = _color.a;
00107                 
00108                 m_sigColorReady(col);
00109         }
00110 
00111         std::string getName(){ return std::string("FadeColorMode"); }
00112 
00113 private:
00114         bool doOnce;
00115         float h;
00116         float h_s;
00117         float h_t;
00118 };
00119 
00120 #endif


cob_light
Author(s): Benjamin Maidel
autogenerated on Thu Aug 27 2015 12:46:10