[Tweets]

08/12/2017 1:05pm
RT @farscopecdt: @farscopecdt gives you the best possible start on your Robotics and Autonomous Systems research and innovation career, PhD…
29/11/2017 2:28pm
RT @DrARichards: How @farscopecdt student Katie got totally hooked on robotics [LINK]
28/11/2017 1:12pm
A quick overview of our Information-Cost-Reward framework - see how #robot #swarm #foraging performance can be disa… [LINK]
24/11/2017 5:11pm
RT @BristolRobotLab: APPLY NOW: Opportunity to join the FARSCOPE 4 year PhD programme in 2018, based here at the BRL [LINK]

[Developing in NXC using XCode]

Date: Jan 2012
Tags: robotics :: Mindstorms

There are a number of tools and IDEs you can use to create programs for the NXT Mindstorms. I would argue that the best tool should support most operating systems and involve C or a similar language (there is a limited memory on the brick so good memory management becomes an issue). While Robot-C is probably the best choice in terms of integration with the brick, it is a commercial tool and it only work on Windows so far. After comparing a number of options, I chose NXC as a pretty good alternative to Robot-C. It supports a lot of things like sensor and motor management, playing of sounds, basic 2D and 3D graphics, etc. Most importantly, you can compile your programs from the command line or from XCode. This tutorial assumes knowledge of XCode 4 and of C. The NXC programming guide is a good reference.

Setting up an XCode project

This blog by Mark C summarises the main points of NXC XCode development and provides a downloadable Hello World program. Rather than repeating what was said before, I would like to give a step-by-step guide to creating a project from scratch. The reason for that is that even if you download somebody else's HelloWorld program, XCode does not allow you to easily change the project name so it is always easier to create a new project.

1. Download

The first step is to download the latest nxc compiler and nxt firmware. Put the compiler on your disk, e.g. to the /Developer folder. Also, you might find the NeXT Tools useful.

Please read the tutorial Setting up NXC Development on a Mac if you are not sure about this step.

2. Create project

In XCode, choose 'Create new project' and select 'External Build System' under Mac OS X -> Other. This will take care of some basic build and target setup. In this example, we name our project 'MyProject'.

Creating a new XCode project step 1

Creating a new XCode project step 2


Comments

Lenka
[20/12/2014]
Hi Felix,

wow looks cool! Finally something specifically for NXC. And it's nice they include the latest compiler as well. Thanks a lot for sharing and have nice holidays too!

Lenka
Felix
[20/12/2014]
Hi Lenka!
It's me again. I more or less found a more specific IDE for mac! :D
https://github.com/mattrajca/NXC-TextMate-Bundle
With this bundle for Textmate you can have proper syntax highlighting and compile and download to the brick using cmd+R. It's great!
cheers and merry x-mas.
Felix
Lenka
[13/01/2013]
Sorry, I must have misunderstood you then. I thought you wanted to have different targets for different build settings, but with the same source. Your solution to the problem you mention is ok then.

Also thanks for the note about bluetooth - I am using USB so haven't encountered the problem yet.
Shinfane
[13/01/2013]


Lenka, I think this is not enough. Think a Project "Tribot" where you have 2 bots, one called Tribot.nxc, the other Second.nxc. In your case PROGRAM=Tribot, and it builds Tribot.nxc. If you add a target "Second" it will not build(compile) the other source.

You can't simply add new source files for new robots in $(SOURCE) and compile them as you need them.

In order to do so, you would need to change the makefile to produce $(TARGET_NAME) executable from $(TARGET_NAME) source.

The sources location is just relative to the makefile and has afaik no problem in you change $(PROGRAM) to $(TARGET_NAME).

At least this is the regular setup I am using all the time to create different robots from different nxc sources in the same XCode Project (fired up by different XCode targets)


On the options side you are right... one should use -d. I just had issues with downloading over Bluetooth with nbc -d.... so I switched to nxtcom with worked for me perfectly.
Lenka
[11/01/2013]


Hi Shinfane and thanks for your comments. There a couple of things:

1. Starting from the original makefile, you cannot just change the value of program to $(TARGET_NAME) as PROGRAM is also used to access the source files. Therefore, you should leave program as it is but you can change the following in order for your executable name to be based on your target name:
$(NXC) -O=../$(BUILD)/$(TARGET_NAME).rxe \

I have changed the instructions on the top based on this.

2. I'm not sure about the advantage of using nxtcom. The compiler itself (nbc) downloads for you if you use the -d option. I see what you mean about the option of not deploying to the brick though, it which case I would suggest defining the OPTIONS on the top without the -d parameter and then having your if statement changing the OPTIONS:
OPTIONS=-Z2 -I=../$(SOURCE)/ -EF
ifeq ($(CONFIGURATION), Debug)
OPTIONS=-Z2 -I=../$(SOURCE)/ -EF -d
endif


{Please enable JavaScript in order to post comments}

[Blog]

Robot swarms in action

Watch e-puck robots collect resources and bring them back to base. While the previous simulation work helped us to learn a lot about the...

[read full]

How to compile code for e-puck robots on your computer

Compiling code natively on e-puck robots or cross-compiling on your computer can be very tedious. Luckily, there is a third option:...

[read full]

Coding for tomorrow: Why is good code important?

"Why should I care about how my code is written, as long as it works?" I will argue here that well-structured and well-written code not...

[read full]

How Coding in Python Might Be Bad For You

7 reasons why coding in Python is like writing a really bad essay and getting away with it

[read full]