.
Anmeldung | Registrieren | Hilfe

.NET-Blogs Archiv März 2016

Ultimaker 2+ arrived

24.03.2016 18:00:00 | Daniel Springwald

Seven years ago in 2009 I started my first experiences with 3d printing.

It took 2 weeks to assemble my first 3d printer – a rapman from UK. It had no heated built plate and the software needed lot of tuning and testing.

The rapman in 2009:

Then in 2011 I got the makerbot thing-o-matic. It had a heated, automated build platform and only took 2 days to assemble. The software still needed time to tune and to find out the best setting.

All this time I never managed to get PLA printing well – only ABS worked fine for me.

The makerbot in 2011:

Yesterday – 5 years after the makerbot – my ultimaker 3d printer arrived.
In my opinion there are worlds between these two last devices.
The ultimaker looks like from the future with its white led lighted housing, while the makerbot looks like from the past with his wooden case.
The ultimaker prints a lot of finer and more silent than my old makerbot.
No (or only a little bit) software tuning is needed– it is nearly plug and print.
It is very impressive for me to see, how big the improvements of these 5 years are.

Here are some impressions:

Improving the Oculus Rift DK2

23.03.2016 22:00:00 | Daniel Springwald

During the last weeks I added two useful extensions to my oculus rift.

Attaching the leap motion

The first one is a “must have” for the virtual reality glasses: The leap motion controller.


Attach it to the front of the oculus rift to see your own hand inside the virtual reality. 
I already tried to manage this effect using the Kinect some months ago. But the leap motion solution is a much easier to handle.

Attaching a fan

Sometimes - especial in the summer time - the oculus glasses got a little bit fogged. 
This can be disturbing when in an exciting elite-dangerous battle. So I added a small fan to the rift. It can turned on, when needed. 

Before:

After:


 

Configure your ASP.​NET Core 1.0 Application

20.03.2016 18:00:00 | Jürgen Gutsch

The Web.Config is gone and the AppSettings are gone with ASP.NET Core 1.0. How do we configure our ASP.NET Core Application now? With the Web.Config, also the config transform feature is gone. How do we configure a ASP.NET Core Application for specific deployment environments?

Configuring

Unfortunately a newly started ASP.NET Core Application doesn't include a complete configuration as a sample. This makes the jump-start a little difficult. The new Configuration is quite better than the old one and it would make sense to add some settings by default. Anyway, lets start by creating a new Project.

Open the Startup.cs and take a look at the controller. There's already something like a configuration setup. This is exactly what the newly created application needs to run.

public Startup(IHostingEnvironment env)
{
    // Set up configuration sources.
    var builder = new ConfigurationBuilder()
        .AddJsonFile("appsettings.json")
        .AddEnvironmentVariables();

    if (env.IsDevelopment())
    {
        // This will push telemetry data through Application Insights 
        // pipeline faster, allowing you to view results immediately.
        builder.AddApplicationInsightsSettings(developerMode: true);
    }
    Configuration = builder.Build();
}

But in the most cases you need much more configuration. This code creates a ConfigurationBuilder and adds a appsettigns.json and environment variables to the ConfigurationBuilder. In development mode, it also adds ApplicationInsights settings.

If you take a look into the appsettings.json, you'll only find a ApplicationInsights key and some logging specific settings (In case you chose a individual authentication you'll also see a connection string):

{
  "ApplicationInsights": {
    "InstrumentationKey": ""
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Verbose",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

Where do we need to store our custom application settings?

We can use this appsettings.json or any other JSON file to store our settings. Let's use the existing one to add a new section called AppSettings:

{
    ...
    
    "AppSettings" : {
        "ApplicationTitle" : "My Application Title",
        "TopItemsOnStart" : 10,
        "ShowEditLink" : true
    }
}

This looks nice, but how do we read this settings?

In the Startup.cs the Configuration is already built and we could use it like this:

var configurationSection = Configuration.GetSection("AppSettings");
var title = configurationSection.Get<string>("ApplicationTitle");
var topItmes = configurationSection.Get<int>("TopItemsOnStart");
var showLink = configurationSection.Get<bool>("ShowEditLink");

We can also provide a default value in case that item doesn't exist or in case it is null

var topItmes = configurationSection.Get<int>("TopItemsOnStart", 15);

To use it everywhere we need to register the IConfigurationRoot to the dependency injection container:

services.AddInstance<IConfigurationRoot>(Configuration);

But this seems not to be a really useful way to provide the application settings to our application. And it looks almost similar as in the previous ASP.NET Versions. But the new configuration is pretty much better. In previous versions we created a settings facade to encapsulate the settings, to not access the configuration directly and to get typed settings.

No we just need to create a simple POCO to provide access to the settings globally inside the application:

public class AppSettings
{
    public string ApplicationTitle { get; set; }
    public int TopItemsOnStart { get; set; }
    public bool ShowEditLink { get; set; }
}

The properties of this class should match the keys in the configuration section. Is this done we are able to map the section to that AppSettings class:

services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));

