To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 587aca5e authored by remartin's avatar remartin
Browse files

Added 'colour' message type and 'fullSearchPattern' function.

parent 61d2f0b1
......@@ -74,6 +74,8 @@ public:
// Reacts to yaw changes of the target.
void fancyColourFunction(double yaw);
// Covers the whole room.
void fullSearchPattern(double rotationSpeed, int rotations, int zoom);
// toggles some pan values.
......@@ -87,7 +89,8 @@ public:
private:
int posPT; //Where the four PT values start.
int posPT; // Where the four PT values start.
int posColour; // Where Red, Green, Blue and White are.
SerialLight sL;
const static char portLocation[];
unsigned char defaultChannel; // value between 0 and 255...
......@@ -96,6 +99,8 @@ private:
unsigned char dmxValues[14];
double initialSpherical[3];
unsigned char initialPT[4];
double updateFrequency;
double spotlightPos[3];
double targetPos[3];
......@@ -108,4 +113,5 @@ private:
std::string buildMessage(); // 'bad practice to import namespace std in header'
std::string buildPT();
std::string buildChannel();
std::string buildColour();
};
#include <DmxSimple.h>
#include <DmxSimple.h>
// Copyright (C) 2018, ETH Zurich, D-ITET
// Martin Reinhard remartin @ee.ethz.ch
//
......@@ -91,6 +95,7 @@ int i = 0; // Offset in the currentDmxMessage-Array
bool readingMessage = false;
bool readingChannelOffset = false;
bool readingPT = false;
bool readingColour = false;
// Reads messages from the serial port: Either new channel numbers (= channelOffset) or DmxMessages.
void serialEvent(){
......@@ -108,13 +113,18 @@ void serialEvent(){
if(!readingMessage && ch == 'm'){
readingMessage = true;
i = 0;
time = micros();
time = micros();
}else if(!readingChannelOffset && ch == 'c'){
readingChannelOffset = true;
time = micros();
}else if(!readingPT && ch == 'p'){
readingPT = true;
i = 3;
time = micros();
time = micros();
}else if(!readingColour && ch == 'f'){
readingColour = true;
i = 9;
time = micros();
}else if(readingMessage){
if(ch == 'm'){//End reached
parserTemp = 0;
......@@ -149,6 +159,9 @@ void serialEvent(){
Serial.print("New offset: ");
Serial.print(channelOffset);
Serial.println();
time = micros() - time;
Serial.print("Parsing a channel nr. took uS: ");
Serial.println(time, DEC);
}
parserTemp = 0;
readingChannelOffset = false;
......@@ -186,6 +199,31 @@ void serialEvent(){
readingPT = false;
//Serial.println("Error while parsing a PT.");
}
}else if(readingColour){
if(ch == 'f'){//End reached
parserTemp = 0;
i = 0; // reset array offset
readingColour = false;
time = micros() - time;
Serial.print("Parsing a Colour took uS: ");
Serial.println(time, DEC);
}else if(ch == ','){
if(parserTemp>255 || parserTemp<0){
Serial.println("Warning: DMX-Range"); //(std3);
}else{
currentDmxMessage[i] = parserTemp;
DmxSimple.write(channelOffset+i, parserTemp);
}
parserTemp = 0;
i++;
}else if(isDigit(ch)){
parserTemp = 10*parserTemp + (ch-'0');
}else{// abort that attempt and reset everything.
parserTemp = 0;
i = 0;
readingPT = false;
//Serial.println("Error while parsing a PT.");
}
}else{// all other stuff
// Arduino sends some info stuff at startup -> need to disable those error messages.
// Serial.println("Received Gibberish. That one:");
......
......@@ -45,8 +45,11 @@ int main(){
spotlightManager slM;
//slM.setPTmanually(false);
slM.testPTupdater();
slM.setPTmanually(false);
slM.fullSearchPattern(3, 10, 0);
//slM.testPTupdater();
//slM.someDefaultSettings();
......
......@@ -45,7 +45,9 @@ spotlightManager::spotlightManager(){
defaultChannel = 10; //Value between 0 and 255.
messageLength = 14;
posPT = 3; //Where the four PT values start.
posPT = 3; // Where the four PT values start.
posColour = 9; // Where Red, Green, Blue and White are.
updateFrequency = 30.0; // Should be below 55 (Aruino), > 40 makes no sense (DMX)
for(int hans = 0; hans < 14; hans++){
dmxValues[hans] = 0;
......@@ -301,11 +303,45 @@ void spotlightManager::fancyColourFunction(double yaw){
dmxValues[10] = (( (int) (yaw+120) % 360)/360)*255; // Green
dmxValues[11] = (( (int) (yaw+240) % 360)/360)*255; // Blue
// White: 12
sL.writeSerialLight((buildMessage()).c_str());
sL.writeSerialLight((buildColour()).c_str());
// need to adapt Bitrate?
//sendMessage... Or joust colour
}
// Covers the whole room.
void spotlightManager::fullSearchPattern(double rotationSpeed, int rotations, int zoom){
if(zoom>255){zoom = 255;}
if(zoom<0){zoom = 0;}
// Tilt. 106 degrees = 127 DMX
int tiltIncrement = 127/rotations; // wird halt abgerundet.
// Pan. 360 degrees = 170 DMX
int panStep = 170/(rotationSpeed*updateFrequency);
double delayUs = 1000000/updateFrequency;
someDefaultSettings();
dmxValues[2] = zoom;
dmxValues[3] = 40; // 40-210, away from the edges.
dmxValues[5] = 0; // lowest tilt value.
sL.writeSerialLight((buildMessage()).c_str());
usleep(1000000); // Wait a second. Looks cooler.
bool oneDirectionRubbish = true;
for(int turn = 0; turn < rotations; turn++){
// one pass
for(int hubba = 0; hubba < (170/panStep); hubba++){
if(oneDirectionRubbish){dmxValues[3]+=panStep;}else{dmxValues[3]-=panStep;}
sL.writeSerialLight((buildPT()).c_str());
usleep(delayUs);
}
dmxValues[5] += tiltIncrement;
sL.writeSerialLight((buildPT()).c_str());
oneDirectionRubbish = !oneDirectionRubbish;
usleep(200000); // cosmetic effects. Wait 1/5 second.
}
}
// construct strings that can be decoded by the arduino
string spotlightManager::buildMessage(){
stringstream ss;
......@@ -335,7 +371,16 @@ string spotlightManager::buildChannel(){
return ss.str();
}
// construct strings that can be decoded by the arduino
string spotlightManager::buildColour(){
stringstream ss;
ss << 'f';
for(int brot = posColour; brot<posColour+4; brot++){
ss << (int) dmxValues[brot] << ',';
}
ss << 'f';
return ss.str();
}
// toggles some pan values.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment