本文整理汇总了C++中Gcode::get_value方法的典型用法代码示例。如果您正苦于以下问题:C++ Gcode::get_value方法的具体用法?C++ Gcode::get_value怎么用?C++ Gcode::get_value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gcode
的用法示例。
在下文中一共展示了Gcode::get_value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_gcode_execute
// Compute extrusion speed based on parameters and gcode distance of travel
void Extruder::on_gcode_execute(void* argument) {
Gcode* gcode = static_cast<Gcode*>(argument);
// Absolute/relative mode
if( gcode->has_m ) {
if( gcode->m == 82 ) {
this->absolute_mode = true;
}
if( gcode->m == 83 ) {
this->absolute_mode = false;
}
if( gcode->m == 84 ) {
this->en_pin->set(1);
}
}
// The mode is OFF by default, and SOLO or FOLLOW only if we need to extrude
this->mode = OFF;
if( gcode->has_g ) {
// G92: Reset extruder position
if( gcode->g == 92 ) {
if( gcode->has_letter('E') ) {
this->current_position = gcode->get_value('E');
this->target_position = this->current_position;
this->current_steps = int(floor(this->steps_per_millimeter * this->current_position));
} else if( gcode->get_num_args() == 0) {
this->current_position = 0.0;
this->target_position = this->current_position;
this->current_steps = 0;
}
} else {
// Extrusion length from 'G' Gcode
if( gcode->has_letter('E' )) {
// Get relative extrusion distance depending on mode ( in absolute mode we must substract target_position )
double relative_extrusion_distance = gcode->get_value('E');
if( this->absolute_mode == true ) {
relative_extrusion_distance = relative_extrusion_distance - this->target_position;
}
// If the robot is moving, we follow it's movement, otherwise, we move alone
if( fabs(gcode->millimeters_of_travel) < 0.0001 ) { // With floating numbers, we can have 0 != 0 ... beeeh. For more info see : http://upload.wikimedia.org/wikipedia/commons/0/0a/Cain_Henri_Vidal_Tuileries.jpg
this->mode = SOLO;
this->travel_distance = relative_extrusion_distance;
if( gcode->has_letter('F') ) {
this->feed_rate = gcode->get_value('F');
}
} else {
// We move proportionally to the robot's movement
this->mode = FOLLOW;
this->travel_ratio = relative_extrusion_distance / gcode->millimeters_of_travel;
}
this->en_pin->set(0);
}
}
}
}
示例2: on_gcode_execute
// Process and respond to eeprom gcodes (M50x)
void Configurator::on_gcode_execute(void* argument){
Gcode* gcode = static_cast<Gcode*>(argument);
if( gcode->has_letter('G') ){
int code = gcode->get_value('G');
switch( code ){
}
}
else if( gcode->has_letter('M') ){
int code = gcode->get_value('M');
switch( code ){
}
}
}
示例3: on_gcode_execute
void TemperatureControl::on_gcode_execute(void* argument){
Gcode* gcode = static_cast<Gcode*>(argument);
// Set temperature
if( gcode->has_letter('M') && gcode->get_value('M') == 104 && gcode->has_letter('S') ){
this->set_desired_temperature(gcode->get_value('S'));
}
// Get temperature
if( gcode->has_letter('M') && gcode->get_value('M') == 105 ){
this->kernel->serial->printf("get temperature: %f current:%f target:%f \r\n", this->get_temperature(), this->new_thermistor_reading(), this->desired_adc_value );
}
}
示例4: on_gcode_received
void SpindleControl::on_gcode_received(void *argument)
{
Gcode *gcode = static_cast<Gcode *>(argument);
if (gcode->has_m)
{
if (gcode->m == 957)
{
// M957: report spindle speed
report_speed();
}
else if (gcode->m == 958)
{
THECONVEYOR->wait_for_idle();
// M958: set spindle PID parameters
if (gcode->has_letter('P'))
set_p_term( gcode->get_value('P') );
if (gcode->has_letter('I'))
set_p_term( gcode->get_value('I') );
if (gcode->has_letter('D'))
set_p_term( gcode->get_value('D') );
// report PID settings
get_pid_settings();
}
else if (gcode->m == 3)
{
THECONVEYOR->wait_for_idle();
// M3: Spindle on
if(!spindle_on) {
turn_on();
}
// M3 with S value provided: set speed
if (gcode->has_letter('S'))
{
set_speed(gcode->get_value('S'));
}
}
else if (gcode->m == 5)
{
THECONVEYOR->wait_for_idle();
// M5: spindle off
if(spindle_on) {
turn_off();
}
}
}
}
示例5: on_gcode_execute
void TemperatureControl::on_gcode_execute(void* argument){
Gcode* gcode = static_cast<Gcode*>(argument);
if( gcode->has_m){
if (((gcode->m == this->set_m_code) || (gcode->m == this->set_and_wait_m_code))
&& gcode->has_letter('S'))
{
float v = gcode->get_value('S');
if (v == 0.0)
{
this->target_temperature = UNDEFINED;
this->heater_pin.set((this->o=0));
}
else
{
this->set_desired_temperature(v);
if( gcode->m == this->set_and_wait_m_code)
{
THEKERNEL->pauser->take();
this->waiting = true;
}
}
}
}
}
示例6: on_gcode_received
void ToolManager::on_gcode_received(void *argument)
{
Gcode *gcode = static_cast<Gcode*>(argument);
if( gcode->has_letter('T') ) {
int new_tool = gcode->get_value('T');
if(new_tool >= (int)this->tools.size() || new_tool < 0) {
// invalid tool
char buf[32]; // should be big enough for any status
int n = snprintf(buf, sizeof(buf), "T%d invalid tool ", new_tool);
gcode->txt_after_ok.append(buf, n);
} else {
if(new_tool != this->active_tool) {
// We must wait for an empty queue before we can disable the current extruder
THEKERNEL->conveyor->wait_for_empty_queue();
this->tools[active_tool]->disable();
this->active_tool = new_tool;
this->current_tool_name = this->tools[active_tool]->get_name();
this->tools[active_tool]->enable();
//send new_tool_offsets to robot
const float *new_tool_offset = tools[new_tool]->get_offset();
THEKERNEL->robot->setToolOffset(new_tool_offset);
}
}
}
}
示例7: on_gcode_execute
// Turn laser on/off depending on received GCodes
void Laser::on_gcode_execute(void* argument){
Gcode* gcode = static_cast<Gcode*>(argument);
this->laser_on = false;
if( gcode->has_g){
int code = gcode->g;
if( code == 0 ){ // G0
this->pwm_pin->write(this->pwm_inverting ? 1 - this->laser_minimum_power : this->laser_minimum_power);
this->laser_on = false;
}else if( code >= 1 && code <= 3 ){ // G1, G2, G3
this->laser_on = true;
}
}
if ( gcode->has_letter('S' )){
float requested_power = gcode->get_value('S') / this->laser_maximum_s_value;
// Ensure we can't exceed maximum power
if (requested_power > 1)
requested_power = 1;
this->laser_power = requested_power;
}
if (this->ttl_used)
this->ttl_pin->set(this->laser_on);
}
示例8: on_gcode_execute
// Turn pin on and off
void Switch::on_gcode_execute(void *argument)
{
Gcode *gcode = static_cast<Gcode *>(argument);
if(match_input_on_gcode(gcode)) {
int v;
this->switch_state = true;
if (this->output_type == PWM) {
// PWM output pin turn on
if(gcode->has_letter('S')) {
v = round(gcode->get_value('S') * output_pin.max_pwm() / 255.0); // scale by max_pwm so input of 255 and max_pwm of 128 would set value to 128
this->output_pin.pwm(v);
} else {
this->output_pin.pwm(this->switch_value);
}
} else {
// logic pin turn on
this->output_pin.set(true);
}
} else if(match_input_off_gcode(gcode)) {
this->switch_state = false;
if (this->output_type == PWM) {
// PWM output pin
this->output_pin.set(false);
} else {
// logic pin turn off
this->output_pin.set(false);
}
}
}
示例9: on_gcode_received
void CurrentControl::on_gcode_received(void *argument)
{
Gcode *gcode = static_cast<Gcode*>(argument);
char alpha[8] = { 'X', 'Y', 'Z', 'E', 'A', 'B', 'C', 'D' };
if (gcode->has_m)
{
if (gcode->m == 907)
{
int i;
for (i = 0; i < 8; i++)
{
if (gcode->has_letter(alpha[i])){
float c= gcode->get_value(alpha[i]);
this->digipot->set_current(i, c);
switch(i) {
case 0: this->alpha_current= c; break;
case 1: this->beta_current= c; break;
case 2: this->gamma_current= c; break;
case 3: this->delta_current= c; break;
case 4: this->epsilon_current= c; break;
case 5: this->zeta_current= c; break;
case 6: this->eta_current= c; break;
case 7: this->theta_current= c; break;
}
}
gcode->stream->printf("%c:%3.1fA%c", alpha[i], this->digipot->get_current(i), (i == 7)?'\n':' ');
}
}else if(gcode->m == 500 || gcode->m == 503) {
if(this->delta_current != this->original_delta_current) { // if not the same as loaded by config then save it
gcode->stream->printf(";Extruder current:\nM907 E%1.5f\n", this->delta_current);
}
}
}
}
示例10: on_gcode_execute
// Turn pin on and off
void Switch::on_gcode_execute(void* argument){
Gcode* gcode = static_cast<Gcode*>(argument);
if( gcode->has_m){
int code = gcode->m;
if( code == this->on_m_code ){
if (gcode->has_letter('S'))
{
int v = gcode->get_value('S') * output_pin.max_pwm() / 256.0;
if (v)
this->output_pin.pwm(v);
else
this->output_pin.set(0);
}
else
{
// Turn pin on
this->output_pin.set(1);
}
}
if( code == this->off_m_code ){
// Turn pin off
this->output_pin.set(0);
}
}
}
示例11: on_gcode_received
void TemperatureControl::on_gcode_received(void* argument){
Gcode* gcode = static_cast<Gcode*>(argument);
if (gcode->has_m) {
// Get temperature
if( gcode->m == this->get_m_code ){
char buf[32]; // should be big enough for any status
int n= snprintf(buf, sizeof(buf), "%s:%3.1f /%3.1f @%d ", this->designator.c_str(), this->get_temperature(), ((target_temperature == UNDEFINED)?0.0:target_temperature), this->o);
gcode->txt_after_ok.append(buf, n);
gcode->mark_as_taken();
} else if (gcode->m == 301) {
gcode->mark_as_taken();
if (gcode->has_letter('S') && (gcode->get_value('S') == this->pool_index))
{
if (gcode->has_letter('P'))
setPIDp( gcode->get_value('P') );
if (gcode->has_letter('I'))
setPIDi( gcode->get_value('I') );
if (gcode->has_letter('D'))
setPIDd( gcode->get_value('D') );
if (gcode->has_letter('X'))
this->i_max = gcode->get_value('X');
}
//gcode->stream->printf("%s(S%d): Pf:%g If:%g Df:%g X(I_max):%g Pv:%g Iv:%g Dv:%g O:%d\n", this->designator.c_str(), this->pool_index, this->p_factor, this->i_factor/this->PIDdt, this->d_factor*this->PIDdt, this->i_max, this->p, this->i, this->d, o);
gcode->stream->printf("%s(S%d): Pf:%g If:%g Df:%g X(I_max):%g O:%d\n", this->designator.c_str(), this->pool_index, this->p_factor, this->i_factor/this->PIDdt, this->d_factor*this->PIDdt, this->i_max, o);
} else if (gcode->m == 303) {
if (gcode->has_letter('E') && (gcode->get_value('E') == this->pool_index)) {
gcode->mark_as_taken();
float target = 150.0;
if (gcode->has_letter('S')) {
target = gcode->get_value('S');
gcode->stream->printf("Target: %5.1f\n", target);
}
int ncycles= 8;
if (gcode->has_letter('C')) {
ncycles= gcode->get_value('C');
}
gcode->stream->printf("Start PID tune, command is %s\n", gcode->command.c_str());
this->pool->PIDtuner->begin(this, target, gcode->stream, ncycles);
}
} else if (gcode->m == 500 || gcode->m == 503){// M500 saves some volatile settings to config override file, M503 just prints the settings
gcode->stream->printf(";PID settings:\nM301 S%d P%1.4f I%1.4f D%1.4f\n", this->pool_index, this->p_factor, this->i_factor/this->PIDdt, this->d_factor*this->PIDdt);
gcode->mark_as_taken();
} else if( ( gcode->m == this->set_m_code || gcode->m == this->set_and_wait_m_code ) && gcode->has_letter('S') ) {
// Attach gcodes to the last block for on_gcode_execute
THEKERNEL->conveyor->append_gcode(gcode);
// push an empty block if we have to wait, so the Planner can get things right, and we can prevent subsequent non-move gcodes from executing
if (gcode->m == this->set_and_wait_m_code)
// ensure that no subsequent gcodes get executed with our M109 or similar
THEKERNEL->conveyor->queue_head_block();
}
}
}
示例12: on_gcode_received
void TemperatureSwitch::on_gcode_received(void *argument)
{
Gcode *gcode = static_cast<Gcode *>(argument);
if(gcode->has_m && gcode->m == this->arm_mcode) {
this->armed= (gcode->has_letter('S') && gcode->get_value('S') != 0);
gcode->stream->printf("temperature switch %s\n", this->armed ? "armed" : "disarmed");
}
}
示例13: on_gcode_received
void Spindle::on_gcode_received(void* argument)
{
Gcode *gcode = static_cast<Gcode *>(argument);
if (gcode->has_m) {
if (gcode->m == 957) {
// M957: report spindle speed
THEKERNEL->streams->printf("Current RPM: %5.0f Target RPM: %5.0f PWM value: %5.3f\n",
current_rpm, target_rpm, current_pwm_value);
} else if (gcode->m == 958) {
// M958: set spindle PID parameters
if (gcode->has_letter('P'))
control_P_term = gcode->get_value('P');
if (gcode->has_letter('I'))
control_I_term = gcode->get_value('I');
if (gcode->has_letter('D'))
control_D_term = gcode->get_value('D');
THEKERNEL->streams->printf("P: %0.6f I: %0.6f D: %0.6f\n",
control_P_term, control_I_term, control_D_term);
} else if (gcode->m == 3) {
THEKERNEL->conveyor->wait_for_empty_queue();
// M3: Spindle on
spindle_on = true;
if (gcode->has_letter('S')) {
target_rpm = gcode->get_value('S');
}
} else if (gcode->m == 5) {
THEKERNEL->conveyor->wait_for_empty_queue();
spindle_on = false;
}
}else if(!gcode->has_m && !gcode->has_g && gcode->has_letter('S')) {
// special case S on its own
THEKERNEL->conveyor->wait_for_empty_queue();
target_rpm = gcode->get_value('S');
}
}
示例14: on_gcode_execute
// Turn laser on/off depending on received GCodes
void Laser::on_gcode_execute(void* argument){
Gcode* gcode = static_cast<Gcode*>(argument);
this->laser_on = false;
if( gcode->has_letter('G' )){
int code = gcode->get_value('G');
if( code == 0 ){ // G0
this->laser_pin = 0;
this->laser_on = false;
}else if( code >= 1 && code <= 3 ){ // G1, G2, G3
this->laser_on = true;
}
}
}
示例15: on_gcode_received
void Extruder::on_gcode_received(void *argument){
Gcode *gcode = static_cast<Gcode*>(argument);
// Gcodes to execute immediately
if (gcode->has_m){
if (gcode->m == 114){
gcode->stream->printf("E:%4.1f ", this->current_position);
gcode->add_nl = true;
gcode->mark_as_taken();
}
if (gcode->m == 92 ){
double spm = this->steps_per_millimeter;
if (gcode->has_letter('E'))
spm = gcode->get_value('E');
gcode->stream->printf("E:%g ", spm);
gcode->add_nl = true;
gcode->mark_as_taken();
}
}
// Gcodes to pass along to on_gcode_execute
if( ( gcode->has_m && (gcode->m == 17 || gcode->m == 18 || gcode->m == 82 || gcode->m == 83 || gcode->m == 84 || gcode->m == 92 ) ) || ( gcode->has_g && gcode->g == 92 && gcode->has_letter('E') ) || ( gcode->has_g && ( gcode->g == 90 || gcode->g == 91 ) ) ){
gcode->mark_as_taken();
if( this->kernel->conveyor->queue.size() == 0 ){
this->kernel->call_event(ON_GCODE_EXECUTE, gcode );
}else{
Block* block = this->kernel->conveyor->queue.get_ref( this->kernel->conveyor->queue.size() - 1 );
block->append_gcode(gcode);
}
}
// Add to the queue for on_gcode_execute to process
if( gcode->has_g && gcode->g < 4 && gcode->has_letter('E') ){
if( !gcode->has_letter('X') && !gcode->has_letter('Y') && !gcode->has_letter('Z') ){
// This is a solo move, we add an empty block to the queue
//If the queue is empty, execute immediatly, otherwise attach to the last added block
if( this->kernel->conveyor->queue.size() == 0 ){
this->kernel->call_event(ON_GCODE_EXECUTE, gcode );
this->append_empty_block();
}else{
Block* block = this->kernel->conveyor->queue.get_ref( this->kernel->conveyor->queue.size() - 1 );
block->append_gcode(gcode);
this->append_empty_block();
}
}
}else{
// This is for follow move
}
}