Need help clarifying coding!

Hey im new to this, and im wondering, can you just use other pre existing code? Like, if i found someone's line following robot code online and use it on my own line following robot with a different spec will ut work? please clarify

Or is there a basic line following code? And a guide on how to modify it based on the specs of your robot?

Yes... if it works. "Use" means "it works correctly."

Probably not. Devices used will probably be different. The difference could be close enough to need minimal work to make them work, or the difference could be slight enough to need loads of work.

If you get a complete, new robot kit (hardware, software, firmware) you have a high chance of making a working robot.

Oh ok so, your saying that every model needs a different code? If so, is there some kind of basic line following robot code thats available to the public?

Not every model needs different code. You will always need motors, motor drivers, and sensors. One robot "works" like another robot just like one automobile works like another automobile. But... how many parts in a BMW work in an MG? If you are good enough at cars, you can make BMW parts work in an MG. Same with robots.

Here is my simulation of an object avoiding robot. The code will only work in another robot with similar parts... or with enough practice, the code can be changed to fit another robot.

Oh wow! This is very helpful, thank you so much!

Your question is excellent.
The principles are all ‘similar’, but it’s like any customised project.

Weight, size, colour of the line, run time etc all have to be factored in.

Yes the fundamentals are the same, but every other element is a variable.

Size of motors, steering, sensors power source are all varoavbles.
Thats what makes this an interesting hobby, there’s no instruction manual for what you’re making.

You have to learn, understand, try and fail as you pick up new shills.
The last step is to succeed, and it feels great.. until you think you can do it better in version x+1 !

Wait so, based on the different parts, you'll need to adjust accordingly in the code?

Of course. Different parts have different requirements. If you have a motor driver that takes serial commands and change it for one that takes step and direction inputs then you'll have to change the code to produce those signals. There are thousands of parts in millions of configurations that you could use to build a robot. How you code it depends entirely on what it is built from. How could you expect the code for one part to work for a completely different part?

Yes. All devices will have input and output requirements. You will read a technical specification for all your devices (whitepaper, datasheet) to learn the requirements of each device. You will connect the devices and write code for the microprocessor to communicate with each device, accept any input needed from the device, process this input, and provide the output to other devices.

Just to confuse you some more…

For any given piece of code there are often THREE or more PERFECTLY right ways to do it…

The choice depends on skill, familiarity and urgency.
Some will be way shorter /or/ more efficient in memory - and/or faster to execute !

it is typically faster to modify someone else's code to meet your requirements than to write code from scratch, assuming that code is well written (maintainable: easy to read, debug and expand)

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