mBot Mega code not finding included files

// Let Mega walk like a crab


// generated by mBlock5 for MegaPi
// codes make you happy

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include "src/MeSingleLineFollower.h"
#include "src/MeCollisionSensor.h"
#include "src/MeBarrierSensor.h"
#include "src/MeNewRGBLed.h"
#include <MeMegaPi.h>

MeBarrierSensor barrier_61(61);
MeMegaPiDCMotor motor_1(1);
MeMegaPiDCMotor motor_9(9);
MeMegaPiDCMotor motor_2(2);
MeMegaPiDCMotor motor_10(10);
MeMegaPiDCMotor motor_3(3);
MeMegaPiDCMotor motor_11(11);
MeMegaPiDCMotor motor_4(4);
MeMegaPiDCMotor motor_12(12);
double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;

float T = 0;

void motor_foward_left_run(int16_t speed)
{
   motor_10.run(-speed);
}

void motor_foward_right_run(int16_t speed)
{
  motor_1.run(speed);
}

void motor_back_left_run(int16_t speed)
{
  motor_2.run(-speed);
}

void motor_back_right_run(int16_t speed)
{
  motor_9.run(speed);
}

void move_control(int16_t vx, int16_t vy, int16_t vw)
{
  int16_t foward_left_speed;
  int16_t foward_right_speed;
  int16_t back_left_speed;
  int16_t back_right_speed;

  foward_left_speed = vy + vx + vw;
  foward_right_speed = vy - vx - vw;
  back_left_speed = vy - vx + vw;
  back_right_speed = vy + vx - vw;

  motor_foward_left_run(foward_left_speed);
  motor_foward_right_run(foward_right_speed);
  motor_back_left_run(back_left_speed);
  motor_back_right_run(back_right_speed);
}

void _delay(float seconds) {
  if(seconds < 0.0){
    seconds = 0.0;
  }
  long endTime = millis() + seconds * 1000;
  while(millis() < endTime) _loop();
}

void setup() {
  TCCR1A = _BV(WGM10);
  TCCR1B = _BV(CS11) | _BV(WGM12);
  TCCR2A = _BV(WGM21) | _BV(WGM20);
  TCCR2B = _BV(CS21);
  T = 0.7;

}

void _loop() {
}