This fills our AppSettings class with the values from the configuration section. This code also adds the settings to the IoC container and we are now able to use it everywhere in the application by requesting for the IOptions<AppSettings>:

public class HomeController : Controller
{
    private readonly AppSettings _settings;

    public HomeController(IOptions<AppSettings> settings)
    {
        _settings = settings.Value;
    }

    public IActionResult Index()
    {
        ViewData["Message"] = _settings.ApplicationTitle;
        return View();
    }

Even directly in the view:

@inject IOptions<AppSettings> AppSettings
@{
    ViewData["Title"] = AppSettings.Value.ApplicationTitle;
}
<h2>@ViewData["Title"].</h2>
<ul>
    @for (var i = 0; i < AppSettings.Value.TopItemsOnStart; i++)
    {
        <li>
            <span>Item no. @i</span><br/>
            @if (AppSettings.Value.ShowEditLink) {
                <a asp-action="Edit" asp-controller="Home"
                   asp-route-id="@i">Edit</a>
            }
        </li>
    }
</ul>

With this approach, you are able to create as many configuration sections as you need and you are able to provide as many settings objects as you need to your application.

What do you think about it? Please let me know and drop a comment.

Environment specific configuration

Now we need to have differnt configurations per deployment environment. Let's assume we have a production, a staging and a development environment where we run our application. All this environments need another configuration, another connections string, mail settings, Azure access keys, whatever...

Let's go back to the Startup.cs to have a look into the constructor. We can use the IHostingEnvironment to load different appsettings.json files per environment. But we can do this in a pretty elegant way:

.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)

We can just load another JSON file with an environment specific name and with optional set to true. Let's say the appsettings.json contain the production and the default settings and the appsettings.Staging.json contains the staging sepcific settings. It we are running in Staging mode, the second settings file will be loaded and the existing settings will be overridden by the new one. We just need to sepcify the settings we want to override.

Setting the flag optional to true means, the settings file doesn't need to exist. Whith this approatch you can commit some default setings to the source code repository and the top secret access keys and connections string, could be stored in an appsettings.Development.json, an appsettings.staging.json and an appsettings.Production.json on the buildserver or on the webserver directly.

Conclusion

As you can see, configuration in ASP.NET Core is pretty easy. You just need to know how to do it. Because it is not directly visible in a new project, it is a bit difficult to find the way to start.

Schneller starten mit Start Bootstrap

17.03.2016 06:30:02 | Johnny Graber

Das CSS-Framework Bootstrap hält sich schon erfreulich lange unter den beliebtesten Frameworks für Webentwickler. Ohne grossen Aufwand kommt man damit zu in sich stimmigen Webseiten, die sich automatisch auch den engen Platzverhältnissen auf mobilen Geräten anpassen können (sogenanntes Responsive Design). Der Start ist sehr einfach und wenn man Bootstrap personalisieren will, geht dies ohne grossen … Schneller starten mit Start Bootstrap weiterlesen

HPI: Mädchen an die Tastatur

14.03.2016 17:56:33 | Mathias Gronau

