Navigating the Navigator. ArduPilot in Visual Studio 2010

by Visual Micro 2. May 2010 16:31

Editing any of the ardupilot versions using visual studio 2010 really shows off the quality of the ardupilot code. I love people who comment their code. Very neat!

 

 

 

And look how easy arduino project "navigation" is in Visual Studio, you can "Go To" the right place in the code.

 

 

I didn't know where the stabilize() function was but visual studio "Go To Definition" took me right to the attitude.pde. The intellisense in visual studio works best with well stuctured programs such as ArduPilot!

 

 

 

 

  

You need Visual Micro to make this work easily in 2010. It is free and quite new so the help system is a little confusing. Feel free to grab a copy.

 

The ardupilot code can't yet be compiled in visual studio due to the complex interaction between the multiple .pde files. However, Visual Micro adds a menu item to visual studio called "Open project in Arduino".which allows you to easily jump into the Arduino IDE to compile your mods. The next release of Visual Micro will allow compile and upload from within visual studio

 

 

Using the arduino boards menu in visual studio

by Visual Micro 11. April 2010 16:59

The visual studio tool bar provides a way to select which arduino circuit board each project will use

When a board is selected, all of the items in the "_core" filter are removed and replaced by the files from the newly selected boards arduino core

If the _core filter does not exist then it is created. In the example below, the board is about to switch from "atmega168" to "arduino mega"

In the current visual micro version the include and source files are automatically separated into "inc" and "src" filters (see below)

 

 

"One Click" add new source and header file(s)

by Visual Micro 11. April 2010 16:57

The "New" menu contains two very useful options enabling new files to be quickly added to an arduino visual studio project . This is a useful features if you often need to add a new .c and .h files to your projects.

note: To add files to your arduino projects in visual studio you can always use the standard visual studio "add file" or "add existing file" options.

Workflow Objective

Create a new .c file named MySubFile.c to the project (if it does not already exist) folder and link it to the project "Source Files" filter

Create a new .h file named MySubFile.h to the project folder (if it does not already exist) and link it to the project "Header Files" filter

Insert an #Include for MySubFile.h to the currently active source file (or .pde)

Open the new files for editing

 

How To

1. Choose to add .c/.h or .cpp/.h

 

2. Provide a name for the new files

 

3. Visual Micro does the rest!

Visual Micro for Arduino Readme

by Visual Micro 11. April 2010 11:20

=========================================================================
THE Visual Micro SOFTWARE IS PROVIDED TO YOU "AS IS," AND WE MAKE NO
EXPRESS OR IMPLIED WARRANTIES WHATSOEVER WITH RESPECT TO ITS
FUNCTIONALITY, OPERABILITY, OR USE, INCLUDING, WITHOUT LIMITATION, ANY
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
OR INFRINGEMENT. WE EXPRESSLY DISCLAIM ANY LIABILITY WHATSOEVER FOR ANY
DIRECT, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR SPECIAL DAMAGES,
INCLUDING, WITHOUT LIMITATION, LOST REVENUES, LOST PROFITS, LOSSES
RESULTING FROM BUSINESS INTERRUPTION OR LOSS OF DATA, REGARDLESS OF THE
FORM OF ACTION OR LEGAL THEORY UNDER WHICH THE LIABILITY MAY BE ASSERTED,
EVEN IF ADVISED OF THE POSSIBILITY OR LIKELIHOOD OF SUCH DAMAGES.
=========================================================================

===========================================================
Version: 1004.11
Copyright: Visual Micro 2010

For licence and usage guide see http://www.visualmicro.com.
This readme file must be included with Visual Micro.
===========================================================

-------
Summary
-------


The Visual Micro add-in for Microsoft Visual Studio requires the Arduino
software environment. The Arduino software is free and can be obtained
from http://arduino.cc.

The Visual Micro add-in (also known as Visual Micro for Arduino) has not
been approved or acknowldged by the Arduino creators.

This software is free of charge for personal and educational use only.

-----
Setup
-----


