mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 05:56:02 +08:00
SPE-1872: Fixes in calculating actual speed
This commit is contained in:
parent
e4a3fb3b45
commit
268b5860fd
@ -201,7 +201,7 @@ void GCodeProcessor::TimeBlock::calculate_trapezoid()
|
|||||||
acceleration * trapezoid.deceleration_time(distance, acceleration);
|
acceleration * trapezoid.deceleration_time(distance, acceleration);
|
||||||
const float delta_exit_speed_percent = std::abs(100.0f * (new_exit_speed - feedrate_profile.exit) / feedrate_profile.exit);
|
const float delta_exit_speed_percent = std::abs(100.0f * (new_exit_speed - feedrate_profile.exit) / feedrate_profile.exit);
|
||||||
if (delta_exit_speed_percent > 1.0f) {
|
if (delta_exit_speed_percent > 1.0f) {
|
||||||
// what to do in this case ?
|
// what to do in this case ?
|
||||||
}
|
}
|
||||||
#endif // ENABLE_ET_SPE1872
|
#endif // ENABLE_ET_SPE1872
|
||||||
}
|
}
|
||||||
@ -372,7 +372,7 @@ static void recalculate_trapezoids(std::vector<GCodeProcessor::TimeBlock>& block
|
|||||||
GCodeProcessor::TimeBlock* next = nullptr;
|
GCodeProcessor::TimeBlock* next = nullptr;
|
||||||
|
|
||||||
for (size_t i = 0; i < blocks.size(); ++i) {
|
for (size_t i = 0; i < blocks.size(); ++i) {
|
||||||
GCodeProcessor::TimeBlock& b = blocks[i];
|
GCodeProcessor::TimeBlock& b = blocks[i];
|
||||||
|
|
||||||
curr = next;
|
curr = next;
|
||||||
next = &b;
|
next = &b;
|
||||||
@ -441,42 +441,71 @@ void GCodeProcessor::TimeMachine::calculate_time(size_t keep_last_n_blocks, floa
|
|||||||
// detect actual speed moves required to render toolpaths using actual speed
|
// detect actual speed moves required to render toolpaths using actual speed
|
||||||
if (mode == PrintEstimatedStatistics::ETimeMode::Normal) {
|
if (mode == PrintEstimatedStatistics::ETimeMode::Normal) {
|
||||||
GCodeProcessorResult::MoveVertex& curr_move = result.moves[block.move_id];
|
GCodeProcessorResult::MoveVertex& curr_move = result.moves[block.move_id];
|
||||||
|
if (curr_move.type != EMoveType::Extrude)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
assert(curr_move.actual_feedrate == 0.0f);
|
||||||
const GCodeProcessorResult::MoveVertex& prev_move = result.moves[block.move_id - 1];
|
const GCodeProcessorResult::MoveVertex& prev_move = result.moves[block.move_id - 1];
|
||||||
const Vec3f move_vector = curr_move.position - prev_move.position;
|
const bool interpolate = (prev_move.type == EMoveType::Extrude);
|
||||||
|
|
||||||
assert(curr_move.actual_speed == 0.0f);
|
if (block.trapezoid.acceleration_distance() > EPSILON) {
|
||||||
|
|
||||||
// acceleration phase
|
|
||||||
if (EPSILON < block.trapezoid.accelerate_until && block.trapezoid.accelerate_until < block.distance - EPSILON) {
|
|
||||||
const float t = block.trapezoid.accelerate_until / block.distance;
|
const float t = block.trapezoid.accelerate_until / block.distance;
|
||||||
const float width = (prev_move.type == EMoveType::Extrude) ? prev_move.width + t * (curr_move.width - prev_move.width) : curr_move.width;
|
const Vec3f position = lerp(prev_move.position, curr_move.position, t);
|
||||||
const float height = (prev_move.type == EMoveType::Extrude) ? prev_move.height + t * (curr_move.height - prev_move.height) : curr_move.height;
|
const float delta_extruder = interpolate ? lerp(prev_move.delta_extruder, curr_move.delta_extruder, t) : curr_move.delta_extruder;
|
||||||
|
const float feedrate = interpolate ? lerp(prev_move.feedrate, curr_move.feedrate, t) : curr_move.feedrate;
|
||||||
|
const float width = interpolate ? lerp(prev_move.width, curr_move.width, t) : curr_move.width;
|
||||||
|
const float height = interpolate ? lerp(prev_move.height, curr_move.height, t) : curr_move.height;
|
||||||
|
const float mm3_per_mm = interpolate ? lerp(prev_move.mm3_per_mm, curr_move.mm3_per_mm, t) : curr_move.mm3_per_mm;
|
||||||
|
const float fan_speed = interpolate ? lerp(prev_move.fan_speed, curr_move.fan_speed, t) : curr_move.fan_speed;
|
||||||
|
const float temperature = interpolate ? lerp(prev_move.temperature, curr_move.temperature, t) : curr_move.temperature;
|
||||||
actual_speed_moves.push_back({
|
actual_speed_moves.push_back({
|
||||||
block.move_id,
|
block.move_id,
|
||||||
|
position,
|
||||||
block.feedrate_profile.cruise,
|
block.feedrate_profile.cruise,
|
||||||
prev_move.position + t * move_vector,
|
delta_extruder,
|
||||||
|
feedrate,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
mm3_per_mm,
|
||||||
|
fan_speed,
|
||||||
|
temperature
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// cruise phase
|
|
||||||
if (block.trapezoid.accelerate_until + EPSILON < block.trapezoid.decelerate_after &&
|
const bool has_deceleration = block.trapezoid.deceleration_distance(block.distance) > EPSILON;
|
||||||
block.trapezoid.decelerate_after < block.distance - EPSILON) {
|
if (has_deceleration) {
|
||||||
const float t = block.trapezoid.decelerate_after / block.distance;
|
const float t = block.trapezoid.decelerate_after / block.distance;
|
||||||
const float width = (prev_move.type == EMoveType::Extrude) ? prev_move.width + t * (curr_move.width - prev_move.width) : curr_move.width;
|
const Vec3f position = lerp(prev_move.position, curr_move.position, t);
|
||||||
const float height = (prev_move.type == EMoveType::Extrude) ? prev_move.height + t * (curr_move.height - prev_move.height) : curr_move.height;
|
const float delta_extruder = interpolate ? lerp(prev_move.delta_extruder, curr_move.delta_extruder, t) : curr_move.delta_extruder;
|
||||||
|
const float feedrate = interpolate ? lerp(prev_move.feedrate, curr_move.feedrate, t) : curr_move.feedrate;
|
||||||
|
const float width = interpolate ? lerp(prev_move.width, curr_move.width, t) : curr_move.width;
|
||||||
|
const float height = interpolate ? lerp(prev_move.height, curr_move.height, t) : curr_move.height;
|
||||||
|
const float mm3_per_mm = interpolate ? lerp(prev_move.mm3_per_mm, curr_move.mm3_per_mm, t) : curr_move.mm3_per_mm;
|
||||||
|
const float fan_speed = interpolate ? lerp(prev_move.fan_speed, curr_move.fan_speed, t) : curr_move.fan_speed;
|
||||||
|
const float temperature = interpolate ? lerp(prev_move.temperature, curr_move.temperature, t) : curr_move.temperature;
|
||||||
actual_speed_moves.push_back({
|
actual_speed_moves.push_back({
|
||||||
block.move_id,
|
block.move_id,
|
||||||
|
position,
|
||||||
block.feedrate_profile.cruise,
|
block.feedrate_profile.cruise,
|
||||||
prev_move.position + t * move_vector,
|
delta_extruder,
|
||||||
|
feedrate,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
mm3_per_mm,
|
||||||
|
fan_speed,
|
||||||
|
temperature
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// deceleration/exit phase
|
|
||||||
|
const bool is_cruise_only = block.trapezoid.is_cruise_only(block.distance);
|
||||||
actual_speed_moves.push_back({
|
actual_speed_moves.push_back({
|
||||||
block.move_id,
|
block.move_id,
|
||||||
block.feedrate_profile.exit,
|
std::nullopt,
|
||||||
|
(is_cruise_only || !has_deceleration) ? block.feedrate_profile.cruise : block.feedrate_profile.exit,
|
||||||
|
std::nullopt,
|
||||||
|
std::nullopt,
|
||||||
|
std::nullopt,
|
||||||
|
std::nullopt,
|
||||||
std::nullopt,
|
std::nullopt,
|
||||||
std::nullopt,
|
std::nullopt,
|
||||||
std::nullopt
|
std::nullopt
|
||||||
@ -4875,11 +4904,14 @@ void GCodeProcessor::calculate_time(GCodeProcessorResult& result, size_t keep_la
|
|||||||
// override modified parameters
|
// override modified parameters
|
||||||
new_move.time = { 0.0f, 0.0f };
|
new_move.time = { 0.0f, 0.0f };
|
||||||
new_move.position = *it->position;
|
new_move.position = *it->position;
|
||||||
new_move.actual_speed = it->feedrate;
|
new_move.actual_feedrate = it->actual_feedrate;
|
||||||
if (it->width.has_value())
|
new_move.delta_extruder = *it->delta_extruder;
|
||||||
new_move.width = *it->width;
|
new_move.feedrate = *it->feedrate;
|
||||||
if (it->height.has_value())
|
new_move.width = *it->width;
|
||||||
new_move.height = *it->height;
|
new_move.height = *it->height;
|
||||||
|
new_move.mm3_per_mm = *it->mm3_per_mm;
|
||||||
|
new_move.fan_speed = *it->fan_speed;
|
||||||
|
new_move.temperature = *it->temperature;
|
||||||
new_move.internal_only = true;
|
new_move.internal_only = true;
|
||||||
new_moves.push_back(new_move);
|
new_moves.push_back(new_move);
|
||||||
}
|
}
|
||||||
@ -4887,19 +4919,16 @@ void GCodeProcessor::calculate_time(GCodeProcessorResult& result, size_t keep_la
|
|||||||
result.moves.insert(result.moves.begin() + base_id, new_moves.begin(), new_moves.end());
|
result.moves.insert(result.moves.begin() + base_id, new_moves.begin(), new_moves.end());
|
||||||
id_map[it->move_id] = base_id + new_moves.size();
|
id_map[it->move_id] = base_id + new_moves.size();
|
||||||
// update move actual speed
|
// update move actual speed
|
||||||
result.moves[base_id + new_moves.size()].actual_speed = it->feedrate;
|
result.moves[base_id + new_moves.size()].actual_feedrate = it->actual_feedrate;
|
||||||
inserted_actual_speed_moves_count += new_moves.size();
|
inserted_actual_speed_moves_count += new_moves.size();
|
||||||
new_moves.clear();
|
new_moves.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// synchronize blocks' move_ids with after actual speed moves insertion
|
// synchronize blocks' move_ids with after moves for actual speed insertion
|
||||||
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
|
for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Count); ++i) {
|
||||||
for (GCodeProcessor::TimeBlock& block : m_time_processor.machines[i].blocks) {
|
for (GCodeProcessor::TimeBlock& block : m_time_processor.machines[i].blocks) {
|
||||||
auto it = id_map.find(block.move_id);
|
auto it = id_map.find(block.move_id);
|
||||||
if (it != id_map.end()) {
|
|
||||||
int a = 0;
|
|
||||||
}
|
|
||||||
block.move_id = (it != id_map.end()) ? it->second : block.move_id + inserted_actual_speed_moves_count;
|
block.move_id = (it != id_map.end()) ? it->second : block.move_id + inserted_actual_speed_moves_count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ namespace Slic3r {
|
|||||||
float delta_extruder{ 0.0f }; // mm
|
float delta_extruder{ 0.0f }; // mm
|
||||||
float feedrate{ 0.0f }; // mm/s
|
float feedrate{ 0.0f }; // mm/s
|
||||||
#if ENABLE_ET_SPE1872
|
#if ENABLE_ET_SPE1872
|
||||||
float actual_speed{ 0.0f }; // mm/s
|
float actual_feedrate{ 0.0f }; // mm/s
|
||||||
#endif // ENABLE_ET_SPE1872
|
#endif // ENABLE_ET_SPE1872
|
||||||
float width{ 0.0f }; // mm
|
float width{ 0.0f }; // mm
|
||||||
float height{ 0.0f }; // mm
|
float height{ 0.0f }; // mm
|
||||||
@ -293,6 +293,7 @@ namespace Slic3r {
|
|||||||
float acceleration_distance() const { return accelerate_until; }
|
float acceleration_distance() const { return accelerate_until; }
|
||||||
float cruise_distance() const { return decelerate_after - accelerate_until; }
|
float cruise_distance() const { return decelerate_after - accelerate_until; }
|
||||||
float deceleration_distance(float distance) const { return distance - decelerate_after; }
|
float deceleration_distance(float distance) const { return distance - decelerate_after; }
|
||||||
|
bool is_cruise_only(float distance) const { return std::abs(cruise_distance() - distance) < EPSILON; }
|
||||||
#else
|
#else
|
||||||
float cruise_distance() const;
|
float cruise_distance() const;
|
||||||
#endif // ENABLE_ET_SPE1872
|
#endif // ENABLE_ET_SPE1872
|
||||||
@ -368,10 +369,15 @@ namespace Slic3r {
|
|||||||
struct ActualSpeedMove
|
struct ActualSpeedMove
|
||||||
{
|
{
|
||||||
unsigned int move_id{ 0 };
|
unsigned int move_id{ 0 };
|
||||||
float feedrate{ 0.0f };
|
|
||||||
std::optional<Vec3f> position;
|
std::optional<Vec3f> position;
|
||||||
std::optional<float> width{ 0.0f };
|
float actual_feedrate{ 0.0f };
|
||||||
std::optional<float> height{ 0.0f };
|
std::optional<float> delta_extruder;
|
||||||
|
std::optional<float> feedrate;
|
||||||
|
std::optional<float> width;
|
||||||
|
std::optional<float> height;
|
||||||
|
std::optional<float> mm3_per_mm;
|
||||||
|
std::optional<float> fan_speed;
|
||||||
|
std::optional<float> temperature;
|
||||||
};
|
};
|
||||||
#endif // ENABLE_ET_SPE1872
|
#endif // ENABLE_ET_SPE1872
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ struct PathVertex
|
|||||||
//
|
//
|
||||||
// Segment actual speed
|
// Segment actual speed
|
||||||
//
|
//
|
||||||
float actual_speed{ 0.0f };
|
float actual_feedrate{ 0.0f };
|
||||||
#endif // VGCODE_ENABLE_ET_SPE1872
|
#endif // VGCODE_ENABLE_ET_SPE1872
|
||||||
//
|
//
|
||||||
// Segment fan speed
|
// Segment fan speed
|
||||||
|
@ -972,7 +972,7 @@ Color ViewerImpl::get_vertex_color(const PathVertex& v) const
|
|||||||
#if VGCODE_ENABLE_ET_SPE1872
|
#if VGCODE_ENABLE_ET_SPE1872
|
||||||
case EViewType::ActualSpeed:
|
case EViewType::ActualSpeed:
|
||||||
{
|
{
|
||||||
return m_actual_speed_range.get_color_at(v.actual_speed);
|
return m_actual_speed_range.get_color_at(v.actual_feedrate);
|
||||||
}
|
}
|
||||||
#endif // VGCODE_ENABLE_ET_SPE1872
|
#endif // VGCODE_ENABLE_ET_SPE1872
|
||||||
case EViewType::FanSpeed:
|
case EViewType::FanSpeed:
|
||||||
@ -1292,7 +1292,7 @@ void ViewerImpl::update_color_ranges()
|
|||||||
#if VGCODE_ENABLE_ET_SPE1872
|
#if VGCODE_ENABLE_ET_SPE1872
|
||||||
if ((v.is_travel() && m_settings.options_visibility.at(EOptionType::Travels)) || v.is_extrusion()) {
|
if ((v.is_travel() && m_settings.options_visibility.at(EOptionType::Travels)) || v.is_extrusion()) {
|
||||||
m_speed_range.update(v.feedrate);
|
m_speed_range.update(v.feedrate);
|
||||||
m_actual_speed_range.update(v.actual_speed);
|
m_actual_speed_range.update(v.actual_feedrate);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if ((v.is_travel() && m_settings.options_visibility.at(EOptionType::Travels)) || v.is_extrusion())
|
if ((v.is_travel() && m_settings.options_visibility.at(EOptionType::Travels)) || v.is_extrusion())
|
||||||
|
@ -214,12 +214,12 @@ GCodeInputData convert(const Slic3r::GCodeProcessorResult& result, const std::ve
|
|||||||
// and the times, which are set to zero
|
// and the times, which are set to zero
|
||||||
#if ENABLE_ET_SPE1872
|
#if ENABLE_ET_SPE1872
|
||||||
#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||||
const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, prev.actual_speed,
|
const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, prev.actual_feedrate,
|
||||||
curr.fan_speed, curr.temperature, curr.volumetric_rate(), 0.0f, convert(curr.extrusion_role), curr_type,
|
curr.fan_speed, curr.temperature, curr.volumetric_rate(), 0.0f, convert(curr.extrusion_role), curr_type,
|
||||||
static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
|
static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
|
||||||
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f } };
|
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f } };
|
||||||
#else
|
#else
|
||||||
const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, prev.actual_speed,
|
const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, prev.actual_feedrate,
|
||||||
curr.fan_speed, curr.temperature, curr.volumetric_rate(), convert(curr.extrusion_role), curr_type,
|
curr.fan_speed, curr.temperature, curr.volumetric_rate(), convert(curr.extrusion_role), curr_type,
|
||||||
static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
|
static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
|
||||||
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f } };
|
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f } };
|
||||||
@ -243,13 +243,13 @@ GCodeInputData convert(const Slic3r::GCodeProcessorResult& result, const std::ve
|
|||||||
|
|
||||||
#if ENABLE_ET_SPE1872
|
#if ENABLE_ET_SPE1872
|
||||||
#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
#if VGCODE_ENABLE_COG_AND_TOOL_MARKERS
|
||||||
const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.actual_speed,
|
const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.actual_feedrate,
|
||||||
curr.fan_speed, curr.temperature, curr.volumetric_rate(),
|
curr.fan_speed, curr.temperature, curr.volumetric_rate(),
|
||||||
result.filament_densities[curr.extruder_id] * curr.mm3_per_mm * (curr.position - prev.position).norm(),
|
result.filament_densities[curr.extruder_id] * curr.mm3_per_mm * (curr.position - prev.position).norm(),
|
||||||
convert(curr.extrusion_role), curr_type, static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
|
convert(curr.extrusion_role), curr_type, static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
|
||||||
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), curr.time };
|
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), curr.time };
|
||||||
#else
|
#else
|
||||||
const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.actual_speed,
|
const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.actual_feedrate,
|
||||||
curr.fan_speed, curr.temperature, curr.volumetric_rate(), convert(curr.extrusion_role), curr_type,
|
curr.fan_speed, curr.temperature, curr.volumetric_rate(), convert(curr.extrusion_role), curr_type,
|
||||||
static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id), static_cast<uint8_t>(curr.extruder_id),
|
static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id), static_cast<uint8_t>(curr.extruder_id),
|
||||||
static_cast<uint8_t>(curr.cp_color_id), curr.time };
|
static_cast<uint8_t>(curr.cp_color_id), curr.time };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user