Skip to content

Commit

Permalink
Implement basic translation from gcode ast to command list
Browse files Browse the repository at this point in the history
CURA-10561
  • Loading branch information
casperlamboo committed Oct 24, 2023
1 parent 3681de5 commit 13dda18
Show file tree
Hide file tree
Showing 9 changed files with 458 additions and 128 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ set(DULCIFICUM_SRC
src/miracle_jtp/mgjtp_command_to_json.cpp
src/miracle_jtp/mgjtp_json_to_command.cpp

src/proto_path/translate.cpp
src/gcode/gcode_to_command.cpp

src/utils/io.cpp
src/utils/svtod.cpp
Expand Down
13 changes: 11 additions & 2 deletions apps/translator_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

#include <docopt/docopt.h>
#include <dulcificum/gcode/parse.h>
#include <dulcificum/proto_path/translate.h>
#include <dulcificum/miracle_jtp/mgjtp_command_to_json.h>
#include <dulcificum/gcode/gcode_to_command.h>
#include <dulcificum/utils/io.h>
#include <map>

#include <nlohmann/json.hpp>

template<typename... Ts>
struct Overload : Ts...
{
Expand Down Expand Up @@ -38,7 +41,13 @@ int main(int argc, const char** argv)

auto input{ dulcificum::utils::readFile(args.at("INPUT").asString()).value() };
auto gcode_ast = dulcificum::gcode::parse(input);
auto proto_path_ast = dulcificum::proto_path::translate(gcode_ast);
auto command_list = dulcificum::gcode::toCommand(gcode_ast);

auto json_commands = nlohmann::json::array();
for (const auto& command: command_list)
{
json_commands.emplace_back(dulcificum::miracle_jtp::toJson(*command));
}

auto x = 1;
}
14 changes: 14 additions & 0 deletions include/dulcificum/gcode/gcode_to_command.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef INCLUDE_DULCIFICUM_GCODE_TO_COMMAND_H
#define INCLUDE_DULCIFICUM_GCODE_TO_COMMAND_H

#include "dulcificum/gcode/ast/ast.h"
#include "dulcificum/command_types.h"

namespace dulcificum::gcode
{

botcmd::CommandList toCommand(gcode::ast::ast_t& gcode);

} // namespace dulcificum::gcode

#endif // INCLUDE_DULCIFICUM_GCODE_TO_COMMAND_H
20 changes: 0 additions & 20 deletions include/dulcificum/proto_path/ast/ast.h

This file was deleted.

56 changes: 0 additions & 56 deletions include/dulcificum/proto_path/ast/translate.h

This file was deleted.

14 changes: 0 additions & 14 deletions include/dulcificum/proto_path/translate.h

This file was deleted.

63 changes: 63 additions & 0 deletions include/dulcificum/state.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef INCLUDE_DULCIFICUM_STATE_H
#define INCLUDE_DULCIFICUM_STATE_H

#include <cstddef>
#include <map>
#include <memory>
#include <string_view>
#include <variant>
#include <vector>
#include <set>

namespace dulcificum
{

enum class Positioning
{
Absolute,
Relative,
};

struct State
{
unsigned int num_extruders{ 2 };
unsigned int active_tool{ 0 };

unsigned int layer{ 0 };
std::string_view mesh{ "" };
std::string_view feature_type{ "" };

// needed for g92 commands, which set the current position
// of the extruder, and thereby changing the origin
double origin_x{ 0.0 };
double origin_y{ 0.0 };
double origin_z{ 0.0 };

double X{ 0.0 };
Positioning X_positioning{ Positioning::Absolute };

double Y{ 0.0 };
Positioning Y_positioning{ Positioning::Absolute };

double Z{ 0.0 };
Positioning Z_positioning{ Positioning::Absolute };

std::vector<double> E = std::vector<double>(num_extruders, 0.0);
Positioning E_positioning{ Positioning::Absolute };

std::vector<double> F = std::vector<double>(num_extruders, 0.0);

std::vector<double> extruder_temperatures = std::vector<double>(num_extruders, 0.0);

double fan_speed { 0.0 };

double build_plate_temperature{ 0.0 };

double chamber_temperature{ 0.0 };
};

using state_t = State;

} // namespace dulcificum

#endif // INCLUDE_DULCIFICUM_STATE_H
Loading

0 comments on commit 13dda18

Please sign in to comment.