After installation, make sure the Visual Studio add-ins folder is
present, and manually copy the Visual.Micro.Visual.Studio.Arduino.AddIn
file to this directory.

The default location for the Visual.Micro.Visual.Studio.Arduino.AddIn
file is:

C:\Program Files\Visual Micro\Visual Micro for Arduino\

The default location for the Visual Studio add-ins folder is:

(Visual Studio 2008 : XP)
%ALLUSERSPROFILE%\Application Data\Microsoft\MSEnvShared\AddIns

(Visual Studio 2010 : XP)
%ALLUSERSPROFILE%\Microsoft Visual Studio\Addins

If you did not install Visual Micro into the suggested default location
you will need to edit the *.AddIn XML file to reflect the location of
your installation:

<Addin>
...
<Assembly>
..\Visual Micro\Bin\Visual.Micro.Visual.Studio.Arduino.dll</Assembly>
...
</Addin>

<ToolsOptionsPage>
...
<Assembly>
..\Visual Micro\Bin\Visual.Micro.Visual.Studio.Arduino.dll</Assembly>
...
</ToolsOptionsPage>

To disable Visual Micro you can:

1) Uncheck the add-in in Visual Studio's Add-In Manager;
2) Remove the *.AddIn file from Visual Studio's add-ins folder;
3) Set the <LoadBehavior> property in the *.AddIn file to '0'.

The default <LoadBehavior> = 5 causes the add-in to load in Visual
Studio. If you alter the <LoadBehavior> property you will need to restart
Visual Studio for the change to take effect.

--------------------
Visual Micro Options
--------------------


In Visual Studio you can specify the Arduino & AVR-GCC paths in the
Visual Micro options:

(Tools|Options|Visual Micro)

[Locations]
Arduino Application: ..\Arduino
Arduino Library : ..\Arduino\libraries
GCC Application : ..\Arduino\hardware\tools\avr\bin
Include Locations : < VS 2010 Intellisense Include Paths >
Sketch Folders : ..\My Documents\Arduino

[Projects]
Allow Compile: True
Allow Upload : True
Allow Create : True
Allow Open : True

You can compile simple shetches at the moment, but if a sketch references
another sketch then you may have problems.

In Arduino options you can check "Use external editor", this makes
Arduino reload the entire sketch prior to compilation, so you can edit in
Visual Studio and compile in Arduino quite easily.

---------------------
Visual Studio Options
---------------------


In Visual Studio you can associate the *.pde extension with Visual C++:

(Tools|Options|Projects and Solutions)

[VC++ Project Settings]
C/C++ FIle Extensions: *.cpp;*.cxx;*.cc;*.c;*.pde
Extensions To Include: .cpp;.cxx;.cc;.c; ... ;.manifest;.pde

(Tools|Options|Text Editor)

[File Extension]
Extension: PDE
Editor : Microsoft Visual C++

You can also tell Windows to treat *.pde files as C++ *.cpp files by
editing the registry. Save the text below to a *.reg file and execute it:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.pde]
@="CPPFile"

---------
Uninstall
---------


Uninstall Visual Micro via Windows Control Panel|Add/Remove Programs, and
manually delete the *.AddIn file.

If necessary, you can clear all Visual Studio commands created by Visual
Micro with the "/resetaddin" switch:

..\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe /resetaddin Visual.Micro.Visual.Studio.Arduino.Helper

Instead of using the switch, you can also set the "Installed" property to
"False" prior to uninstalling the software:

(Tools|Options|Visual Micro)

[User Interface]
Installed:
False 

 

 

How to automate arduino development using visual studio

by Visual Micro 11. April 2010 11:16

You may add any of the visual micro arduino commands to the visual studio tool bars and menus. You may also reference the commands in your visual studio macros. Serial ports, libraries, boards are also available as commands.

Example

The "Arduino Mega" will appear as a visual studio command (Tools, Customise), COM23 (if it exists) will also appear as a command, the SoftwareSerial library will also appear as a command.

