How to measure walking distance on Arduino Me-BaseBoard V1.0 without any sensors

guys please help

can't answer, too little information

(post at least the assignment in all details)

Hi,

I have a makeblock v2.0 tank that comes with Arduino Me-BaseBoard V1.0
and I wonder if could measure the distance it walks, only by counting the energy that I spend on the wheels

thanks
Seroga

Yes,
but do not expect it to be trivial as the amount of energy is probably not linear with the distance.
(that is why cars have gears)

So you must make a table to see the relation between energy/second and distance/second.

Then you can do a numeric integration of the energy on the wheels.

BTW this assumes the structure of the ground to be constant.
Loose Sand gives other traction than clay or pebbles.

You see the more information you give the better answer you get :wink:

o.k

But I expected you tell me how to actualize the code

For example I'm using Makeblock IR_Controle library, that looks like this:

#include <Makeblock.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>

MeDCMotor MotorL(M1);
MeDCMotor MotorR(M2);
MeInfraredReceiver infraredReceiverDecode(PORT_6);
int moveSpeed = 190;
boolean leftflag,rightflag;
int minSpeed = 55;
int factor = 23;

void setup()
{
infraredReceiverDecode.begin();

}

void loop()
{
if(infraredReceiverDecode.available()||infraredReceiverDecode.buttonState())
{
switch(infraredReceiverDecode.read())
{
case IR_BUTTON_PLUS:
Forward();
break;
case IR_BUTTON_MINUS:
Backward();
break;
case IR_BUTTON_NEXT:
TurnRight();
break;
case IR_BUTTON_PREVIOUS:
TurnLeft();
break;
case IR_BUTTON_9:
ChangeSpeed(factor9+minSpeed);
break;
case IR_BUTTON_8:
ChangeSpeed(factor
8+minSpeed);
break;
case IR_BUTTON_7:
ChangeSpeed(factor7+minSpeed);
break;
case IR_BUTTON_6:
ChangeSpeed(factor
6+minSpeed);
break;
case IR_BUTTON_5:
ChangeSpeed(factor5+minSpeed);
break;
case IR_BUTTON_4:
ChangeSpeed(factor
4+minSpeed);
break;
case IR_BUTTON_3:
ChangeSpeed(factor3+minSpeed);
break;
case IR_BUTTON_2:
ChangeSpeed(factor
2+minSpeed);
break;
case IR_BUTTON_1:
ChangeSpeed(factor*1+minSpeed);
break;
}
}
else
{
Stop();
}
}

void Forward()
{
MotorL.run(moveSpeed);
MotorR.run(moveSpeed);
}
void Backward()
{
MotorL.run(-moveSpeed);
MotorR.run(-moveSpeed);
}
void TurnLeft()
{
MotorL.run(-moveSpeed);
MotorR.run(moveSpeed);
}
void TurnRight()
{
MotorL.run(moveSpeed);
MotorR.run(-moveSpeed);
}
void Stop()
{
MotorL.run(0);
MotorR.run(0);
}
void ChangeSpeed(int spd)
{
moveSpeed = spd;
}

What I need to change or add to measure the distance?

thanks

But I expected you tell me how to actualize the code

wrong expectation, sorry - I have no such makeblock thing so it is difficult for me.

As I tried to explain the thing you want to do is pretty complicated,
but I can show you some changes to get you going.

most important is that we have two variables for distance a raw one and a real. The raw distance measures the movespeed * time. This are not meters or centimetres yet.

Changes in speed are only actual when you turn go forward or reverse, therefore one need to track the actual speed of the motors.

so I would make the following changes.

float rawDistance = 0;
float realDistance = 0;
int  previousSpeed = 0;

void Forward()
{
  // update the distance drived
  stopTime = millis();
  rawDistance += previousSpeed * (stopTime - startTime);
  previousSpeed = moveSpeed;
  startTime = millis();

  // go with possible new speed
  MotorL.run(moveSpeed);
  MotorR.run(moveSpeed);
}

void Backward()
{
  stopTime = millis();
  rawDistance += previousSpeed * (stopTime - startTime);
  previousSpeed = moveSpeed;
  startTime = millis();

  MotorL.run(-moveSpeed);
  MotorR.run(-moveSpeed);

}

void TurnLeft()
{
  stopTime = millis();
  rawDistance += moveSpeed * (stopTime - startTime);
  previousSpeed = moveSpeed;
  startTime = millis();

  MotorL.run(-moveSpeed);
  MotorR.run(moveSpeed);

}

void TurnRight()
{
  stopTime = millis();
  rawDistance += previousSpeed * (stopTime - startTime);
  previousSpeed = moveSpeed;
  startTime = millis();

  MotorL.run(moveSpeed);
  MotorR.run(-moveSpeed);
}

void Stop()
{
  stopTime = millis();
  rawDistance += previousSpeed * (stopTime - startTime);
  previousSpeed = 0;
  startTime = millis();

  MotorL.run(0);
  MotorR.run(0);

}

and somewhere you do a Serial.println(rawDistance);

realDistance = rawDistance * someFactorWhichYouNeedToDetermineByActualMeasurements.

that should give you a start.
But again the assumption is that the movespeed is linear with the distance for all levels of movespeed.

OK lets refactor the common code out into a function

float rawDistance = 0;
float realDistance = 0;
int  previousSpeed = 0;
uint32_t startTime = 0, stopTime = 0;


void updateDistance()
{
  // update the distances
  stopTime = millis();
  rawDistance += previousSpeed * (stopTime - startTime);
  realDistance = rawDistance * factor.....;
  startTime = stopTime;
}


void Forward()
{
  updateDistance();
  previousSpeed = moveSpeed;

  MotorL.run(moveSpeed);
  MotorR.run(moveSpeed);
}

void Backward()
{
  updateDistance();
  previousSpeed = moveSpeed;

  MotorL.run(-moveSpeed);
  MotorR.run(-moveSpeed);

}

void TurnLeft()
{
  updateDistance();
  previousSpeed = moveSpeed;

  MotorL.run(-moveSpeed);
  MotorR.run(moveSpeed);

}

void TurnRight()
{
  updateDistance();
  previousSpeed = moveSpeed;

  MotorL.run(moveSpeed);
  MotorR.run(-moveSpeed);
}

void Stop()
{
  updateDistance();
  moveSpeed = 0;
  previousSpeed = moveSpeed;

  MotorL.run(0);
  MotorR.run(0);

}

give it a try, but as said I cannot test it.

millis() that's the function that I searched for!
I am pretty sure that it will work

thank you Rob
that was really helpful
you are a genius

there is also micros(),

and please let us know if it works.

Now I want to measure the angle of the turn
and I realise that it depends on angular velocity but how to actualise it in code?