Dass Frauen in der IT deutlich unterrepräsentiert sind, ist eine Binsenweisheit. Eine logische Erklärung habe ich dafür nicht. Daher begrüße ich auch eine Initiative des Hasso Plattner Instituts, mehr Mädchen für die Bildschirmarbeit zu begeistern. Um den Frauenmangel in der IT intelligent zu bekämpfen, haben heute das Hasso-Plattner-Institut und seine Bachelorstudentin Lisa Ihde (20) der deutschen Bundesbildungsministerin Prof. Johanna Wanka auf der „Männer-Messe“ CeBIT versprochen. Einen ersten speziellen Onlinekurs für Mädchen, der Schülerinnen an die Informationstechnologie heranführen soll, hat das Potsdamer Hasso-Plattner-Institut (HPI) im Beisein von Bildungsministerin Prof. Johanna Wanka angekündigt. Am Eröffnungstag der CeBIT nahm Wanka vor der Kamera auf dem HPI-Stand (Halle 6, D18) ein Grußwort an die Teilnehmerinnen auf, die ab 6. Juli den zweiwöchigen kostenlosen Online-Workshop auf der Bildungsplattform openHPI des Instituts mitmachen werden. Institutsdirektor Prof. Christoph Meinel sagte: „Wir hoffen, dass gerade die Schülerinnen im deutschsprachigen Raum die Botschaft der Bildungsministerin als klare Einladung zum Mitmachen verstehen“. Initiatorin und HPI-Bachelorstudentin Lisa Ihde (20) aus Potsdam stellte Wanka ihr Konzept vor. „Ich finde es sehr wichtig, dass auch Politikerinnen Mädchen und junge Frauen aktiv motivieren, die Informatik für sich zu entdecken“, so Ihde, die aus Oranienburg stammt. Sie habe sich mit Wanka darüber unterhalten, warum bei vielen Schülerinnen die Begeisterung für das Programmieren zunächst ausbleibe: „Meiner Erfahrung nach liegt das nicht so sehr an den Inhalten, sondern an der Ansprache. Mädchen interessieren sich häufig eher für die kreativen, gestalterischen Möglichkeiten, die die Informatik bietet“, erklärte Ihde. Vom 6. Juli an will sie zwei Wochen lang jungen Frauen auf openHPI zeigen, wie diese eine eigene Homepage designen können. „Zur Zielgruppe gehören Mädchen, die als Weltenbummler ihre Erfahrungen und Fotos auf einer eigenen Webseite teilen wollen, sich in Fashionblogs über neueste Mode-Trends informieren und vielleicht in einem eigenen Blog ihre persönlichen Lieblingsstücke präsentieren möchten“, sagt Ihde. Im Blick habe die Bachelorstudentin, die in der Freizeit gerne tanzt, aber auch Schulklassen mit dem Wunsch nach einer eigenen Internetseite, „auf der jeder auf einen Blick seht, was in den nächsten Wochen so ansteht und was auf Klassenfahrt nicht fehlen darf“. Da haben wir es wieder. Eigentlich soll die Initiative die jungen Frauen ermutigen, die überkommenen Rollenklischees hinter sich zu lassen. Und dann hat die Initiatorin keine bessere Idee für die Teilnehmerinnen an dem Onlinekurs als Themen wie Beauty und Mode zu wählen. Ich kann nur hoffen, dass die Teilnehmerinnen mit besseren Ideen für den Content auftrumpfen. Aber ich will die Initiative nicht schlechtmachen. In dem zweiwöchigen Onlinekurs (Anmeldung unter https://open.hpi.de/courses/homepage2016) wird die 20-jährige HPI-Studentin zeigen, wie die Teilnehmerinnen in wenigen Schritten zu ihrer eigenen Homepage gelangen und was sie dabei hinsichtlich Urheberrechten, Bild- und Farbzusammenstellung beachten sollten. Außerdem erfahren die MOOC-Teilnehmerinnen, woher sie sich witzige Icons holen und sogar eigene Icons, ein eigenes Logo und vieles mehr entwickeln können. Die junge Kursleiterin engagiert sich neben dem Studium als Mentorin bei verschiedenen Schülercamps, CoderDojos und Workshops des Hasso-Plattner-Instituts in Potsdam. Aber nicht nur am HPI kümmert sie sich um den Programmier-Nachwuchs, sondern auch bei anderen Events von der Open Knowledge Foundation […]

Der Microsoft TechGuide fuer AppDevs, GameDevs, WebDevs, OfficeDevs, Developer oder ITPros

14.03.2016 12:01:23 | Kay Giza

Pünktlich zur CeBIT 2016 haben wir unseren Microsoft TechGuide erweitert.
Der TechGuide soll für eine einfachere Orientierung sorgen – er bietet Suchenden schnell und kompakt Links zu den wichtigsten Ressourcen und Downloads aus dem deutschsprachigen Microsoft-Universum für Entwickler & IT-Professionals.

Genauer gesagt finden IT Pros, Software-Entwickler, Web-Developer, App-Developer, Spiele-Entwickler sowie Office-Developer einen Einstieg sowie Übersicht.


Microsoft TechGuide

Der Microsoft TechGuide in der Übersicht:

Über Feedback jeder Art freuen wir uns immer! Bitte via Kommentar hier im Blog oder via Twitter an @MSDEV_DE oder @KayGiza. Danke im Voraus!
Gerne auch ein RT von diesem Tweet wenn Dir der TechGuide gefällt: Alles was Du als #Developer oder #ITPro wissen musst, der @msdev_de #TechGuide: http://bit.ly/1ppg1B1  #AppDev #GameDev #WebDev #OfficeDev


This post is powered by www.Giza-Blog.de | Giza-Blog.de: RSS Feed
© Copyright 2006-2016 Kay Giza. All rights reserved. Legal

Microsoft-Chefin Sabine Bendiek: „Investitionsstau bedroht Innovationskraft“

14.03.2016 09:04:20 | Mathias Gronau

Heute beginnt offiziell die CeBIT. Es ist da eigentlich selbstverständlich, dass auch Microsoft seine Sicht der Lage erklärt. Auch wenn ich die Einschätzung nicht in allen Punkten teile, will ich doch auch Microsoft hier zu Wort kommen lassen. Microsofts Einschätzung der wirtschaftlichen Lage in Deutschland erklärt auch den CeBIT-Auftritt des Unternehmens, der in diesem Jahr anders aussieht als in der Vergangenheit. Die folgenden Angaben stammen aus einer Pressemitteilung des Unternehmens. Die konjunkturelle Lage in Deutschland ist gut, die Auftragsbücher sind voll. Die Eigenkapitalquote deutscher Unternehmen erreicht Rekordhöhen, das Zinsniveau Tiefststände. Und auch der Bundeshaushalt steht auf einem stabilen Fundament. Ideale Voraussetzungen, um die digitale Transformation auch finanziell zu stemmen. Unter dem Motto #DigitalesWirtschaftswunder stellt Microsoft auf der CeBIT sieben Faktoren vor, die den Wandel in Unternehmen und staatlichen Institutionen in Deutschland beschleunigen und als Investitionsziele die Chancen der Digitalisierung effizient erschließen. „Finanzstärke und Investitionsschwäche am Standort Deutschland passen nicht zusammen. Für ein #DigitalesWirtschaftswunder braucht es Mut zur Veränderung und einen kühnen Plan“, erklärt Sabine Bendiek, Vorsitzende der Geschäftsführung von Microsoft Deutschland. Laut Sparkassen- und Giroverband sind die Finanzierungsverhältnisse im deutschen Mittelstand „so günstig wie nie zuvor“, mit „großen Puffern bei Eigenkapital und Liquidität“. Und auch der Bundeshaushalt steht trotz Flüchtlingskrise auf einem stabilen Fundament. Mit fast 20 Milliarden Euro haben Bund, Länder und Gemeinden 2015 einen Rekordüberschuss erwirtschaftet. Kurz: Die Rahmenbedingungen für ein #DigitalesWirtschaftswunder sind besser denn je und auch die Technologien für den digitalen Wandel sind ausgereift, sicher und verfügbar. Investitionsstau bedroht Innovationskraft „Die Investitionsmittel sind da – ein überzeugender Plan, sie einzusetzen, fehlt an vielen Stellen. Für ein #DigitalesWirtschaftswunder sind jetzt gezielte Investitionen in die Faktoren Infrastruktur, Organisation, Team, Mitarbeiter, Wissen, Produktion und Staat erforderlich“, so Bendiek. Denn noch immer steht laut IDC mehr als die Hälfte der deutschen Unternehmen bei der digitalen Transformation ganz am Anfang und die KfW bemängelt schon seit Jahren die sinkende Innovationskraft kleiner und mittlerer Unternehmen. Der Vorsitzende der Expertenkommission Forschung und Innovation (EFI), Dietmar Harhoff, warnte erst im Februar, deutsche Unternehmen seien bei der Digitalisierung im internationalen Vergleich allenfalls Mittelmaß und auch die E-Government-Vorhaben deutscher Behörden kämen nicht recht voran. Microsoft Cloud Deutschland für einen beweglichen und souveränen Staat Microsoft wird seine Cloud-Dienste Azure, Office 365 und Dynamics CRM Online ab der zweiten Jahreshälfte 2016 sukzessive auch aus deutschen Rechenzentren anbieten. Das Angebot richtet sich besonders an Organisationen und Unternehmen in datensensiblen Bereichen wie dem öffentlichen, dem Finanz- oder dem Gesundheitssektor. Ein #DigitalesWirtschaftswunder hängt auch davon ab, ob sich Unternehmen und Bürger auf effiziente und flexible Strukturen in der öffentlichen Verwaltung stützen können. Die Digitalisierung ist für den öffentlichen Sektor eine Chance, beweglicher und dabei kunden- und serviceorientierter zu arbeiten. Laut Gutachten des nationalen Normenkontrollrats spart wirksames E-Government 34 Prozent des bürokratischen Aufwands. „Mit Microsoft Cloud Deutschland bieten wir eine Lösung an, die dem Staat hilft, beweglicher zu werden ohne Souveränität aufgeben zu müssen“, so Bendiek. Digitale Kunden verlangen digitale Kompetenzen Um Innovationen schneller auf den Markt zu bringen und mit dem voll vernetzten Kunden Schritt zu halten, müssen Organisationen dringend beweglicher […]

Visual Studio Code: Made in Heaven - aehm in Switzerland

10.03.2016 18:01:46 | Kay Giza

Mein Kollege Erich Gamma hat eine sehr beachtliche und vor allen informative Keynote auf den TechDays 2016 gehalten zu Visual Studio Code. Für alle VS Coder sollten die 30 Minuten eine Pflicht sein, man erfährt so einige WIRKLICH interessante Dinge rund um Visual Studio Code - oder wusstest Du, das Visual Studio Code irgendwas mal mit OneDrive, Visual Studio Team System, Internet Explorer oder Azure zu tun hatte? Und schlussendlich: Zur BUILD 2016 - so hat es Erich verraten... [... mehr in diesem Blogeintrag auf Giza-Blog.de]

This post is powered by www.Giza-Blog.de | Giza-Blog.de: RSS Feed
© Copyright 2006-2016 Kay Giza. All rights reserved. Legal

Connecting to a Windows 10 IoT device

10.03.2016 17:00:00 | Jürgen Gutsch

While playing around with Windows 10 IoT on a Raspberry PI 2, I found different ways to connect to the device to setup and manage it. Some other tools, mentioned in the getting started tutorial seem not to work on my machine. This post shows, how I setup and manage my Windows IoT devices.

Setup the SD Card

In the getting started tutorial there is a tool mentioned called Windows 10 IoT Core Dashboard. This tool should show you all your running Windows 10 IoT devices in your network and with this tool you should be able to setup a new device. This tool looks almost like this (screenshot in German):

This tool downloads the latest image of Windows 10 IoT and installed it on the SD Cards. Pretty useful and hopefully it doesn't download that image every time you need to setup a new SD Card ;)

If you already downloaded and installed the latest Windows 10 IoT for the Raspberry PI (or even every other Board) on your machine, you are able to Setup the SD Card directly using. Using the Windows Explorer just go to C:\Program Files (x86)\Microsoft IoT\ and start the IoTCoreImageHelper.exe. This is a small tool called Windows IoT Core Image Helper which uses the dism.exe to copy the FFU image to your SD card.

If you like to use command line tools, you're able to use the dism.exe directly which is located in the dism folder under C:\Program Files (x86)\Microsoft IoT\ ;)

Setup the Raspberry PI

This is just about the hardware. Plug-in a screen, mouse, keyboard and network cable or alternatively a WiFi adapter. (I use the original Raspberry PI WiFi adapter). Put you SD card with the Windows 10 IoT image in the SD card slot and plugin the power cable to switch the device on.

Now you just need to follow the wizard to setup your device. Usually the device will find your network and you're able to connect to the device. In case of WiFi you need to enter the WiFi key to connect to your network.

Connecting to the Raspberry PI

The already mentioned Windows 10 IoT Core Dashboard on your computer should find all the devices in your network, but it doesn't on my computer.

Maybe this happens also to you, or maybe this is really a problem on OSI Layer 8, as mentioned by Hannes Preishuber in his always friendly manner ;)