Therefore you could add there new tool bar buttons for each providing a "one click" option to select options you use regularly. or you can create a workflow (macro) that automatically selects the "mega" board, sets COM23 and includes the software serial library into the current project.

Example: Customise Visual Studio Arduino Commands

 

Unsupported Upload Note

The compiler outputs .hex files into the <project>\_vsaddin\_build folder. The addin projects can be run from the visual studio command line. This makes it possible to design windows applications using visual stuidio that upload different arduino sketches based upon conditional factors. If you use the arduino visual studio compiler or the arduino uploader then please beaware that no liability is accepted by us and that you will break your arduino warranty

Quick Start Guide to Arduino Programing in Visual Studio

by Visual Micro 11. April 2010 10:54

 

After installing the .dll and resource files, you must configure your Visual Micro options:

 

Visual Studio | Tools | Options | Visual Micro

 

The most important option to set is the Arduino Application under [Locations]. Select the path to your Arduino executable (arduino.exe).

 

 

I suggest copying the latest Arduino (0018) to a folder called C:\Arduino\ArduinoIDE. By using a common Arduino folder you will find it easier to update to the latest Arduino versions in the future without having to reset your Visual Micro options.

 

After entering a valid Arduino folder, click the Arduino Library and the GCC Application (WinAVR) folder paths. They should automatically determine their locations.

 

 

 

 

 

After setting the Visual Micro properties, click [OK] to close the Options window. After a short pause (< 2 sec), the Visual Micro toolbar should appear containing the Boards and Serial ports menu.

 

 

Select your Arduino board and the serial port it is connected to.

 

Opening an Existing PDE

 

In Visual Studio select File|Open, and navigate to a folder containing an Arduino sketch (.pde). Select the sketch and click [OK]. The sketch will open briefly and then the following will happen automatically: the sketch will close, and it will be re-opened in a Project & Solution with the same name as the .pde; the Project & Solution will be created automatically in the sketch's folder.

 

Adding Libraries

 

You can add libraries using the Libraries menu on the toolbar, or add files to your projects as you normally would. When you add .c or .cpp files you will find that they automatically associate themselves to a custom build action of AVR_C_GCC or AVR_CPP_GCC (right-click with your mouse a source file to see what I mean).

 

If you encounter any problems just re-associate source files to the correct custom build tool. If you have an older Visual Studio project and want the toolbar to work with it then just edit the Visual Micro .vcproj and .sln files with Notepad, and copy over the platform and build settings.

 

NOTE that Visual Micro only compiles correctly when the build type is set to AVR|Win32. This is designed to ensure that Visual Micro doesn't mess with your normal Visual Studio projects.

 

Click compile and enjoy!

 

How to compile an arduino sketch in visual studio using avr-gcc

by Visual Micro 11. April 2010 10:50

The following visual studio arduino compilation overview is for information only and is not required knowlege to make use of the addin

The gcc system is used to compile .hex files (*see note at the end of this document) that you will find in the _vsaddin folder of each project. In this folder you will also find the .bat files that visual micro uses to compile each sketch

When a project has been compiled a folder will be created called _vsaddin\_build. This folder will contain the .o object files from the gcc compiler and also the compiled .elf and .hex files

Prior to compile/rebuild, the addin creates a unique list of include paths from all of the .h files included in the project. These paths are passed to the gcc compiler along with the avr\include folder. 

The list of paths will also include the current projects' reference paths (see visual studio project options). (The arduino addin does not add or alter visual studio project reference paths, it just uses them if they exist)

note: in the initial version using build>solution from the visual studio solution menu fails to compile. Use either the solution rebuild option or use the compile buttons on the addin tool bar

The .\_vsaddin folder

The Build/Compiler Output Window

note: when you compile, if a previous compilation does not exist, you might see some warning messages in the visual studio output window. these can be ignored. the output window will show you if the compilation succeeds

 

arduino visual studio compiler .bat files

The following .bat files are created and maintained automatically by the addin. The events that cause these files to alter are as follows:-

When you switch board

When you add an arduino library

When you compile the project

 

Description of each file

avr_build.rules 

