Total noob, want to make sure my project is doable before I buy components

I have never worked with arduino before but I have some very limited experience with programming (Java). I am starting a project in school where we will have a robot that follows a drawn path (this step will be completed by another member of my group). What I would like to do is have the robot remember this path and recreate it later. The robot will use 2 stepper motors- one for right drive wheel , one for left. Here is the general procedure I am thinking will be used:

while robot is following path:

-read position of motor shaft every x milliseconds (using rotary encoder?) -store these values (in an array?)

time to redraw path:

-convert encoder output to stepper "steps" -send to motor -wait x ms -send next step

So, will this accurately replicate the original path? Will this be too hard for someone with very little programming knowledge to tackle? Will the array be too big to store in onboard memory?

Will I need a separate arduino to control each motor? (we have like 4+ between group members so this won't be a problem if so) Any other general insight is welcome

Have you looked around on the internet at similar projects yet? That's a good starting point. Don't be afraid of reading. The words won't bite, I promise.

fatJim710: So, will this accurately replicate the original path?

Maybe. If you read the encoders accurately and code it right it should at least get close. This is your experiment to find out.

fatJim710: Will this be too hard for someone with very little programming knowledge to tackle?

Depends on how smart you are and how much thought you're willing to put in. For most beginners yeah this is a little steep. You should maybe start out just getting some lights to flash or something and learn how the language works first. What you've described will be impossible if you don't have a decent grasp on how C++ works.

fatJim710: Will the array be too big to store in onboard memory?

How big will the array be? How many steps are you storing? How much memory do you need to store one step? Don't start this project until you know enough about C++ to answer that question. It will be key.

fatJim710: Will I need a separate arduino to control each motor? (we have like 4+ between group members so this won't be a problem if so) Any other general insight is welcome

A separate arduino for each motor? You shouldn't. Again, why don't you go look at some similar projects on the web. This one has only been done about a bazillion times.

Another way to look at this given the robot will take orders at different points in time to follow the line. So if you can agree with your team mate how to code those orders by calling your functions first which in turn call the control of the motors then you don’t need to read the motors or whatever - you just remember the sequence of commands and associated timing

Delta_G: You should maybe start out just getting some lights to flash or something and learn how the language works first. What you've described will be impossible if you don't have a decent grasp on how C++ works.

This morning I followed an example to control the motor by turning a potentiometer. I will try to now store the potentiometer output, wait a few seconds, then have the motor move. Is an array the best way to store these values though?

I have started looking through similar projects but haven't found anything super applicable so far. I will continue looking but if you know of a specific one please link me to it. Thanks!

J-M-L: Another way to look at this given the robot will take orders at different points in time to follow the line. So if you can agree with your team mate how to code those orders by calling your functions first which in turn call the control of the motors then you don’t need to read the motors or whatever - you just remember the sequence of commands and associated timing

I believe the path will be followed using some sort of line sensor. I don't know what the output of the sensor looks like but I suppose that will be the first step. I will hold off on buying rotary encoders until we get the line following part to work. How would I store/remember the commands sent to the motors to use later?

There is a big difference between following a line and repeating that route blindly based on recorded movements.

Try making a route in a room using some chairs as corner points. Walk the route and count the number of steps between corners. Make it easy by positioning the chairs so there are no half-steps and all the turns are right angles.

Now go back to the start. Point yourself in the right direction, close your eyes (and keep them closed) and repeat the journey just by counting steps. Make it easy and have a colleague call out the number of steps and whether to turn left or right. But the colleague is not allowed to give you advice to correct any errors.

I suspect you won't even get to the second corner accurately. And I suspect it will be the exact same problem for your robot.

...R

Ask your mate how she/he is going to tell the robot to turn 30° or 90° Or stop the robot or set a speed for example (you need to do this for ALL possible commands)

Assuming it’s functions like:

turn(int angle)
stop()
setSpeed(int speed)

Then write your own functions called

registerAndTurn(int angle)
registerAndStop()
registerAndSetSpeed(int speed)

and tell your mate to never call his own functions directly but to call your functions instead.

In your code you would add something like

enum order_t : byte {TURN, STOP, SPEED}; // and all the possible other commands 

struct command_t {
   order_t type;
   int param;
   unsigned long chrono;
}; // what to memorize for a command

const byte maxCommands = 100;
command_t sequence[maxCommands];

byte commandIndex = 0; // how many orders have been recorded

void turn(int angle)
{
    // do the right thing
}

void stop()
{
   // do the right thing
}

void setSpeed(int speed)
{
   // do the right thing
}


void registerAndTurn(int angle)
{
    unsigned long t0 = millis(); // capture moment
    turn(angle); // issue the real command should be non blocking

    // here store t0, angle  and type of command in memory 
    if (commandIndex < maxCommands) {
       sequence[commandIndex].type = TURN;
       sequence[commandIndex].chrono = t0;
       sequence[commandIndex].param = angle; 
      commandIndex++;  // remember you captured one more command
   } else {
      // no more space available handle it
   }
}

void registerAndSetSpeed(int speed)
{
    unsigned long t0 = millis(); // capture moment
    setSpeed(speed); // issue the real command, should be non blocking

    // here store t0, speed  and type of command in memory
    if (commandIndex < maxCommands) {
       sequence[commandIndex].type = SPEED;
       sequence[commandIndex].chrono = t0;
       sequence[commandIndex].param = speed;       
      commandIndex++;  // remember you captured one more command
   } else {
      // no more space available, you are toast
   }
}

void registerAndStop()
{
    unsigned long t0 = millis(); // capture moment
    stop(); // issue the real command, should be non blocking

    // here store t0 and type of command in memory
    if (commandIndex < maxCommands) {
       sequence[commandIndex].type = STOP;
       sequence[commandIndex].chrono = t0;
       sequence[commandIndex].param = 0;       // not used for this type of command
      commandIndex++;  // remember you captured one more command
   } else {
      // no more space available, too bad...
   }
}

Typed on my phone so possibly some errors :slight_smile: but you get the idea right?

(if enum or struct or arrays are not familiar, then read a C/C++ manual about those)

That would record the commands for playback. now motors being not perfect, the track slippery, the initial position not exactly the same, the chances that repeating those steps in real world and getting to the same end place are pretty slim…
(that’s why you have a line to follow in the first place)

J-M-L: Typed on my phone so possibly some errors :) but you get the idea right?

(if enum or struct or arrays are not familiar, then read a C/C++ manual about those)

That would record the commands for playback. now motors being not perfect, the track slippery, the initial position not exactly the same, the chances that repeating those steps in real world and getting to the same end place are pretty slim... (that’s why you have a line to follow in the first place)

Yeah, this makes sense, thanks a lot. This seems like it's gonna be a bit more complicated than I originally thought so I won't consider doing it unless we get all the simpler functions working correctly well before the deadline. I wasn't anticipating this method would perfectly replicate the original path but it would be cool to get close. This is by no means required for my project so I'll call it a stretch goal or something in the proposal :P