Anyway, there is another option to see all your devices from your computer. Again, go to the folder C:\Program Files (x86)\Microsoft IoT\ and start the WindowsIoTCoreWatcher.exe. This installs the Windows IoT Core Watcher which shows you all your devices and additionally the addresses, states and so on.

A right click on a device enables you to copy the physical address, the IP address or to open the web dashboard on that device.

The web dashboard is one of the most important tools, where you can manage your apps, watch the performance, manage your network connections and many more.

Maybe you need to enter a user name and a password to connect to your device. This is initially set to Administrator and p@ssw0rd.

SSH is another option to connect to your device. I usually use Putty to connect connect via SSH:

An additional way is FTP. Using FileZilla it looks like this:

Deploying an app using Visual Studio

You are able to deploy an already published app using the web dashboard of your device. Another easy way while you are developing your app, is to use Visual Studio 2015. This is pretty easy if you know the way to do it ;-)

Choose "ARM" as solution platform and Remote Machine as the target. The first time you choose the Remote Machine, the Remote Connections dialog will open. Type in the IP address of your PI and choose the authentication mode Universal. Click select and you are now able to deploy via F5 or via right click and deploy in the context menu of the current project.

To change the Remote Machine settings, just go to the debug settings and reconfigure the settings. I had to change the configuration because I chose the wrong authentication at the first time I tried to deploy:

