collapse collapse

* Who's Online

  • Dot Guests: 73
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Board Stats

  • stats Total Members: 88
  • stats Total Posts: 11163
  • stats Total Topics: 1699
  • stats Total Categories: 4
  • stats Total Boards: 76
  • stats Most Online: 248

Author Topic: c coding for robots  (Read 2319 times)

0 Members and 1 Guest are viewing this topic.

Cody.Chandler

  • Guest
c coding for robots
« on: November 10, 2010, 10:58:37 am »
For those who are a pro at c and other languages, I was wondering if you could make a tutorial for those of us who are currently making a simple Lego bot. I understand a simple amount of the code, going forward and backwards, but I donít know how to incorporate light beam sensors and bump sensors into the code.

Offline Celestialkey

  • Administrator
  • Hero Member
  • *
  • Posts: 3962
  • Reputation 4874
  • Gender: Male
  • Its Alive!!
    • View Profile
    • www.CelestialCoding.com
Re: c coding for robots
« Reply #1 on: November 10, 2010, 11:33:29 am »
I'm assuming you are talking about LEGO Mindstorm(the only one I've ever owned.) If so, that language is completely proprietary to the Lego set. The blocks you use in the editor are translated into asm that is sent into the box. Unless someone around here has the set or software already installed, there is no way for us to provide a tutorial about it. Your best bet is to look into online resources dedicated to that language.

There is a "bypass" though for skipping the built in language and directly programming the robot in C. Use the newer mindstorm kit "Lego Mindstorm NXT". A good tutorial on it can be foun here. http://nxtgcc.sourceforge.net/EMSOFT-2009-Mindstorms-Tutorial.pdf

Since I no longer own it (gave it to my nephew) I cannot write any tutorials for it. Sorry. If your lucky, maybe someone else here has the set still.
Created By: Eczuo
Quote
I have noticed that people who claim that everything is predestined, and we can do nothing to change it, look both ways before they cross the road.
Quote
I'd prefer to die standing, than to live on my knees - Che Guevara
Quote
If you change the way you look at something, does that something change in any way?
- Quantum Theory

Hacking
Quote
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill


Quote from: Revelations 12:4
And his tail drew the third part of the stars of heaven, and did cast them into the earth; and the dragon stood before the woman which was ready to be delivered, for to devour her child as soon as it was born.

Quote
It takes skill to build an empire. It takes an idiot to maintain it.

Offline Sinister

  • - Secret Permissions Level 1 -
  • Sr. Member
  • ****
  • Posts: 383
  • Reputation 619
  • Gender: Male
    • View Profile
Re: c coding for robots
« Reply #2 on: November 12, 2010, 06:54:10 am »
Today is your lucky day, Cody.Chandler, because I happened to have used Legos Mindstorm NXT for my [bullshit] ICTP class.

The NXT software, I don't like using because you're limited on what you can do (while loops, functions), and the software wasn't designed for creating larger programs, else it will start lagging and be impossible to edit anything at all.

You don't really need to learn C to use NXT. Provided you do have the NXT software, and by what you are describing, that seems to be the case, all the built-in function for the legos bots are all included as blocks, each one representing a different statement.

Some blocks, like the move block you described earlier, work by themselves to move the robot forward, backwards, or to turn it. To use the different sensors, you must first hook up the sensor you want to use on the physical robot first, and make sure to remember which port that sensor is plugged into. There should be four possible ports (1-4). In NXT, there will be certain blocks that either activates the sensor itself, or can be used in conjunction with the sensor.

For example, the ultrasonic sensor, which is like a radar the robot can use to determine distances in front of it, can be called using the "ultrasonic sensor block", or you can take a Loop block, and set the loop condition to "ultrasonic sensor".

Loop blocks repeat the commands inside them, UNTIL the condition (in this case, whatever distance the ultrasonic sensor is measuring) is met.
You can say, for example: UNTIL Ultrasonic Sensor distance < 6 inches, move forward 1 rotation...

So as long as the robot is more than 6 inches away from the wall, it will move up 1 rotation, check the distance, move up 1 rotation, check the distance, move up 1 rotation...until when checking the distance, the ultrasonic sensor measures the distance to finally be < 6 inches. I hope this makes sense.
I don't have too much time right now, but I'll add screenshots and pictures later. Keep playing with the Block Palette, and you should find the blocks I am talking about.

 

Donate


* Search


* Recent Posts

Image Comparison by Shishka
[May 15, 2017, 01:18:02 pm]


Re: srchub - free source code hosting by Nathan
[December 14, 2015, 11:37:02 pm]


Re: srchub - free source code hosting by Celestialkey
[November 27, 2015, 08:51:42 am]


Updates by Nathan
[October 30, 2015, 08:27:36 pm]


Re: Client-Server Messaging by Nathan
[October 25, 2015, 05:48:57 pm]