NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
light_flow.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef LIGHT_FLOW_H_
20 #define LIGHT_FLOW_H_
21 
22 #include <ff_hw_msgs/ConfigureLED.h>
23 #include <ff_common/ff_names.h>
24 #include <jsoncpp/json/value.h>
25 #include <ros/ros.h>
26 #include <stdio.h>
27 #include <string>
28 #include <vector>
29 
30 #endif // LIGHT_FLOW_H_
31 
32 namespace light_flow {
33 
34 double getUnixTimestamp();
35 int hexToInt(std::string hex);
38  Json::Value obj);
39 Json::Value macroExpand(const Json::Value &macroLookup, Json::Value obj);
40 double floatFromHex(const std::string &hex);
41 Json::Value compileColor(const Json::Value &rgbHexAsJson);
60 Json::Value getProcedureLookup(const Json::Value &procedures);
62  const Json::Value &procedureLookup);
64  const Json::Value &procedureLookup);
66  const Json::Value &procedureLookup);
68  const Json::Value &motionOffset);
69 Json::Value getSequenceFrameInfo(const Json::Value &seq, double t,
70  double motionOffset);
72  double motionOffset);
74  double motionOffset);
76  double motionOffset);
77 Json::Value getSequenceFrameInfo(const Json::Value &seq, double t,
78  double motionOffset);
79 void vectorAdd(Json::Value &u, const Json::Value &v);
80 Json::Value vectorMix(const Json::Value &u, double ku, const Json::Value &v,
81  double kv);
82 Json::Value getPixelColorBasicFrame(const Json::Value &frame, double pos);
83 Json::Value getPixelColorRepeatFrame(const Json::Value &frame, double pos);
84 Json::Value getPixelColorListFrame(const Json::Value &frame, double pos);
85 Json::Value getPixelColorFrame(const Json::Value &frame, double pos);
86 
87 class Light {
88  public:
89  float red, green, blue;
90  bool set;
91  Light(float r, float g, float b);
92  Light();
93  explicit Light(const std::vector<double> &d);
94 };
95 
96 class Frame {
97  public:
98  std::vector<Light> lights;
99  bool isLeft;
100  explicit Frame(int numberOfLights, bool isLeft);
101  void setLight(int index, float red, float green, float blue);
102  void setLight(int index, const std::vector<double> &d);
103  int translateIndex(int index);
104  void printLights();
105 };
106 
107 void vectorElementProduct(std::vector<double> &u, const std::vector<double> &v);
108 std::vector<double> jsonArrayToDoubleVector(const Json::Value &array);
109 std::vector<double> getPixelColorFrameInfo(const Json::Value &frameInfo,
110  double pos,
111  const std::vector<double> &filter);
112 void applyBasicAnimation(Frame &frame, const Json::Value &animation, double t,
113  const std::vector<double> &filter);
114 void applyListAnimation(Frame &frame, Json::Value animation, double t,
115  const std::vector<double> &filter);
116 void applyAnimation(Frame &frame, Json::Value animation, double t,
117  const std::vector<double> &filter);
118 void applyCall(Frame &frame, double t, const Json::Value &call);
119 
120 class Modules {
121  public:
124  explicit Modules(int numberOfLights);
125 };
126 
127 void renderFrame(const Json::Value &statesOfExecution, Modules &modules,
128  double timeElapsed);
129 void compileLightFlow(Json::Value &input);
130 void setAllBlack(std::vector<ff_hw_msgs::ConfigureLED> &ledConfigs);
131 ff_hw_msgs::ConfigureLED createLED(uint red, uint green, uint blue,
132  uint position);
133 void publishLightFlow(const Json::Value &statesOfExecution,
134  const ros::Publisher &publishLEDGroup,
135  bool isStreaming);
136 
137 } // namespace light_flow
light_flow::compileListAnimation
Json::Value compileListAnimation(const Json::Value &obj)
Definition: light_flow.cc:321
light_flow::Frame::printLights
void printLights()
Definition: light_flow.cc:639
light_flow::Modules
Definition: light_flow.h:120
light_flow::Frame::lights
std::vector< Light > lights
Definition: light_flow.h:98
light_flow::compileBasicAnimation
Json::Value compileBasicAnimation(const Json::Value &obj)
Definition: light_flow.cc:311
light_flow::getPixelColorFrameInfo
std::vector< double > getPixelColorFrameInfo(const Json::Value &frameInfo, double pos, const std::vector< double > &filter)
Definition: light_flow.cc:666
light_flow::getPixelColorBasicFrame
Json::Value getPixelColorBasicFrame(const Json::Value &frame, double pos)
Definition: light_flow.cc:519
light_flow::getPixelColorListFrame
Json::Value getPixelColorListFrame(const Json::Value &frame, double pos)
Definition: light_flow.cc:557
light_flow::createLED
ff_hw_msgs::ConfigureLED createLED(uint red, uint green, uint blue, uint position)
Definition: light_flow.cc:772
light_flow::compileDomain
Json::Value compileDomain(const Json::Value &obj)
Definition: light_flow.cc:300
light_flow::Light
Definition: light_flow.h:87
light_flow::getPixelColorFrame
Json::Value getPixelColorFrame(const Json::Value &frame, double pos)
Definition: light_flow.cc:571
light_flow::Light::green
float green
Definition: light_flow.h:89
light_flow::Frame::translateIndex
int translateIndex(int index)
Definition: light_flow.cc:606
light_flow::macroExpand
Json::Value macroExpand(const Json::Value &macroLookup, Json::Value obj)
Definition: light_flow.cc:84
light_flow::compileRepeatSequence
Json::Value compileRepeatSequence(const Json::Value &obj)
Definition: light_flow.cc:235
light_flow::compileBasicFrame
Json::Value compileBasicFrame(const Json::Value &obj)
Definition: light_flow.cc:125
light_flow::compileAnimation
Json::Value compileAnimation(const Json::Value &obj)
Definition: light_flow.cc:331
light_flow::applyCall
void applyCall(Frame &frame, double t, const Json::Value &call)
Definition: light_flow.cc:730
light_flow::getRepeatSequenceFrameInfo
Json::Value getRepeatSequenceFrameInfo(const Json::Value &seq, double t, double motionOffset)
Definition: light_flow.cc:465
light_flow::applyListAnimation
void applyListAnimation(Frame &frame, Json::Value animation, double t, const std::vector< double > &filter)
Definition: light_flow.cc:713
light_flow::getUnixTimestamp
double getUnixTimestamp()
Definition: light_flow.cc:44
light_flow::Frame
Definition: light_flow.h:96
light_flow::compileBasicSequence
Json::Value compileBasicSequence(const Json::Value &obj)
Definition: light_flow.cc:199
light_flow::compileLightFlow
void compileLightFlow(Json::Value &input)
Definition: light_flow.cc:759
light_flow::Frame::Frame
Frame(int numberOfLights, bool isLeft)
Definition: light_flow.cc:595
light_flow::compileInterval
Json::Value compileInterval(const Json::Value &obj)
Definition: light_flow.cc:291
access_control::hex
constexpr char hex[]
Definition: access_control.cc:23
gpio::Value
Value
Definition: GPIO.h:42
light_flow::compileListFrame
Json::Value compileListFrame(const Json::Value &obj)
Definition: light_flow.cc:170
light_flow::Frame::setLight
void setLight(int index, float red, float green, float blue)
Definition: light_flow.cc:598
light_flow::renderFrame
void renderFrame(const Json::Value &statesOfExecution, Modules &modules, double timeElapsed)
Definition: light_flow.cc:739
light_flow::getSequenceFrameInfo
Json::Value getSequenceFrameInfo(const Json::Value &seq, double t, double motionOffset)
Definition: light_flow.cc:490
light_flow::compileSequence
Json::Value compileSequence(const Json::Value &obj)
Definition: light_flow.cc:266
light_flow::getProcedureLookup
Json::Value getProcedureLookup(const Json::Value &procedures)
Definition: light_flow.cc:383
light_flow::Modules::left
Frame left
Definition: light_flow.h:122
light_flow::setAllBlack
void setAllBlack(std::vector< ff_hw_msgs::ConfigureLED > &ledConfigs)
Definition: light_flow.cc:764
ff_names.h
light_flow::Modules::right
Frame right
Definition: light_flow.h:123
light_flow::Light::set
bool set
Definition: light_flow.h:90
light_flow::compileRepeatFrame
Json::Value compileRepeatFrame(const Json::Value &obj)
Definition: light_flow.cc:145
light_flow::compileReturn
Json::Value compileReturn(const Json::Value &obj)
Definition: light_flow.cc:349
light_flow::applyBasicAnimation
void applyBasicAnimation(Frame &frame, const Json::Value &animation, double t, const std::vector< double > &filter)
Definition: light_flow.cc:689
light_flow::hexToInt
int hexToInt(std::string hex)
Definition: light_flow.cc:46
light_flow::compileFrame
Json::Value compileFrame(const Json::Value &obj)
Definition: light_flow.cc:180
light_flow::compileCall
Json::Value compileCall(const Json::Value &obj, const Json::Value &procedureLookup)
Definition: light_flow.cc:392
light_flow::compileListSequence
Json::Value compileListSequence(const Json::Value &obj)
Definition: light_flow.cc:256
light_flow::Light::Light
Light()
Definition: light_flow.cc:586
light_flow::jsonArrayToDoubleVector
std::vector< double > jsonArrayToDoubleVector(const Json::Value &array)
Definition: light_flow.cc:657
light_flow::macroExpandRecursive
Json::Value macroExpandRecursive(const Json::Value &macroLookup, Json::Value obj)
Definition: light_flow.cc:55
light_flow::getPixelColorRepeatFrame
Json::Value getPixelColorRepeatFrame(const Json::Value &frame, double pos)
Definition: light_flow.cc:542
light_flow
Definition: light_flow.h:32
light_flow::getBasicSequenceFrameInfo
Json::Value getBasicSequenceFrameInfo(const Json::Value &seq, double t, const Json::Value &motionOffset)
Definition: light_flow.cc:425
light_flow::applyAnimation
void applyAnimation(Frame &frame, Json::Value animation, double t, const std::vector< double > &filter)
Definition: light_flow.cc:719
light_flow::Light::blue
float blue
Definition: light_flow.h:89
green
uint8_t green
Definition: signal_lights.h:62
light_flow::compileCallList
Json::Value compileCallList(const Json::Value &obj, const Json::Value &procedureLookup)
Definition: light_flow.cc:405
light_flow::compileDefine
Json::Value compileDefine(const Json::Value &obj)
Definition: light_flow.cc:341
light_flow::Frame::isLeft
bool isLeft
Definition: light_flow.h:99
light_flow::compileColor
Json::Value compileColor(const Json::Value &rgbHexAsJson)
Definition: light_flow.cc:106
light_flow::Light::red
float red
Definition: light_flow.h:89
light_flow::vectorElementProduct
void vectorElementProduct(std::vector< double > &u, const std::vector< double > &v)
Definition: light_flow.cc:651
light_flow::publishLightFlow
void publishLightFlow(const Json::Value &statesOfExecution, const ros::Publisher &publishLEDGroup, bool isStreaming)
Definition: light_flow.cc:782
light_flow::compileExecState
Json::Value compileExecState(const Json::Value &obj, const Json::Value &procedureLookup)
Definition: light_flow.cc:413
light_flow::getMacroLookup
Json::Value getMacroLookup(const Json::Value &proc)
Definition: light_flow.cc:48
light_flow::Modules::Modules
Modules(int numberOfLights)
Definition: light_flow.cc:736
light_flow::getProcedureAnimation
Json::Value getProcedureAnimation(const Json::Value &procedure)
Definition: light_flow.cc:373
light_flow::getMoveSequenceFrameInfo
Json::Value getMoveSequenceFrameInfo(const Json::Value &seq, double t, double motionOffset)
Definition: light_flow.cc:459
light_flow::compileProcedure
Json::Value compileProcedure(const Json::Value &obj)
Definition: light_flow.cc:358
light_flow::vectorAdd
void vectorAdd(Json::Value &u, const Json::Value &v)
Definition: light_flow.cc:506
blue
uint8_t blue
Definition: signal_lights.h:63
light_flow::compileMoveSequence
Json::Value compileMoveSequence(const Json::Value &obj)
Definition: light_flow.cc:227
red
uint8_t red
Definition: signal_lights.h:61
light_flow::vectorMix
Json::Value vectorMix(const Json::Value &u, double ku, const Json::Value &v, double kv)
Definition: light_flow.cc:511
light_flow::floatFromHex
double floatFromHex(const std::string &hex)
Definition: light_flow.cc:95
light_flow::getListSequenceFrameInfo
Json::Value getListSequenceFrameInfo(const Json::Value &seq, double t, double motionOffset)
Definition: light_flow.cc:481