Conclusion

The Windows 10 IoT Core Dashboard is useless for me, because it doesn't really work on my machine. And it doesn't really bother me why it doesn't work. Because there are some more ways to connect and to deploy to your device. Hope this helps to get a short overview about the setup, about connecting and the deployment to your Windows 10 IoT device.

Did I forgot something? Please drop me a comment and I'll immediately update this post.

DevOps und Application Lifecycle Management

09.03.2016 11:17:27 | Kay Giza

Nach meinem Blogpost den ich gestern veröffentlicht habe, erreicht mich einige Fragen rund um das Thema DevOps und Application Lifecycle Management. DevOps ist mehr als nur eine Technologie oder ein Toolset. Es ist ein Denkansatz, der eine kulturelle Weiterentwicklung voraussetzt. DevOps sollte als Weg und nicht als Ziel begriffen werden. Das Prinzip sollte schrittweise durch Projekte mit entsprechendem Umfang implementiert werden, um so Erfolge zu veranschaulichen, Erkenntnisse zu gewinnen und Weiterentwicklung zu realisieren... (mehr in diesem Blogeintrag auf Giza-Blog.de)

This post is powered by www.Giza-Blog.de | Giza-Blog.de: RSS Feed
© Copyright 2006-2016 Kay Giza. All rights reserved. Legal

ALM Days 2016: DevOps - der Weg ins naechste agile Zeitalter mit Sam Guckenheimer

08.03.2016 15:36:27 | Kay Giza

In fast genau einem Monat finden wieder die ALM Days statt! An zwei Konferenztagen am 13. und 14. April geben Application Lifecycle Management (ALM)-Experten ihr Wissen rund um aktuelle Themen im Bereich ALM an Sie weiter. Dieses Jahr stehen die ALM Days ganz im Zeichen von DevOps. Die Agenda liest sich wirklich spannend, was aber an den zahlreichen wirklich guten Sprechern liegt! Unter anderem vor Ort sind: Sam Guckenheimer (Microsoft Corp., Product Owner, Visual Studio Product Line), Martin Woodward (Microsoft Corp.) sowie 30 nationale und internatione ALM-Koryphäen. Meine Empfehlung... [... mehr auf Giza-Blog.de]

