<commit_before>#include <Chassis.h>
#include <RfidDetector.h>
#include <GrippController.h>
#include <MachineAPI.h>

#include <Arduino.h>
#include <Component.h>
#include <SPI.h>
#include <Wire.h>
#include <Debug.h>

#include <Adafruit_MotorShield.h>

#ifndef MachineLogic_h
#define MachineLogic_h

class MachineLogic : public Component<Config>
{
public:
  MachineLogic(Component<GrippPosition> *grippController,
               Component<int> *rfidDetector,
               Component<int> *chassis,
               Component<Config> *machineAPI) : grippController{grippController},
                                                chassis{chassis},
                                                rfidDetector{rfidDetector},
                                                machineAPI{machineAPI}
  {
    this->componentData = machineAPI->getData();
  }

protected:
  Config loop()
  {
    if (chassIsAtStartPosition() && grippControllerIsAtStartPosition())
    {
      if (chipDetected())
      {
        debugLn("1");
        grippController->setAction(componentData.rfidSourcePosition);
        grippController->on();
      }
      else
      {
        debugLn("2");
        chassis->wait();
        grippController->wait();
        rfidDetector->on();
      }
    }

    if (grippControllerHasChip())
    {
      debugLn("3");
      chassis->setAction(componentData.rfids[rfidDetector->getData()].destination);
      chassis->on();
    }

    if (!allOff() && chassisReachedDestination() && !grippControllerDeposeChip())
    {
      debugLn("4");
      grippController->setAction(componentData.rfids[rfidDetector->getData()].GrippPosition);
      grippController->on();
    }

    if ((allFinished() || allOff()) && !grippControllerIsAtStartPosition() && !chassIsAtStartPosition() && !chassisReachedDestination())
    {
      debugLn("5");
      grippController->setAction(componentData.grippSleepPosition);
      grippController->on();
    }

    if (grippControllerIsAtStartPosition() && !chassIsAtStartPosition())
    {
      debugLn("6");
      chassis->setAction(componentData.chassisStart);
      chassis->on();
    }

    if (chassisReachedDestination() && grippControllerDeposeChip())
    {
      debugLn("7");
      grippController->wait();
      chassis->wait();
      rfidDetector->wait();
    }

    printStatus();
    chassis->executeOneStep();
    grippController->executeOneStep();
    rfidDetector->executeOneStep();

    return componentData;
  }

private:
  Component<GrippPosition> *grippController;
  Component<int> *chassis;
  Component<int> *rfidDetector;
  Component<Config> *machineAPI;
<commit_msg>change order & add some debuginfos.<commit_after>#include <Chassis.h>
#include <RfidDetector.h>
#include <GrippController.h>
#include <MachineAPI.h>

#include <Arduino.h>
#include <Component.h>
#include <SPI.h>
#include <Wire.h>
#include <Debug.h>

#include <Adafruit_MotorShield.h>

#ifndef MachineLogic_h
#define MachineLogic_h

class MachineLogic : public Component<Config>
{
public:
  MachineLogic(Component<GrippPosition> *grippController,
               Component<int> *rfidDetector,
               Component<int> *chassis,
               Component<Config> *machineAPI) : grippController{grippController},
                                                chassis{chassis},
                                                rfidDetector{rfidDetector},
                                                machineAPI{machineAPI}
  {
    this->componentData = machineAPI->getData();
  }

protected:
  Config loop()
  {
    if ((allFinished() || allOff()) && !grippControllerIsAtStartPosition() && !chassIsAtStartPosition() && !chassisReachedDestination())
    {
      debugLn("State 1: Put Gripp in its sleepposition.");
      grippController->setAction(componentData.grippSleepPosition);
      grippController->on();
    }

    if (grippControllerIsAtStartPosition() && !chassIsAtStartPosition())
    {
      debugLn("State 2: Put Chassis in its startposition.");
      chassis->setAction(componentData.chassisStart);
      chassis->on();
    }

    if (chassIsAtStartPosition() && grippControllerIsAtStartPosition() && !chipDetected())
    {
      debugLn("State 3: Check for new sortjobs.");
      chassis->wait();
      grippController->wait();
      rfidDetector->on();
    }

    if (chassIsAtStartPosition() && grippControllerIsAtStartPosition() && chipDetected())
    {
      debugLn("State 4: Get the new sortjob.");
      grippController->setAction(componentData.rfidSourcePosition);
      grippController->on();
    }

    if (grippControllerHasChip())
    {
      debugLn("State 5: Put chassis at the sortjob position.");
      chassis->setAction(componentData.rfids[rfidDetector->getData()].destination);
      chassis->on();
    }

    if (!allOff() && chassisReachedDestination() && !grippControllerDeposeChip())
    {
      debugLn("State 6: Put gripp at the sortjob position.");
      grippController->setAction(componentData.rfids[rfidDetector->getData()].GrippPosition);
      grippController->on();
    }

    if (chassisReachedDestination() && grippControllerDeposeChip())
    {
      debugLn("State 7: Go to State 1.");
      grippController->wait();
      chassis->wait();
      rfidDetector->wait();
    }

    printStatus();
    chassis->executeOneStep();
    grippController->executeOneStep();
    rfidDetector->executeOneStep();

    return componentData;
  }

private:
  Component<GrippPosition> *grippController;
  Component<int> *chassis;
  Component<int> *rfidDetector;
  Component<Config> *machineAPI;

{'fraction_non_alphanumeric': 0.1317117117117117, 'fraction_numerical': 0.002702702702702703, 'mean_word_length': 2.97921146953405, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1781507', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1644, 'n_words': 263}