Thread: Programming Robots and things with C!

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    6

    Programming Robots and things with C!

    Since I'm starting to learn C with a goal of working with robots or operating systems. I was wondering if the people here would be able to give me or direct me to a comprehensive list of things that would be necessary/beneficial to learn before attempting AI/robots or basic operating systems, preferably for AI/robots, that would be amazing!

    Thanks in advance,
    Darwin

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    How long have you been programming?

    No, I'm not being a smart arse... the first thing you need to learn is C...

    Take any good C textbook or tutorial... go through it page by page, do all the exercises --as often as you need to understand how they work-- then write a few programs on your own before you even think about advanced programming like Operating Systems, AI or Mechatronics... Believe me learning a few if--else--do--while tricks is no where near the skill level you will require for "deep guts" programming.

    I've seen source code for an OS project... it's in C but it ain't like no programming I've ever seen before.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    6
    I understand where your coming from. I've been programming with C# for 2 years now (my grade 11 and 12 years of high-school; the latter of which I am just finishing up) but have found it too easy. So I understand the basic structure, if/else, do/whiles and things like that and I do have a copy of the K&R book for C. I've even been dabling with it for a little while now. I Went through the C for Dummies book and was able to understand almost everything that was going on. And I'm now working on building a simple command prompt program for some MTG mathematics.

    So hopefully that gives you an idea of how long I've been programming/ how much I know.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Well, we all learn at different rates, but as more than one person here has commented C is an overnight language that will still surprise you 10 years later. What I'm suggesting is that you temper the exhuberance of youth with the deliberacy of a planned course of action. You can do both... but please don't make the mistake of thinking that because you wrote "the parking lot program" you're now ready for deep guts programming... they are two different worlds.

    That said... go ahead and make your attempts... if they do nothing else they will show you what you still need to learn...

    FWIW... I had my own comeuppance when I started Windows GUI programming. Now THAT is truly a horse of a different color!

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    6
    Awesome! Thanks Common. I think I'll just keep playing around with C until I feel I'm proficient enough to start delving into the deeper guts of it all. I am taking University courses on computer science/mathematics next year focusing on Robotics/AI (I REALLY want to go to robo-cup) so I will learn all this stuff then. But I just have this passion and sweet love for computer science so I kinda wanna start learning it now.

    Once again. Thanks for your help.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Then you should start now... There's no rule against reading ahead. The more you know going in the easier the course will be.

    When I was in school, I would take the next semester textbooks home from the library and read them over summer/winter holidays so that each course was actually a refresher and a chance to ask questions about stuff that wasn't clear... Worked a charm too...

    As I said... pour over K&R do the exercises, even if they seem a bit trite, they're a good review. Even the best readers don't remember stuff nearly as well as when they actually do it...

  7. #7
    Registered User
    Join Date
    May 2011
    Posts
    6
    Good to see that someone else has the same motivation I do! I'll see what happens after I'm done the book and who knows. Maybe it will tell me what to do when I'm done reading it!

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    If robotics interest you, you may want to start looking for some low cost robotic kits. If you are interested in programming look for kits that require programming. Also there are quite a few low cost micro-controller evaluation boards available.

    Also remember that a robot contains many mechanical and electronic parts so a knowledge of electronics and mechanics is usually also beneficial.

    Jim

  9. #9
    Registered User
    Join Date
    May 2011
    Posts
    6
    Awesome, thanks jim! My dad (who has no programming experience unfortunately. He just supports me A LOT) and I looked at someone's guide on youtube on how to program a robot and his was really cheap and moved according to "sunlight bounding boxes" i believe.

    One other question I just came upon. Ever since I was taught programming I have been told to comment everything. But upon recently I read some advice in another programming book that told me to comment things that I was uncertain about, things that might be confusing to another person or things I want to do next time I open my code. I also read in a different book that the only comment lines someone puts in is the overview of the script at the top of the file. My question is, do I really need more comment lines than that.

    Just figure I'd through in that question real quick.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Comments come in three types:

    1) A what the program as a whole does, it's input and output, author's name, license/copyright etc. overview.

    2) An overview of what each function does, right before the function.

    3) For the code itself, if the code or logic is not easy to understand what it's doing, or why.

    Never comment all your code - that's a waste of time, and just clutter. Also, be concise with your comments. It's not an essay.

  11. #11
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Coming from industry experience, the most important thing to comment in code is 'why' the code does what it does. The 'what' where and when etc are all able to be figured out later, but the 'why' is often the thing that takes the longest to figure out afterwards.

    Good names and well laid out code should for the most part make code self-explanatory to the average programmer, but if you only remember one thing about commenting, remember that the 'why' is the most important part.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  12. #12
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    If you are interested in robotics, this site has some really good resources that covers basic programming, electronics, and mech - How to Build a Robot Tutorial - Society of Robots

    That's where I started a few years ago.

    For an intro to embedded (tiny computer) programming, I recommend taking a look at the Arduino project.

    Coincidentally, I am involved in my school's Robocup team. Not in software, though. I'm doing the electronics.

    It's a good idea to learn to program on the PC first, but since you said you have a few years of programming experience, I wouldn't worry about that too much.

    At our school, for electrical engineering, programming is actually taught the other way around - assembly first, embedded C, then C++ on PC. As a result, many people are more familiar with assembly and think it's easier than C, which is pretty cool.
    Last edited by cyberfish; 05-27-2011 at 01:00 AM.

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Darwin Froese View Post
    Awesome, thanks jim! My dad (who has no programming experience unfortunately. He just supports me A LOT) and I looked at someone's guide on youtube on how to program a robot and his was really cheap and moved according to "sunlight bounding boxes" i believe.

    One other question I just came upon. Ever since I was taught programming I have been told to comment everything. But upon recently I read some advice in another programming book that told me to comment things that I was uncertain about, things that might be confusing to another person or things I want to do next time I open my code. I also read in a different book that the only comment lines someone puts in is the overview of the script at the top of the file. My question is, do I really need more comment lines than that.

    Just figure I'd through in that question real quick.
    Think about it this way... You've written a fairly complex bit of code, but it's been 5 years since you looked at it... Are you still going to be able to follow it and remember what you did? ... Comment anything that is not painfully obvious!

    Like this...
    Code:
    // replace a command line flag, remove if NewFlag = NULL
    VOID DoReplace(PTCHAR Str, PTCHAR OldFlag, PTCHAR NewFlag)
      { PTCHAR ft,fs;  // pointers for string manip
        // locate the old flag
        ft = wcsstr(Str,OldFlag);
        if (!ft)
          return;
        fs = ft;
        // find end of flag
        while((*fs != _T(' ')) && (*fs != 0))
          fs++;  
        // finds start of next flag
        while((*fs != _T('-')) && (*fs != 0))
          fs++;  
        // copy line forward
        while(*ft++ = *fs++);      
        // clean trailing spaces
        ft = Str + lstrlen(Str) - 1;
        while(*ft == _T(' '))
          *ft-- = 0;
        // add new flag
        if (lstrlen(NewFlag))
          { lstrcat(Str,_T(" "));
            lstrcat(Str,NewFlag); } }

  14. #14
    Registered User
    Join Date
    May 2011
    Posts
    6
    Wow! Thanks everyone, the information here is just amazing!

    At our school, for electrical engineering, programming is actually taught the other way around - assembly first, embedded C, then C++ on PC. As a result, many people are more familiar with assembly and think it's easier than C, which is pretty cool.
    Unfortunately my highschool taught us C# and the university I'm going to teaches Java and then C++ and then C I believe. I know java is for certain but I don't know about the order of the other two. But that is the computer science program not electrical engineering.

    I bookmarked the link that cyberfish posted, thanks for posting that.


    And on the topic of comment lines. Y'all should see the mess some of my classmates projects get with all their comment lines. Even the teachers is hard to read sometimes there is so many!

  15. #15
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Working with robots will be less about the language and more about knowing some geometry and physics. Doing inverse matrices (computing optimum movement of several servos), matrix multiplication (image rotation, 3-D gyroscope calibration), curve fitting (temperature/pressure sensors), mathematical low-pass filtering (speed sensors or any other jitter issues). Remember you are interfacing digital with analog, programmatically. When you are comfortable with these concepts then the "C" implementation is just simple math and loops.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Different way of doing things
    By AaA in forum C Programming
    Replies: 12
    Last Post: 07-29-2005, 06:47 PM
  2. i need help with a few things
    By kwm32 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 03-25-2004, 05:36 PM
  3. robots
    By yavanna in forum Tech Board
    Replies: 16
    Last Post: 10-30-2003, 01:30 PM
  4. Robots
    By loque in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 11-18-2001, 01:58 PM
  5. What is your favorite things about programming?
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 10-21-2001, 12:13 PM