This post is powered by www.Giza-Blog.de | Giza-Blog.de: RSS Feed
© Copyright 2006-2016 Kay Giza. All rights reserved. Legal

Creating a Windows 10 IoT driven remote controlled car with the Raspberry PI 2

06.03.2016 17:00:00 | Jürgen Gutsch

In the last few months a started a small project with the kids. We wanted to create a car, which can be remote controlled via Wifi and a smart phone.

We bought a 2 wheel drive robot car chassis kit to get two motors, a chassis and a battery pack. This kit also includes a small switch and a rotatable stabilizing wheel. To steer the car it is pretty much easier to control two wheels with two separate servos.

I already had a L293D stepper motor driver, some jumper cables and a prototyping board to connect all that stuff. The good thing about the L293D is, that I can control two servos separately.

The L293D is pretty cool, because each side can control one servo. The outer pins connects to the power for the servos. In our case the battery pack with 6V. The two inner pins are going to the ground. The pins left and right from the inner pins need to be connected to the servos and the other two pins (RA0 to RA3) are connected to the Raspberry PI. This pins are used to control the servos.

  • sending a high to RA0 (on GPIO 23) moves the right wheel forward
  • sending a high to RA1 (on GPIO 22) moves the right wheel backward
  • sending a high to RA2 (on GPIO 18) moves the left wheel backward
  • sending a high to RA3 (on GPIO 17) moves the left wheel forward

Setting all the jumpers, connecting all to the RPI and the battery pack and it looks like this:

I use a small power pack to get the right power (5V) for the Raspberry PI. I use the battery pack for the servos and the power pack for the RPI.

Let me introduce Rollie :)

To control the servos and to provide the remote control, we decided to use Windows 10 IoT, because it was simpler to setup the Wifi connection in the RPI. To setup Windows 10 IoT on a SDCard please follow the getting started guide on https://ms-iot.github.io/content/en-US/GetStarted.htm

To setup Windows 10 IoT on the PI, we needed to connect the PI on a screen and to connect a keyboard and a mouse. I followed the setup steps on the screen and configured the Wifi connection. (BTW: I use the original Raspberry Pi Wifi Adapter) If this is done the RPI will automatically connect to the configured WiFi and we don't need the screen, the keyboard and the mouse anymore.

Controlling the car

My idea was to provide a simple web page with the UI on it. This website should send commands to the PI via a simple Web API. Also the web page should be hosted on the RPI

Pressing a button should start the servo and releasing the button should stop the servo. The red "Stop"-button is something like a emergency stop while developing and will be removed later on.

Providing a Web API and the static web page was a bit challenging with the first tries, but I found a small library which helps a lot. It was Restup by Tom Kuijsten. Unfortunately this library didn't work with the Windows IoT Core Background Application, but a Universal Blank App works pretty fine. Restup is available as a NuGet package. I use version 1.0.0-beta2:

PW> Install-Package Restup -Pre

I created a new blank app and named it RollieServer. I added some code to initialize and start the HTTP server in the Page_Loaded method of the MainPage:

private async void Page_Loaded(object sender, RoutedEventArgs e)
{
    await InitializeWebServer();
}

private HttpServer _httpServer;
private async Task InitializeWebServer()
{
    // creating the http server
    var httpServer = new HttpServer(5000);
    _httpServer = httpServer;

    // register the api controller
    var restRouteHandler = new RestRouteHandler();
    restRouteHandler.RegisterController<RollieController>();

    // provide the web api 
    httpServer.RegisterRoute("api", restRouteHandler);
    // provide the web ui
    httpServer.RegisterRoute(new StaticFileRouteHandler(@"Web"));

    // starting the http server
    await httpServer.StartServerAsync();
}

I don't care about the XAML code of the page, because I don't need any UWP UI directly on the PI.

The StaticFileRouteHandler is pretty cool: I just needed to create a folder called "web" in the project folder. After that I was able to place a index.html page with the web UI in that folder. I also added a small CSS file and jQuery to that folder.

The RestRouteHandler registeres the RollieController to the HttpServer. Additionally the controller will be registered to the route /api/. Inside the Controller we use AttributeRouting to map the Actions to the specific routes:

[UriFormat("/rollie/{wheel}/{direction}/{rnd}")]
public GetResponse Wheel(string wheel, string direction, string rnd)
{
    // ...
}

In this case we have the sub route /rollie/. wheel specifies the right or the left wheel. direction can be forward, backward or off and the last option rnd is only used to call the API with a unique number to disable the cache. The url could look like this:

/api/rollie/left/forward/130981203

The logic

The RollieController provides the web API to control the servos. The controller initializes the RollieMachine which uses two Engines. One Engine per servo to control:

