Welcome to mirror list, hosted at ThFree Co, Russian Federation.

marlin_2.h « ArcWelderInverseProcessor - github.com/FormerLurker/ArcWelderLib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2abea56f93e7852bab5a7b04a7509b678dbcdc2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Arc Welder: Marlin 2 arc interpolation simulator.  Please see the copyright notices in the function definitions
// starting with plan_arc_ for the original license.
//
// Converts G2/G3(arc) commands back to G0/G1 commands.  Intended to test firmware changes to improve arc support.
// This reduces file size and the number of gcodes per second.
//
// Built using the 'Arc Welder: Anti Stutter' library
//
// Copyright(C) 2021 - Brad Hochgesang
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// This program is free software : you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program 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 Affero General Public License for more details.
//
//
// You can contact the author at the following email address: 
// FormerLurker@pm.me
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once
#include "firmware.h"


#define MARLIN_2_XYZE 4

class marlin_2 :
  public firmware
{
public:
  enum class marlin_2_firmware_versions { V2_0_9_1 = 0, V2_0_9_2 = 1};
  /// <summary>
  /// Types and enums taken from https://github.com/MarlinFirmware/Marlin/blob/cce585f6ca2235d0a534e8f3043d6d502b3bd93b/Marlin/src/core/types.h
  /// </summary>
  // This enum was simplified
  enum AxisEnum : uint8_t {
    X_AXIS=0, 
    Y_AXIS=1, 
    Z_AXIS=2, 
    E_AXIS=3,
  };
  
  marlin_2(firmware_arguments args);
  virtual ~marlin_2();
  virtual std::string interpolate_arc(firmware_position& target, double i, double j, double r, bool is_clockwise) override;
  virtual firmware_arguments get_default_arguments_for_current_version() const override;
  virtual void apply_arguments() override;
private:
  marlin_2_firmware_versions marlin_2_version_;
  std::string gcodes_;
  float* current_position;
  float feedrate_mm_s;
  /// <summary>
  /// A struct representing the prusa configuration store.  Note:  I didn't add the trailing underscore so this variable name will match the original source algorithm name.
  /// </summary>
  typedef void(marlin_2::* plan_arc_func)(
    const float(&cart)[MARLIN_2_XYZE],   // Destination position
    const float(&offset)[2], // Center of rotation relative to current_position
    const bool clockwise,     // Clockwise?
    const uint8_t circles     // Take the scenic route
  );

  void plan_arc_2_0_9_1(
    const float (&cart)[MARLIN_2_XYZE],   // Destination position
    const float (&offset)[2], // Center of rotation relative to current_position
    const bool clockwise,     // Clockwise?
    const uint8_t circles     // Take the scenic route
  );
  void plan_arc_2_0_9_2(
    const float(&cart)[MARLIN_2_XYZE],   // Destination position
    const float(&offset)[2], // Center of rotation relative to current_position
    const bool clockwise,     // Clockwise?
    const uint8_t circles     // Take the scenic route
  );
  
  bool buffer_line(const float(&cart)[MARLIN_2_XYZE], double fr_mm_s, int active_extruder);
  void apply_motion_limits(float (&pos)[MARLIN_2_XYZE]);
  plan_arc_func plan_arc_;

  // Marlin Function Defs
  void NOLESS(uint16_t& x, uint16_t y);
  float MMS_SCALED(float x);
  bool NEAR_ZERO(float x);
  bool NEAR(float x, float y);
  void COPY(float target[MARLIN_2_XYZE], const float(&source)[MARLIN_2_XYZE]);
};