Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tagging to add bead mode tags #29

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions include/dulcificum/command_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ enum class CommandType
Pause, // Command to allow for user defined pause.
};

#define MB_BEAD_MODE_TAG(TAG_NAME) \
TAG_NAME##_0, \
TAG_NAME##_1

enum class Tag
{
Invalid,
Expand All @@ -41,11 +45,20 @@ enum class Tag
Restart,
Retract,
Roof,
Support,
Sparse,
TravelMove
TravelMove,
MB_BEAD_MODE_TAG(Fill),
MB_BEAD_MODE_TAG(PrimeTower),
MB_BEAD_MODE_TAG(TopSurface),
MB_BEAD_MODE_TAG(Support),
MB_BEAD_MODE_TAG(SupportInterface),
MB_BEAD_MODE_TAG(WallOuter),
MB_BEAD_MODE_TAG(WallInner),
MB_BEAD_MODE_TAG(Skirt)
};

#undef MB_BEAD_MODE_TAG

using ExtruderIndex = size_t;

struct Command
Expand Down
43 changes: 31 additions & 12 deletions include/dulcificum/miracle_jtp/mgjtp_mappings_json_key_to_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,39 @@ NLOHMANN_JSON_SERIALIZE_ENUM(
{ CommandType::WaitForTemperature, "wait_for_temperature" },
{ CommandType::Pause, "pause" } })

#define MB_JTP_TAG(TAG_NAME, TAG_STR) \
{ Tag::TAG_NAME, #TAG_STR }

#define MB_BEAD_MODE_TAG_DEF(TAG_NAME, TAG_STR) \
MB_JTP_TAG(TAG_NAME##_0, TAG_STR##_0), \
MB_JTP_TAG(TAG_NAME##_1, TAG_STR##_1)

NLOHMANN_JSON_SERIALIZE_ENUM(
Tag,
{ { Tag::Invalid, "Invalid" },
{ Tag::Infill, "Infill" },
{ Tag::Inset, "Inset" },
{ Tag::Purge, "Purge" },
{ Tag::QuickToggle, "Quick Toggle" },
{ Tag::Raft, "Raft" },
{ Tag::Restart, "Restart" },
{ Tag::Retract, "Retract" },
{ Tag::Roof, "Roof" },
{ Tag::Sparse, "Sparse" },
{ Tag::Support, "Support" },
{ Tag::TravelMove, "Travel Move" } })
{
MB_JTP_TAG(Invalid, Invalid),
MB_JTP_TAG(Infill, Infill),
MB_JTP_TAG(Inset, Inset),
MB_JTP_TAG(Purge, Purge),
MB_JTP_TAG(QuickToggle, Quick Toggle),
MB_JTP_TAG(Raft, Raft),
MB_JTP_TAG(Restart, Restart),
MB_JTP_TAG(Retract, Retract),
MB_JTP_TAG(Roof, Roof),
MB_JTP_TAG(Sparse, Sparse),
MB_JTP_TAG(TravelMove, Travel Move),
MB_BEAD_MODE_TAG_DEF(Fill, FILL),
MB_BEAD_MODE_TAG_DEF(PrimeTower, PRIME_TOWER),
MB_BEAD_MODE_TAG_DEF(TopSurface, TOP_SURFACE),
MB_BEAD_MODE_TAG_DEF(Support, SUPPORT),
MB_BEAD_MODE_TAG_DEF(SupportInterface, SUPPORT_INTERFACE),
MB_BEAD_MODE_TAG_DEF(WallOuter, WALL_OUTER),
MB_BEAD_MODE_TAG_DEF(WallInner, WALL_INNER),
MB_BEAD_MODE_TAG_DEF(Skirt, SKIRT)
})

#undef MB_BEAD_MODE_TAG
#undef MB_JTP_TAG

} // namespace botcmd

Expand Down
97 changes: 87 additions & 10 deletions src/gcode/gcode_to_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ void VisitCommand::to_proto_path(const gcode::ast::G0_G1& command)
}
else
{
// NOTE: A move may only have a single bead mode tag
move->tags.emplace_back(botcmd::Tag::TravelMove);
return;
}
}
else if (delta_e < 0)
Expand All @@ -285,41 +287,116 @@ void VisitCommand::to_proto_path(const gcode::ast::G0_G1& command)
}
else if (delta_e == 0)
{
// NOTE: A move may only have a single bead mode tag
move->tags.emplace_back(botcmd::Tag::TravelMove);
return;
}
if (state.feature_type == "WALL-OUTER" || state.feature_type == "INNER-OUTER")

// Bead Mode Tags
// NOTE: A move may only have a single bead mode tag

if (state.feature_type == "WALL-OUTER")
{
move->tags.emplace_back(botcmd::Tag::Inset);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::WallOuter_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::WallOuter_1);
}
}
else if (state.feature_type == "WALL-INNER")
{
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::WallInner_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::WallInner_1);
}
}
else if (state.feature_type == "SKIN")
{
move->tags.emplace_back(botcmd::Tag::Roof);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::TopSurface_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::TopSurface_1);
}
}
else if (state.feature_type == "TOP-SURFACE")
{
move->tags.emplace_back(botcmd::Tag::Roof);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::TopSurface_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::TopSurface_1);
}
}
else if (state.feature_type == "PRIME-TOWER")
{
move->tags.emplace_back(botcmd::Tag::Purge);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::PrimeTower_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::PrimeTower_1);
}
}
else if (state.feature_type == "FILL")
{
move->tags.emplace_back(botcmd::Tag::Infill);
move->tags.emplace_back(botcmd::Tag::Sparse);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::Fill_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::Fill_1);
}
}
else if (state.feature_type == "Purge")
{
move->tags.emplace_back(botcmd::Tag::Raft);
}
else if (state.feature_type == "SUPPORT")
{
move->tags.emplace_back(botcmd::Tag::Sparse);
move->tags.emplace_back(botcmd::Tag::Support);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::Support_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::Support_1);
}
}
else if (state.feature_type == "SUPPORT-INTERFACE")
{
move->tags.emplace_back(botcmd::Tag::Support);
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::SupportInterface_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::SupportInterface_1);
}
}
else if (state.feature_type == "SKIRT")
{
if (state.active_tool == 0)
{
move->tags.emplace_back(botcmd::Tag::Skirt_0);
}
else
{
move->tags.emplace_back(botcmd::Tag::Skirt_1);
}
}
proto_path.emplace_back(move);
}
Expand Down
3 changes: 2 additions & 1 deletion tests/miracle_jsontoolpath_dialect_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ TEST(miracle_jtp_tests, fan_duty)
botcmd::FanDuty cmd;
cmd.index = 0;
cmd.duty = 0.12;
cmd.tags = { botcmd::Tag::TopSurface_1};
auto jcmd = miracle_jtp::toJson(cmd);
auto cmd1 = miracle_jtp::toCommand(jcmd);
auto jcmd1 = miracle_jtp::toJson(*cmd1);
EXPECT_EQ(jcmd, jcmd1);

EXPECT_EQ(nlohmann::to_string(jcmd), "{\"command\":{\"function\":\"fan_duty\",\"metadata\":{},\"parameters\":{\"index\":0,\"value\":0.12},\"tags\":[]}}");
EXPECT_EQ(nlohmann::to_string(jcmd), "{\"command\":{\"function\":\"fan_duty\",\"metadata\":{},\"parameters\":{\"index\":0,\"value\":0.12},\"tags\":[\"TOP_SURFACE_1\"]}}");
}

TEST(miracle_jtp_tests, rwrw)
Expand Down
Loading