[RestController(InstanceCreationType.Singleton)]
public class RollieController
{
    private readonly RollieMachine _rollie;
    public RollieController()
    {
        _rollie = new RollieMachine(
            leftEngine: new Engine(forwardPin: 23, backwardPin: 22),
            rightEngine: new Engine(forwardPin: 17, backwardPin: 18));
    }

I pass in the GPIO pin numbers to use, into the engines.

In the API action I decided not to call specific methods of the RollieMachine to move the wheels direcly, but to set states of the Machine to move it afterwards depending on the states:

[UriFormat("/rollie/{wheel}/{direction}/{rnd}")]
Response Wheel(string wheel, string direction, string rnd)
{
    var stateChanged = false;

    if (wheel.Equals("left"))
    {
        _rollie.LeftState = EngineState.Off;

        if (direction.Equals("forward"))
        {
            _rollie.LeftState = EngineState.ForwardOn;
            stateChanged = true;
        }
        else if (direction.Equals("backward"))
        {
            _rollie.LeftState = EngineState.BackwardOn;
            stateChanged = true;
        }
        else if (direction.Equals("off"))
        {
            _rollie.LeftState = EngineState.Off;
            stateChanged = true;
        }
    }

    if (wheel.Equals("right"))
    {
        _rollie.RightState = EngineState.Off;
        if (direction.Equals("forward"))
        {
            _rollie.RightState = EngineState.ForwardOn;
            stateChanged = true;
        }
        else if (direction.Equals("backward"))
        {
            _rollie.RightState = EngineState.BackwardOn;
            stateChanged = true;
        }
        else if (direction.Equals("off"))
        {
            _rollie.RightState = EngineState.Off;
            stateChanged = true;
        }
    }

    if (stateChanged)
    {
        _rollie.Move();
    }

    return new GetResponse(
        GetResponse.ResponseStatus.OK,
        new DataReceived { Wheel = wheel, Direction = direction });
}

The call of the method Move() triggers the RollieMachine to do its job:

public void Move()
{
    MoveLeft();

    MoveRight();
}

private void MoveLeft()
{
    if (LeftState == EngineState.Off)
    {
        _leftEngine.Off();
    }
    else if (LeftState == EngineState.ForwardOn)
    {
        _leftEngine.Forward();
    }
    else if (LeftState == EngineState.BackwardOn)
    {
        _leftEngine.Backward();
    }
}

private void MoveRight()
{
    if (RightState == EngineState.Off)
    {
        _rightEngine.Off();
    }
    else if (RightState == EngineState.ForwardOn)
    {
        _rightEngine.Forward();
    }
    else if (RightState == EngineState.BackwardOn)
    {
        _rightEngine.Backward();
    }
}

The RollieMachine is only a sort of a controller class, which is handling states and triggers the engines to move in the tight direction. Lets have a look into the Engine class. To talk to the GPIOs of the Raspberry PI you need to add a reffernce to Windows IoT Extensions for the UWP to your project. This library should already be available on your machine and helps you to use the GPIO pins of your Raspberry PI, Arduino, or whatever is supported by Windows 10 IoT.

The Engine first needs to initialize the GPIOs (aka Pins). We need two pins, one to move the servo in the forward direction and one to backward:

internal class Engine : IDisposable
{
    private readonly int _forwardPin;
    private readonly int _backwardPin;

    private GpioPin _forwardGpio;
    private GpioPin _backwardGpio;

    public Engine(int forwardPin, int backwardPin)
    {
        _forwardPin = forwardPin;
        _backwardPin = backwardPin;

        InitGpio();
    }

