From a83e9ba861a93428112b5fd2a0fda6dbc734e929 Mon Sep 17 00:00:00 2001
From: Paul Beuchat <beuchatp@control.ee.ethz.ch>
Date: Sun, 7 Jul 2019 03:51:52 +0200
Subject: [PATCH] Tested to be working with a network of 1 teacher, 1 student
 laptop, 1 raspberry pi, and 1 student GUI laptop. Added line to Config.sh for
 how to run as a teacher (aka dfallmaster), and adjust Radio Emulator to wrap
 back around for command above 65535

---
 dfall_ws/src/dfall_pkg/launch/Config.sh                   | 4 +++-
 dfall_ws/src/dfall_pkg/src/classes/QuadrotorSimulator.cpp | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/dfall_ws/src/dfall_pkg/launch/Config.sh b/dfall_ws/src/dfall_pkg/launch/Config.sh
index 1aa9fac5..fcd2c5ea 100755
--- a/dfall_ws/src/dfall_pkg/launch/Config.sh
+++ b/dfall_ws/src/dfall_pkg/launch/Config.sh
@@ -1,7 +1,9 @@
 # TO RUN THE SYSTEM FULLY ON THE LOCAL COMPUTER:
 #export ROS_MASTER_URI=http://localhost:11311
-# TO RUN THE SYSTEM ON A DEFAULT CONFIGURATION OF THE NETWROK:
+# TO RUN THE SYSTEM AS AN AGENT ON A DEFAULT CONFIGURATION OF THE NETWROK:
 export ROS_MASTER_URI=http://dfallmaster:11311
+# TO RUN THE SYSTEM AS A ROS-MASTER ON A DEFAULT CONFIGURATION OF THE NETWROK:
+#export ROS_HOSTNAME=teacher
 # OTHER NECESSARY ENVIRONMENT VARIABLES:
 export ROS_IP=$(hostname -I | awk '{print $1;}')
 export DFALL_DEFAULT_AGENT_ID=$(cat /etc/dfall_default_agent_id)
diff --git a/dfall_ws/src/dfall_pkg/src/classes/QuadrotorSimulator.cpp b/dfall_ws/src/dfall_pkg/src/classes/QuadrotorSimulator.cpp
index 92e45dc9..4741dde7 100644
--- a/dfall_ws/src/dfall_pkg/src/classes/QuadrotorSimulator.cpp
+++ b/dfall_ws/src/dfall_pkg/src/classes/QuadrotorSimulator.cpp
@@ -464,7 +464,7 @@ void QuadrotorSimulator::subscribe_to_commanding_agent_id( int commanding_agent_
 float QuadrotorSimulator::convert_16_bit_motor_command_to_newtons( int motor_command )
 {
 	// Convert the command to a float
-	float cmd = float( motor_command );
+	float cmd = fmod( float( motor_command ) , 65535.0 );
 
 	// Saturate it
 	if (cmd < this->m_command_sixteenbit_min)
-- 
GitLab