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 eb0ed0cf authored by remartin's avatar remartin
Browse files

Cleaned up, minor changes. Final commit.

parent 693842fa
......@@ -35,8 +35,6 @@
#ifndef UWBSPOTLIGHT_MAIN_H
#define UWBSPOTLIGHT_MAIN_H
//#include <fstream>
#include <std_msgs/Float32MultiArray.h>
#include "std_msgs/Int32.h"
#include "std_msgs/UInt32MultiArray.h"
......
#include <DmxSimple.h>
#include <DmxSimple.h>
// Copyright (C) 2018, ETH Zurich, D-ITET
// Martin Reinhard remartin @ee.ethz.ch
//
......
// Copyright (C) 2018, ETH Zurich, D-ITET
// Martin Reinhard remartin @ee.ethz.ch
//
// Based on source: https://learn.sparkfun.com/tutorials/temt6000-ambient-light-sensor-hookup-guide
//
// This file is part of D-FaLL-System.
//
// D-FaLL-System is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// D-FaLL-System is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with D-FaLL-System. If not, see <http://www.gnu.org/licenses/>.
//
//
// ----------------------------------------------------------------------------------
// DDDD FFFFF L L SSSS Y Y SSSS TTTTT EEEEE M M
// D D F aaa L L S Y Y S T E MM MM
// D D --- FFFF a a L L --- SSS Y SSS T EEE M M M
// D D F a aa L L S Y S T E M M
// DDDD F aa a LLLL LLLL SSSS Y SSSS T EEEEE M M
//
//
// DESCRIPTION:
// Arduino program for logging intensity values.
//
// ----------------------------------------------------------------------------------
#define LIGHTSENSORPIN A0 //Ambient light sensor reading
......
......@@ -26,7 +26,8 @@
//
//
// DESCRIPTION:
// Main function for testing the spotlightManager. Compile with customCooker.
// Main function for testing the spotlightManager. Compile with 'bash customCooker.sh'.
// Need to run 'bash eavesdropper.sh' in another terminal window.
//
// ----------------------------------------------------------------------------------
......@@ -40,15 +41,19 @@ int main(){
}
spotlightManager slM;
//slM.someDefaultSettings();
//slM.setPTmanually(false);
//slM.fullSearchPattern(3, 10, 0);
slM.setPTmanually(false);
slM.fullSearchPattern(3, 10, 0);
//slM.fullSearchPattern(2, 10, 200);
//slM.fullSearchPattern(2, 4, 255);
//slM.fullSearchPattern(4, 20, 200);
slM.fullSearchPattern(2, 10, 200);
slM.fullSearchPattern(2, 4, 255);
slM.fullSearchPattern(4, 20, 200);
slM.lineWithLogging(30, 255, 200, 4, true);
// Narrow:
//slM.lineWithLogging(35, 255, 200, 4, true);
// Wide:
//slM.lineWithLogging(55, 255, 0, 6, true);
//slM.testPTupdater();
......
......@@ -27,6 +27,7 @@
//
// DESCRIPTION:
// Writes intensity values delivered by a sensor on an Arduino to a .txt file.
// Run with 'bash cookIntensityLogger.sh'.
//
// ----------------------------------------------------------------------------------
......@@ -52,7 +53,7 @@ intensityLogger::intensityLogger(){
void intensityLogger::run(){
ofstream intensityLog;
intensityLog.open("loggedIntensityValues.txt", ofstream::out | ofstream::trunc);
intensityLog.open("loggedIntensityValues_C.txt", ofstream::out | ofstream::trunc);
intensityLog << "time\tNormed Intensity\n";
intensityLog.flush();
......
......@@ -27,6 +27,7 @@
//
// DESCRIPTION:
// Writes intensity values delivered by a sensor on an Arduino to a .txt file.
// Run with 'bash cookIntensityLogger.sh'.
//
// ----------------------------------------------------------------------------------
......
......@@ -80,7 +80,6 @@ void SerialLight::init(){
}
int SerialLight::startConnection(const char* port){
//printf("Attempting to connect to Serial port %s...\n", port);
_port = "";
_isConnected = false;
......@@ -129,9 +128,10 @@ int SerialLight::startConnection(const char* port){
_port = port;
_isConnected = true;
//printf("%sConnected\n", K_WARNING);
//printf("%s", K_NORMAL);
// Just drop everything being received to avoid an input buffer overflow.
// Start in another terminal if logging is required:
// bash eavesdropper.sh
tcflush(tty_fd, TCIFLUSH); // Bug: Doesn't work, somewhy the eavesdropper is required.
return 1;
}
......@@ -153,9 +153,8 @@ bool SerialLight::writeSerialLight(const char* buffer){
// Just drop everything being received to avoid an input buffer overflow.
// Start in another terminal if logging is required:
// echo 'A new log: ' > eavesDroppingLog.txt
// cat -v < /dev/ttyACM0 |& tee -a eavesDroppingLog.txt
tcflush(tty_fd, TCIFLUSH);
// bash eavesdropper.sh
tcflush(tty_fd, TCIFLUSH); // Bug: Doesn't work, somewhy the eavesdropper is required.
printf("Sending packet to Serial (%s)\n", buffer);
// zero day SerialUnix code? (Just sending first 14 bytes -> pointer stuff? )
......@@ -164,7 +163,5 @@ bool SerialLight::writeSerialLight(const char* buffer){
//}
write(tty_fd, buffer, strlen(buffer));
//ioctl(tty_fd, TCFLSH, 1); // flush transmit
return 1;
}
......@@ -47,8 +47,6 @@ int main(int argc, char* argv[]){
ros::NodeHandle nodeHandle("~");
ros::NodeHandle namespaceNodeHandle = ros::NodeHandle();
// need to load parameters?
// to get the anchor positions/detect whether they have changed.
uwbManager = nodeHandle.serviceClient<Anchors>("/UWBManagerService/UWBData", false);
ros::Subscriber enableUWBSubscriber = nodeHandle.subscribe("/my_GUI/enableUWB", 1, anchorArrangementChangedCallback);
......@@ -74,7 +72,7 @@ void d_fall_pps::updateTargetPositionCallback(const CrazyflieData &data){
if(elapsedTime > (1000/maxFrequency)){
//ROS_INFO_STREAM("Applying new coordinates: %f,%f,%f. ", data.x, data.y, data.z);
slM.setTargetPosition(data.x, data.y, data.z); // invert z position
slM.setTargetPosition(data.x, data.y, -data.z); // invert z position
slM.updatePTvalues();
slM.fancyColourFunction(data.yaw);
printf("\n");
......@@ -84,7 +82,7 @@ void d_fall_pps::updateTargetPositionCallback(const CrazyflieData &data){
}else if(placedSpotlight){
slM.setTargetPosition(data.x, data.y, data.z); // invert z position
slM.setTargetPosition(data.x, data.y, -data.z); // invert z position
slM.calibrateOrientation();
lastSent = std::chrono::high_resolution_clock::now();
......
......@@ -86,7 +86,7 @@ void spotlightManager::someDefaultSettings(){
void spotlightManager::setTargetPosition(double x, double y, double z){
//printf("Received new Target position: %f,%f,%f. \n", x,y,z);
//printf("Momemorised spotlight position is: %f,%f,%f. \n", spotlightPos[0], spotlightPos[1], spotlightPos[2]);
printf("Z component currently is: %f \n", z);
//printf("Z component currently is: %f \n", z);
targetPos[0] = x;
targetPos[1] = y;
targetPos[2] = z;
......@@ -107,6 +107,7 @@ void spotlightManager::updateSpherical(){
double dz = targetPos[2]-spotlightPos[2];
//printf("The differences are: dx is %f, dy is %f, dz is %f. \n", dx, dy, dz);
//printf("The z difference is %f, between %f and %f. \n", dz, targetPos[2], spotlightPos[2]);
double r = sqrt(dx*dx + dy*dy + dz*dz);
double phi = atan2(dy, dx)* RAD2DEG; // use atan2 to avoid messing up quadrants
......@@ -114,9 +115,8 @@ void spotlightManager::updateSpherical(){
double theta = acos(dz/r) * RAD2DEG;
//printf("The saved angles are: phi %f, theta %f.\n", initialSpherical[1], initialSpherical[2]);
printf("The current angles are: phi is %f°, theta is %f°. \n", phi, theta);
printf("Saved theta is %f, current one is %f. \n", initialSpherical[2], theta);
//printf("The current angles are: phi is %f°, theta is %f°. \n", phi, theta);
//printf("Saved theta is %f, current one is %f. \n", initialSpherical[2], theta);
spherical[0] = r;
spherical[1] = phi;
......@@ -143,7 +143,7 @@ void spotlightManager::updatePTvalues(){
// type conversion works properly that way.
//Pan:
deviation = (spherical[1]-initialSpherical[1])*phiDmxPan; // stays within 0 and 170
deviation = (spherical[1]-initialSpherical[1])*phiDmxPan; // Minus sign because positive tilt DMX is in negative theta direction
// printf("Pan deviation (DMX): %f \n", deviation);
// overlap situation
......@@ -166,7 +166,7 @@ void spotlightManager::updatePTvalues(){
//Tilt:
deviation = (initialSpherical[2]-spherical[2])*thetaDmxTilt;
printf("Tilt deviation (DMX): %f \n", deviation);
//printf("Tilt deviation (DMX): %f \n", deviation);
hypo = (double) initialPT[2] + deviation;
if(hypo <= 0){ // constraint of the spotlight
......@@ -188,7 +188,7 @@ void spotlightManager::updatePTvalues(){
dmxValues[posPT+3] = unicorn;
}
printf("Saved tilt DMX is %i, new one %i.\n", initialPT[2], dmxValues[posPT+2]);
//printf("Saved tilt DMX is %i, new one %i.\n", initialPT[2], dmxValues[posPT+2]);
// send already. Buffering?
sL.writeSerialLight((buildPT()).c_str());
}
......@@ -317,19 +317,16 @@ void spotlightManager::calibrateOrientation(){
// Reacts to yaw changes of the target.
void spotlightManager::fancyColourFunction(double yaw){
// radians? yes...
//printf("Received new Yaw %f. \n", yaw);
int yaw_i = yaw*RAD2DEG;
dmxValues[9] = (int) ( ((yaw_i ) % 360)*255/360.0 ); // Red
dmxValues[10] = (int) ( ((yaw_i+120) % 360)*255/360.0 ); // Green
dmxValues[11] = (int) ( ((yaw_i+240) % 360)*255/360.0 ); // Blue
// White: 12
sL.writeSerialLight((buildColour()).c_str());
// need to adapt Bitrate?
//sendMessage... Or joust colour
sL.writeSerialLight((buildColour()).c_str());
}
// Covers the whole room.
......@@ -532,13 +529,24 @@ void spotlightManager::testPTupdater(){
// saves applied pan values in a file, along with a timestamp
void spotlightManager::lineWithLogging(int panWidth, int brightness, int zoom, double speed, bool loadTimeToSynchro){
double panToPhi = 360/170.0; // save as constant somewhere...
ofstream panLog;
panLog.open("loggedPanValues.txt", ofstream::out | ofstream::trunc);
panLog << "time\tDMX pan\t"<<"Dataset with " << brightness << " brightness, " << zoom << " zoom, " << speed << " speed. \n";
panLog.open("loggedPanValues_C.txt", ofstream::out | ofstream::trunc);
panLog << "time\tDMX pan\tDataset with " << brightness << " brightness, " << zoom << " zoom, " << panWidth*panToPhi/speed << "° angular speed\n";
panLog.flush();
setPTmanually(false);
//setPTmanually(false);
// specific setup for light sensor test:
someDefaultSettings();
if(zoom == 200){dmxValues[posPT] = 155; }
else if(zoom == 0){dmxValues[posPT] = 135; }
// end of specific setup
dmxValues[posPT+2] = 10;
double panStep = panWidth/(speed*updateFrequency); // need Precision here.
double delayUs = 1000000/updateFrequency;
......@@ -546,6 +554,8 @@ void spotlightManager::lineWithLogging(int panWidth, int brightness, int zoom, d
dmxValues[1] = brightness;
dmxValues[2] = zoom;
sL.writeSerialLight((buildMessage()).c_str());
usleep(1000000); // Wait a second. Looks cooler.
......@@ -572,20 +582,17 @@ void spotlightManager::lineWithLogging(int panWidth, int brightness, int zoom, d
startTime = std::chrono::high_resolution_clock::now();
}
*/
while(true){
bool keepDoingIt = true;
while(keepDoingIt){
// one pass
for(int mm = 0; mm < steps; mm++){
if(bumerang){precisePan+=panStep;}else{precisePan-=panStep;}
// logging
//std::chrono::high_resolution_clock::time_point cbTime = std::chrono::high_resolution_clock::now();
//timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(cbTime - 0).count();
//timestamp =
chrono::high_resolution_clock::time_point cbTime = chrono::high_resolution_clock::now();
timestamp = chrono::duration_cast<chrono::nanoseconds>(cbTime-startTime).count();
panLog << timestamp << "\t" << precisePan << "\n";
// panLog << time(0) << "\t" << precisePan << "\n";
panLog.flush();
......@@ -596,6 +603,19 @@ void spotlightManager::lineWithLogging(int panWidth, int brightness, int zoom, d
sL.writeSerialLight((buildPT()).c_str());
usleep(delayUs);
}
// specifically for the light sensor tests
if(!bumerang){keepDoingIt = false; }// just one swipe this time.
else{
if(zoom == 200){
dmxValues[posPT+2] += 10;
}else if(zoom == 0){
dmxValues[posPT+2] += 20;
}
sL.writeSerialLight((buildPT().c_str()));
}
// end of specific stuff
bumerang = !bumerang;
}
}
\ No newline at end of file
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