1
0
Эх сурвалжийг харах

Standardize speed setting based on maxSpeed

Tuan Nguyen 1 жил өмнө
parent
commit
badafadeea

+ 13 - 6
arduino_code/arduino_code.ino

@@ -187,20 +187,27 @@ void appMode()
             return;
         }
 
+        // Example: The user calls "SET_SPEED 60" => 60% of maxSpeed
         if (input.startsWith("SET_SPEED"))
         {
-            // Parse and set the speed
+            // Parse out the speed value from the command string
             int spaceIndex = input.indexOf(' ');
             if (spaceIndex != -1)
             {
                 String speedStr = input.substring(spaceIndex + 1);
-                float speed = speedStr.toFloat();
+                float speedPercentage = speedStr.toFloat();
 
-                if (speed > 0) // Ensure valid speed
+                // Make sure the percentage is valid
+                if (speedPercentage >= 1.0 && speedPercentage <= 100.0)
                 {
-                    rotStepper.setMaxSpeed(speed);
-                    inOutStepper.setMaxSpeed(speed);
-                    Serial.println("SPEED_SET");
+                    // Convert percentage to actual speed
+                    long newSpeed = (speedPercentage / 100.0) * maxSpeed;
+
+                    // Set the stepper speeds
+                    rotStepper.setMaxSpeed(newSpeed);
+                    inOutStepper.setMaxSpeed(newSpeed);
+
+                    Serial.println("SPEED_SET");  
                     Serial.println("R");
                 }
                 else

+ 14 - 8
arduino_code_TMC2209/arduino_code_TMC2209.ino

@@ -40,7 +40,7 @@ float currentTheta = 0.0; // Current theta in radians
 float currentRho = 0.0;   // Current rho (0 to 1)
 bool isFirstCoordinates = true;
 float totalRevolutions = 0.0; // Tracks cumulative revolutions
-float maxSpeed = 1000;
+long maxSpeed = 1000;
 float maxAcceleration = 50;
 long interpolationResolution = 0.001;
 float userDefinedSpeed = maxSpeed; // Store user-defined speed
@@ -232,21 +232,27 @@ void appMode()
             return;
         }
 
+        // Example: The user calls "SET_SPEED 60" => 60% of maxSpeed
         if (input.startsWith("SET_SPEED"))
         {
-            // Parse and set the speed
+            // Parse out the speed value from the command string
             int spaceIndex = input.indexOf(' ');
             if (spaceIndex != -1)
             {
                 String speedStr = input.substring(spaceIndex + 1);
-                double speed = speedStr.toDouble();
+                float speedPercentage = speedStr.toFloat();
 
-                if (speed > 0) // Ensure valid speed
+                // Make sure the percentage is valid
+                if (speedPercentage >= 1.0 && speedPercentage <= 100.0)
                 {
-                    rotStepper.setMaxSpeed(speed);
-                    inOutStepper.setMaxSpeed(speed);
-                    Serial.print("SPEED_SET ");
-                    Serial.println(speed);
+                    // Convert percentage to actual speed
+                    long newSpeed = (speedPercentage / 100.0) * maxSpeed;
+
+                    // Set the stepper speeds
+                    rotStepper.setMaxSpeed(newSpeed);
+                    inOutStepper.setMaxSpeed(newSpeed);
+
+                    Serial.println("SPEED_SET");  
                     Serial.println("R");
                 }
                 else

+ 13 - 6
esp32/esp32.ino

@@ -81,20 +81,27 @@ void loop()
             return;
         }
 
+        // Example: The user calls "SET_SPEED 60" => 60% of maxSpeed
         if (input.startsWith("SET_SPEED"))
         {
-            // Parse and set the speed
+            // Parse out the speed value from the command string
             int spaceIndex = input.indexOf(' ');
             if (spaceIndex != -1)
             {
                 String speedStr = input.substring(spaceIndex + 1);
-                double speed = speedStr.toDouble();
+                float speedPercentage = speedStr.toFloat();
 
-                if (speed > 0) // Ensure valid speed
+                // Make sure the percentage is valid
+                if (speedPercentage >= 1.0 && speedPercentage <= 100.0)
                 {
-                    rotStepper.setMaxSpeed(speed);
-                    inOutStepper.setMaxSpeed(speed);
-                    Serial.println("SPEED_SET");
+                    // Convert percentage to actual speed
+                    long newSpeed = (speedPercentage / 100.0) * maxSpeed;
+
+                    // Set the stepper speeds
+                    rotStepper.setMaxSpeed(newSpeed);
+                    inOutStepper.setMaxSpeed(newSpeed);
+
+                    Serial.println("SPEED_SET");  
                     Serial.println("R");
                 }
                 else

+ 1 - 2
templates/index.html

@@ -26,7 +26,7 @@
                 </div>
                 <div class="button-group">
                     <label for="speed_input">Speed:</label>
-                    <input type="number" id="speed_input" placeholder="1-5000" min="1" step="1" max="5000">
+                    <input type="number" id="speed_input" placeholder="1-100" min="1" step="1" max="5000">
                     <button class="small-button"  onclick="changeSpeed()">Set Speed</button>
                 </div>
             </div>
@@ -95,7 +95,6 @@
                     </div>
                     <div class="button-group modeSection single_run">
                         <button id="run_button" disabled>Run Selected File</button>
-                        <button onclick="stopExecution()" class="delete-button">Stop</button>
                     </div>
                     <div class="button-group modeSection create_playlist" style="display: none;">
                         <button onclick="addToPlaylist()">Add File to Playlist</button>