Merge pull request #934 from wolfmanjm/upstreamedge
authorJim Morris <morris@wolfman.com>
Mon, 30 May 2016 23:00:15 +0000 (16:00 -0700)
committerJim Morris <morris@wolfman.com>
Mon, 30 May 2016 23:00:15 +0000 (16:00 -0700)
make the cnc test circle use G2

src/modules/robot/Robot.cpp
src/modules/utils/simpleshell/SimpleShell.cpp

index ec176a8..9ed88ff 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "mbed.h" // for us_ticker_read()
 
-#include <math.h>
+#include <fastmath.h>
 #include <string>
 using std::string;
 
@@ -1000,15 +1000,15 @@ bool Robot::append_arc(Gcode * gcode, const float target[], const float offset[]
 
     // Patch from GRBL Firmware - Christoph Baumann 04072015
     // CCW angle between position and target from circle center. Only one atan2() trig computation required.
-    float angular_travel = atan2(r_axis0 * rt_axis1 - r_axis1 * rt_axis0, r_axis0 * rt_axis0 + r_axis1 * rt_axis1);
+    float angular_travel = atan2f(r_axis0 * rt_axis1 - r_axis1 * rt_axis0, r_axis0 * rt_axis0 + r_axis1 * rt_axis1);
     if (is_clockwise) { // Correct atan2 output per direction
-        if (angular_travel >= -ARC_ANGULAR_TRAVEL_EPSILON) { angular_travel -= 2 * M_PI; }
+        if (angular_travel >= -ARC_ANGULAR_TRAVEL_EPSILON) { angular_travel -= (2 * (float)M_PI); }
     } else {
-        if (angular_travel <= ARC_ANGULAR_TRAVEL_EPSILON) { angular_travel += 2 * M_PI; }
+        if (angular_travel <= ARC_ANGULAR_TRAVEL_EPSILON) { angular_travel += (2 * (float)M_PI); }
     }
 
     // Find the distance for this gcode
-    gcode->millimeters_of_travel = hypotf(angular_travel * radius, fabs(linear_travel));
+    gcode->millimeters_of_travel = hypotf(angular_travel * radius, fabsf(linear_travel));
 
     // We don't care about non-XYZ moves ( for example the extruder produces some of those )
     if( gcode->millimeters_of_travel < 0.00001F ) {
index c5de246..cc06465 100644 (file)
@@ -966,39 +966,31 @@ void SimpleShell::test_command( string parameters, StreamOutput *stream)
         stream->printf("done\n");
 
     }else if (what == "circle") {
-        // draws a circle around current position. usage: radius segments iterations [feedrate]
+        // draws a circle around origin. usage: radius iterations [feedrate]
         string radius = shift_parameter( parameters );
-        string segments = shift_parameter( parameters );
         string iters = shift_parameter( parameters );
         string speed = shift_parameter( parameters );
-         if(radius.empty() || segments.empty() || iters.empty()) {
-            stream->printf("error: Need radius segments iterations\n");
+         if(radius.empty() || iters.empty()) {
+            stream->printf("error: Need radius iterations\n");
             return;
         }
 
         float r= strtof(radius.c_str(), NULL);
-        uint32_t s= strtol(segments.c_str(), NULL, 10);
         uint32_t n= strtol(iters.c_str(), NULL, 10);
         float f= speed.empty() ? THEKERNEL->robot->get_feed_rate() : strtof(speed.c_str(), NULL);
-        float xoff, yoff;
-        std::tie(xoff, yoff, std::ignore) = THEKERNEL->robot->mcs2wcs(THEKERNEL->robot->get_axis_position());
+
         char cmd[64];
-        snprintf(cmd, sizeof(cmd), "G90\n");
+        snprintf(cmd, sizeof(cmd), "G0 X%f Y0 F%f", -r, f);
+        stream->printf("%s\n", cmd);
         struct SerialMessage message{&StreamOutput::NullStream, cmd};
         THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message );
 
         for (uint32_t i = 0; i < n; ++i) {
-            for(uint32_t a=0;a<s;a++) {
-                snprintf(cmd, sizeof(cmd), "G0 X%f Y%f F%f",
-                    xoff + (sinf(a * (360.0F / s) * (float)M_PI / 180.0F) * r),
-                    yoff + (cosf(a * (360.0F / s) * (float)M_PI / 180.0F) * r),
-                    f);
-                stream->printf("%s\n", cmd);
-                message.message= cmd;
-                THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message );
-                if(THEKERNEL->is_halted()) break;
-            }
             if(THEKERNEL->is_halted()) break;
+            snprintf(cmd, sizeof(cmd), "G2 X%f Y0 I%f J0 F%f", -r, r, f);
+            stream->printf("%s\n", cmd);
+            message.message= cmd;
+            THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message );
             THEKERNEL->conveyor->wait_for_empty_queue();
         }
         stream->printf("done\n");
@@ -1050,7 +1042,7 @@ void SimpleShell::test_command( string parameters, StreamOutput *stream)
     }else {
         stream->printf("usage:\n test jog axis distance iterations [feedrate]\n");
         stream->printf(" test square size iterations [feedrate]\n");
-        stream->printf(" test circle radius segments iterations [feedrate]\n");
+        stream->printf(" test circle radius iterations [feedrate]\n");
     }
 }
 #endif