<commit_before>/*
 * gcode-machine.c
 *
 *  Created on: Aug 11, 2012
 *      Author: csdexter
 */

#include <math.h>
#include <stdbool.h>
#include <stdio.h>

#include "gcode-commons.h"
#include "gcode-machine.h"
#include "gcode-debugcon.h"
#include "gcode-parameters.h"


static double machineX, machineY, machineZ;
static uint32_t spindleSpeed;
static TGCodeMachineState currentMachineState;
static bool stillRunning, servoPower;

bool init_machine(void *data) {
  machineX = machineY = machineZ = 0.0;
  currentMachineState.flags = 0x00;
  set_spindle_speed_machine(GCODE_MACHINE_LOWEST_RPM);
  enable_override_machine(GCODE_OVERRIDE_ON);
  stillRunning = true;
  enable_power_machine(GCODE_SERVO_ON);
  /* By default our home and zero positions are at (0, 0, 0) */
  set_parameter(GCODE_PARM_FIRST_HOME + 0, machineX);
  set_parameter(GCODE_PARM_FIRST_HOME + 1, machineY);
  set_parameter(GCODE_PARM_FIRST_HOME + 2, machineZ);
  set_parameter(GCODE_PARM_FIRST_ZERO + 0, machineX);
  set_parameter(GCODE_PARM_FIRST_ZERO + 1, machineY);
  set_parameter(GCODE_PARM_FIRST_ZERO + 2, machineZ);

  GCODE_DEBUG("Machine is up");

  return true;
}

bool move_machine_line(double X, double Y, double Z, TGCodeFeedMode feedMode, uint16_t F) {
  if(!servoPower || (X == machineX && Y == machineY && Z == machineZ)) return false;

  machineX = X;
  machineY = Y;
  machineZ = Z;
  if(F == GCODE_MACHINE_FEED_TRAVERSE)
    GCODE_DEBUG("Traverse move to V(%4.2fmm, %4.2fmm, %4.2fmm)", X, Y, Z)
  else
    GCODE_DEBUG("Linear move to V(%4.2fmm, %4.2fmm, %4.2fmm) at %4dmm/min", X, Y, Z, F);
  GCODE_MACHINE_POSITION(X, Y, Z);

  return true;
}

bool move_machine_arc(double X, double Y, double Z, double I, double J, double K, double R, bool ccw, TGCodePlaneMode plane, TGCodeFeedMode feedMode, uint16_t F) {<commit_msg>UPDATE: - added machine (whole axis) mirroring<commit_after>/*
 * gcode-machine.c
 *
 *  Created on: Aug 11, 2012
 *      Author: csdexter
 */

#include <math.h>
#include <stdbool.h>
#include <stdio.h>

#include "gcode-commons.h"
#include "gcode-machine.h"
#include "gcode-debugcon.h"
#include "gcode-parameters.h"


static double machineX, machineY, machineZ;
static uint32_t spindleSpeed;
static TGCodeMachineState currentMachineState;
static bool stillRunning, servoPower;

bool init_machine(void *data) {
  machineX = machineY = machineZ = 0.0;
  currentMachineState.flags = 0x00;
  set_spindle_speed_machine(GCODE_MACHINE_LOWEST_RPM);
  enable_override_machine(GCODE_OVERRIDE_ON);
  stillRunning = true;
  enable_power_machine(GCODE_SERVO_ON);
  /* By default our home and zero positions are at (0, 0, 0) */
  set_parameter(GCODE_PARM_FIRST_HOME + 0, machineX);
  set_parameter(GCODE_PARM_FIRST_HOME + 1, machineY);
  set_parameter(GCODE_PARM_FIRST_HOME + 2, machineZ);
  set_parameter(GCODE_PARM_FIRST_ZERO + 0, machineX);
  set_parameter(GCODE_PARM_FIRST_ZERO + 1, machineY);
  set_parameter(GCODE_PARM_FIRST_ZERO + 2, machineZ);

  GCODE_DEBUG("Machine is up");

  return true;
}

bool move_machine_line(double X, double Y, double Z, TGCodeFeedMode feedMode, uint16_t F) {
  if(!servoPower || (X == machineX && Y == machineY && Z == machineZ)) return false;

  //Apply machine mirroring
  machineX += (X - machineX) * (currentMachineState.mirrorX ? -1 : 1);
  machineY += (Y - machineY) * (currentMachineState.mirrorY ? -1 : 1);
  machineZ = Z;

  if(F == GCODE_MACHINE_FEED_TRAVERSE)
    GCODE_DEBUG("Traverse move to V(%4.2fmm, %4.2fmm, %4.2fmm)", X, Y, Z)
  else
    GCODE_DEBUG("Linear move to V(%4.2fmm, %4.2fmm, %4.2fmm) at %4dmm/min", X, Y, Z, F);
  GCODE_MACHINE_POSITION(X, Y, Z);

  return true;
}

bool move_machine_arc(double X, double Y, double Z, double I, double J, double K, double R, bool ccw, TGCodePlaneMode plane, TGCodeFeedMode feedMode, uint16_t F) {
{'fraction_non_alphanumeric': 0.12143611404435058, 'fraction_numerical': 0.02164730728616684, 'mean_word_length': 4.9575471698113205, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3573177', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1445, 'n_words': 346}