void loop() {
  if(barrier_61.isBarried()){

      move_control(50 / 100.0 * 255,0 / 100.0 * 255,0 / 100.0 * 255);
      _delay(0.7);

      motor_1.run(0);
      motor_9.run(0);
      motor_2.run(0);
      motor_10.run(0);
      motor_3.run(0);
      motor_11.run(0);
      motor_4.run(0);
      motor_12.run(0);
      _delay(float(T));

      move_control(-50 / 100.0 * 255,50 / 100.0 * 255,0 / 100.0 * 255);
      _delay(0.7);

      motor_1.run(0);
      motor_9.run(0);
      motor_2.run(0);
      motor_10.run(0);
      motor_3.run(0);
      motor_11.run(0);
      motor_4.run(0);
      motor_12.run(0);
      _delay(float(T));

      move_control(50 / 100.0 * 255,50 / 100.0 * 255,0 / 100.0 * 255);
      _delay(0.7);

      motor_1.run(0);
      motor_9.run(0);
      motor_2.run(0);
      motor_10.run(0);
      motor_3.run(0);
      motor_11.run(0);
      motor_4.run(0);
      motor_12.run(0);
      _delay(float(T));

      move_control(-50 / 100.0 * 255,50 / 100.0 * 255,0 / 100.0 * 255);
      _delay(0.7);

      motor_1.run(0);
      motor_9.run(0);
      motor_2.run(0);
      motor_10.run(0);
      motor_3.run(0);
      motor_11.run(0);
      motor_4.run(0);
      motor_12.run(0);
      _delay(float(T));

      move_control(50 / 100.0 * 255,50 / 100.0 * 255,0 / 100.0 * 255);
      _delay(0.7);

      motor_1.run(0);
      motor_9.run(0);
      motor_2.run(0);
      motor_10.run(0);
      motor_3.run(0);
      motor_11.run(0);
      motor_4.run(0);
      motor_12.run(0);
      _delay(float(T));

      move_control(-50 / 100.0 * 255,0 / 100.0 * 255,0 / 100.0 * 255);
      _delay(0.7);

      motor_1.run(0);
      motor_9.run(0);
      motor_2.run(0);
      motor_10.run(0);
      motor_3.run(0);
      motor_11.run(0);
      motor_4.run(0);
      motor_12.run(0);
      _delay(float(T));

      move_control(50 / 100.0 * 255,-50 / 100.0 * 255,0 / 100.0 * 255);
      _delay(0.7);

      motor_1.run(0);
      motor_9.run(0);
      motor_2.run(0);
      motor_10.run(0);
      motor_3.run(0);
      motor_11.run(0);
      motor_4.run(0);
      motor_12.run(0);
      _delay(float(T));

      move_control(-50 / 100.0 * 255,-50 / 100.0 * 255,0 / 100.0 * 255);
      _delay(0.7);

      motor_1.run(0);
      motor_9.run(0);
      motor_2.run(0);
      motor_10.run(0);
      motor_3.run(0);
      motor_11.run(0);
      motor_4.run(0);
      motor_12.run(0);
      _delay(float(T));

      move_control(50 / 100.0 * 255,-50 / 100.0 * 255,0 / 100.0 * 255);
      _delay(0.7);

      motor_1.run(0);
      motor_9.run(0);
      motor_2.run(0);
      motor_10.run(0);
      motor_3.run(0);
      motor_11.run(0);
      motor_4.run(0);
      motor_12.run(0);
      _delay(float(T));

      move_control(-50 / 100.0 * 255,-50 / 100.0 * 255,0 / 100.0 * 255);
      _delay(0.7);

      motor_1.run(0);
      motor_9.run(0);
      motor_2.run(0);
      motor_10.run(0);
      motor_3.run(0);
      motor_11.run(0);
      motor_4.run(0);
      motor_12.run(0);

  }

  _loop();
}

Here is the error message:

C:\Users\thoma\AppData\Local\Temp\849b73b6-2b0f-44c5-8777-b75f1b4ecfac_The_crab_walk.rar.fac\The_crab_walk\The_crab_walk.ino:10:10: fatal error: src/MeSingleLineFollower.h: No such file or directory
#include "src/MeSingleLineFollower.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: src/MeSingleLineFollower.h: No such file or directory

#include "src/MeSingleLineFollower.h"
#include "src/MeCollisionSensor.h"
#include "src/MeBarrierSensor.h"
#include "src/MeNewRGBLed.h"

Where exactly are these libraries located in relation to the sketch file ?

The libraries are relative to the folder that the sketch file is in.

You can't use a source code directories inside the sketch folder.
You have either copy these files to the sketch folder itself or put it in standard Arduino library.

1 Like

As a matter of fact you can

For complete clarity, what is the full path to the sketch .ino file and the full path to MeSingleLineFollower.h ?

Full path is: Arduino > libraries > Crab Walk > The_crab_walk

Full path of what ?

full path to the MeSingleLineFollower.h

The full path for the sketch.ino file is the same path, because for both once you're in The_crab_walk you can then access the files

Please be more accurate when presenting a path. Does your path contains a ">" characters?

If suppose that the path is something like
Arduino/libraries/Crab Walk/The_crab_walk

I see a several problems in it

  • the library name can't contain a spaces
  • the library code must be either in the first level folder or in src folder. The folder name The_crab_walk is invalid name for this.

So why did you included it in the code as

where the src/ in your path?

I moved it to Arduino/libraries/src/MeSingleLineFollower.h(plus the rest)

It is incorrect path too.
The file should be in the folder, for example:
Arduino/libraries/CrabWalk/MeSingleLineFollower.h

and the includes in the code shouldn't have a "src" part at the beginning

Also the sketch itself must be moved to sketch folder from the library.

(edited - remove the src part from the path)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.