this is a static file containing the definition of the custom build.rules for the project. the file is configured custom build rules on the visual studio project menu 

this file is responsible for providing the GCC_C_AVR and GCC_CPP_AVR custom build tools. when you add .c or .cpp files to your project they should automically be assigned to the respective rule./tool

 

build_all_begin

clear temp files from prev build

build_env.bat

enviroment variables and board/port settings 

build_c_item.bat

called once for each .c file in the project. creates a filename.c.o file using avr-gcc

build_cpp_item.bat

called once for each .cpp file in the project. creates a filename.c.o file using avr-g++

link_all.bat

 

creates a .hex from all the .o files using the avr tools and/or uploads to the arduino using the avr upload tool

 

* The visual studio arduino compile option is provided as way for you to verify that your code is correct. You should not upload the resulting compilations (.hex) to your arduino unless you are happy to void the arduino warranty. These feature(s) are also provided by us without warranty or liability.

 

How to enable arduino Intellisense in visual studio

by Visual Micro 11. April 2010 10:40

2nd may please see archive for visual studio 2010 intellisense ardupilot overview

 

The visual micro addin provides intellisense using visual studio for all arduino core, library and your own project files

If you add or link your own files to a visual micro project and the intellisense doesn't detect them. Just click compile on the tool bar (or rebuild the vs project)

Click CTRL+J in your code to see a master list of properties. See example...

When switching board, when adding an arduino library or when you add or link multiple existing files to a project you will see the background progress for the intellisense update

If your arduino intellisense stops working (somestimes happens with visual studio) then shutdown visual studio and delete the .ncb file of the project (it's in the projects folder). Important - Only delete the .ncb!

 

Arduino Visual Studio Overview

by Visual Micro 10. April 2010 22:21

Beta released 11th April 2010. Free version for private or student use is due for release end April 2010

Intellisense for the arduino is provided by Visual Studio. The 'Visual Micro' add-in simply helps to ensure that the files of a .pde project, the arduino core and arduino libraries are registered (or known) to the Visual Studio intellisense system.

Add-in preferences are set using the "Visual Studio Tools Options" window. When set the add-in will extend the Visual Studio menus and toolbars with additional controls to help you build arduino projects. (Note: all visual studio extensions created by the add-in are temporary)

The add-in is also able to retain board and port settings for each sketch (project). In most cases this means you will select a board and serial port once for the life of each project. That you can work on multiple projects at the same time, each project with its own board and port settings.

The add-in provides many other useful features.
Here are just a few...

> Automatic create new project from sketch

> Automatic link of all project items to intellisense

> Two way sketch compatibility with Arduino IDE

> Option to open the Arduino IDE loading the active visual micro studio project sketch.

> Automatic code completion (Visual Studio Style!)

> One click include of an Arduino Library

> Automatic LINK to arduino cores and libraries.

> When the arduino cores are updated your projects will automatically update (on next use)

> Standard copy/paste, highlight short cut keys

> All short cut keys user-definable

> Multi-instance Serial monitor enabling, for example, the output from two xbees to be monitored easily with auto port close if using the upload tools (see warning notes below about this!)

> Simple one click create of .c;.h with #include added to active .pde;.c or .cpp window.

> Code example helper makes it easy to create your own code examples for your projects.

> Examples/snippets are stored in an xml file in the same location of the code file.

 

 


Whilst not supported by Arduino or ourselves, the add-in allows you to switch on, at your own risk, "Compile and Upload" features. We have tried to ensure that these features are correct for Arduino and have been using our own boards without problem. We have found the Compile and Upload so useful we decided to leave it in the product (at your own risk!).

 

News - 2010

2nd May - Visual Studio 2010 - Navigating the Navigator with ArduPilot

18th April - Supports multiple sketch (pde) files in a single project (ArduPilot)

17th April - Supported on all windows language versions

14th April - First test success

11th April - The arduino visual studio beta was released today

Links and References

Visual Micro Forums here

Visit the Arduino forums here

A different solution here

Bob Powell's solution here

Ardupliot example here