    private async void InitGpio()
    {
        var gpio = await GpioController.GetDefaultAsync();

        if (gpio == null)
        {
            _forwardGpio = null;
            _backwardGpio = null;
            return;
        }

        _forwardGpio = gpio.OpenPin(_forwardPin);
        _backwardGpio = gpio.OpenPin(_backwardPin);

        _forwardGpio.Write(GpioPinValue.Low);
        _forwardGpio.SetDriveMode(GpioPinDriveMode.Output);

        _backwardGpio.Write(GpioPinValue.Low);
        _backwardGpio.SetDriveMode(GpioPinDriveMode.Output);
    }

In the method InitGpio() we need to get the GpioController to access the Pins. After some simple null handling I open the Pins with the passed in pin number. I also need to configure the pins as output pins and I write a Low to the output to ensure not to send anything.

With the next four methods I really control the servos:

// ensure to stop the servos and dispose the pins:
public void Dispose()
{
    Off();
    _forwardGpio?.Dispose();
    _backwardGpio?.Dispose();
}

// stop all servos:
public void Off()
{
    _forwardGpio?.Write(GpioPinValue.Low);
    _backwardGpio?.Write(GpioPinValue.Low);
}

// stop all servos and start moving forward
public void Forward()
{
    Off();
    _forwardGpio?.Write(GpioPinValue.High);
}

// stop all servos and start moving backward
public void Backward()
{
    Off();
    _backwardGpio?.Write(GpioPinValue.High);
}

It is pretty much important not to send Highs to both pins in the same time. This could kill the servo, the L293D or at least the RPI. This is why I always sent Low to all the pins, before sending a High to one of them.

The web UI

Shame on me, but the first draft of the web UI is using a layout table to place the buttons and I also use jQuery to control the buttons and to call the API. I will improve this in the future, but this is a small project with the kids and I can't write too much boring code with the Kids, who want to see a driving robot as a cool results. (The Kids are like customers, who want to see results instead of nice looking code)

<table>
    <tr>
        <td class="left"><button id="vl" type="button">Vor</button></td>
        <td class="center">&nbsp;</td>
        <td class="right"><button id="vr" type="button">Vor</button></td>
    </tr>
    <tr>
        <td class="left"><button id="bl" type="button">Zurück</button></td>
        <td class="center"><button id="stop" type="button">Stop</button></td>
        <td class="right"><button id="br" type="button">Zurück</button></td>
    </tr>
</table>

All the buttons are controlled with jQuery, which is also used to call the API:

$(function () {
	
	var leftForward = $('#fl');
    var rightForward = $('#fr');
    var leftBackward = $('#bl');
    var rightBackward = $('#br');

    var stop = $('#stop');

    var send = function (wheel, direction) {
        var now = Date.now();

        var url = '/api/rollie/' + wheel + '/' + direction;
        url += '/' + now;

        console.log('do: ' + url);
        $.get(url, function () {
            console.log('done: ' + url);
        });
    };

    leftForward.bind('mousedown', function () {
        send('left', 'forward');
    });
    leftForward.bind('mouseup', function () {
        send('left', 'off');
    });

    rightForward.bind('mousedown', function () {
        send('right', 'forward');
    });
    rightForward.bind('mouseup', function () {
        send('right', 'off');
    });

    leftBackward.bind('mousedown', function () {
        send('left', 'backward');
    });
    leftBackward.bind('mouseup', function () {
        send('left', 'off');
    });

    rightBackward.bind('mousedown', function () {
        send('right', 'backward');
    });
    rightBackward.bind('mouseup', function () {
        send('right', 'off');
    });

    stop.bind('mouseup', function () {
        send('right', 'off');
        send('left', 'off');
    });
});

With this code, everytime I press a button, the specific wheel will roll. And if I release the button, the wheel stops rolling.

If the app is deployed and running on the RPI I can use the browser on my smartphone to call the web page:

http://192.168.2.58:5000/index.html

To get the right IP address of yuor RPI, you should use the Windows IoT Core Watcher. This guy shows the Windows 10 IoT devices in your network and it displays the addresses, the online states and so on:

You also need to now the IP to deploy the app to your RPI with Visual Studio 2015.

Deployment

I used Visual Studio 2015 to deploy to the Raspberry PI. This is pretty easy if you know the way to do it ;-)

Choose "ARM" as solution platform and Remote Machine as the target. The first time you choose the Remote Machine, the Remote Connections dialog will open. Type in the IP address of your PI and choose the authentication mode Universal. Click select and you are now able to deploy via F5 or via right click and deploy in the context menu of the current project.

To change the Remote Machine settings, just go to the debug settings and reconfigure the settings. I had to change the configuration because I chose the wrong authentication at the first time I tried to deploy:

Conclusion

This is just the first step to build a small robot. Now it is a remote controlled car. The next step is to add a camera and to stream the video to the web UI on the smart phone. We additionally want to add some more sensors and to get this thingy more and more self controlled. :-)

Initially I wanted to use Node.js on a Rasbian OS, to learn more about Node.js. But it took too much time to configure the system to automatically connect to the WiFi and it got more and more boring for the Kids.

Switching to Windows 10 IoT was pretty fast and C# and Visual Studio are well known tools. Only the deployment and development flow is pretty much faster and easier using Node.js, because I can work directly on the RPI using Vi or Nano via a SSH terminal. Anyway, now I will continue working with Windows 10 IoT and Visual Studio 2015.

Ausprobieren: Cloud-Learning-Plattform Qualiero.com

04.03.2016 10:37:34 | Kay Giza

Pilotprojekt von Microsoft und dem Microsoft Learning Partner New Elements GmbH: Die Plattform Qualiero bündelt unterschiedliche kostenfreie und kostenpflichtige Lernformate, Neuigkeiten und Informationen, Übungsmöglichkeiten, Experten und Community zu Cloud-Themen wie Azure in einem einzigen Portal. Während der Pilotphase stehen die Grundfunktionen des Portals kostenfrei zur Verfügung. Experten, beispielsweise zur Projektunterstützung, und Lerninhalte wie Präsenztrainings können on-Demand kostenpflichtig gebucht werden... [... mehr in diesem Blogeintrag auf Giza-Blog.de]

This post is powered by www.Giza-Blog.de | Giza-Blog.de: RSS Feed
© Copyright 2006-2016 Kay Giza. All rights reserved. Legal

Regeln | Impressum