Hoeist!? Blog of Colin Raaijmakers.
FEZ Mini with Existing RC motor and Servo
Development
Managed to get an existing RC motor (ESC) and Servo running with the FEZ Mini and .NET Micro Framework. Source code below.
Program.cs
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
//
// FEZMiniBot
//
namespace FEZMiniBot
{
//
// Program
//
public class Program
{
//
// Declare Objects
//
private static FEZ_Components.SpeedController SpeedController;
private static FEZ_Components.ServoMotor ServoMotor;
//
// Startup Main Function
//
public static void Main()
{
//
// Print Startup Debug Information
//
Debug.Print("Starting up FEZ Mini Robot.");
Debug.Print("OEM String: " + SystemInfo.OEMString);
Debug.Print("Version: " + SystemInfo.Version.ToString());
//
// Create Objects
//
ServoMotor = new FEZ_Components.ServoMotor(FEZ_Pin.Digital.Di7);
SpeedController = new FEZ_Components.SpeedController(FEZ_Pin.Digital.Di8);
//
// Drive Forward
//
Debug.Print("001 Drive Forward");
SpeedController.CurrentDirection = FEZ_Components.SpeedController.DirectionState.forward;
SpeedController.SetSpeed(100);
Thread.Sleep(5000);
SpeedController.Stop();
//
// Steer Right
//
Debug.Print("002 Steer Right");
ServoMotor.GoRight();
Thread.Sleep(500);
//
// Drive Reverse
//
Debug.Print("003 Drive Reverse");
SpeedController.CurrentDirection = FEZ_Components.SpeedController.DirectionState.reverse;
SpeedController.SetSpeed(25);
Thread.Sleep(2000);
SpeedController.Stop();
//
// Steer Forward
//
Debug.Print("004 Steer Forward");
ServoMotor.GoForward();
Thread.Sleep(500);
//
// Drive Forward
//
Debug.Print("005 Drive Forward");
SpeedController.CurrentDirection = FEZ_Components.SpeedController.DirectionState.forward;
SpeedController.SetSpeed(100);
Thread.Sleep(5000);
SpeedController.Stop();
//
// Sleep Forever, Unreachable code ;-)
//
Debug.Print("Sleep Infinite.");
Thread.Sleep(Timeout.Infinite);
}
}
}
SpeedController.cs
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;
namespace GHIElectronics.NETMF.FEZ
{
public static partial class FEZ_Components
{
public class SpeedController : IDisposable
{
OutputCompare oc;
uint[] timings = new uint[5];
uint forward = 100 * 15;
uint reverse = 100 * 10;
uint stop = 100 * 5;
public DirectionState CurrentDirection = 0;
public enum DirectionState : byte
{
forward = 0,
reverse = 1
}
public void Dispose()
{
oc.Dispose();
}
public SpeedController(FEZ_Pin.Digital pin)
{
oc = new OutputCompare((Cpu.Pin)pin, true, 5);
}
public void SetSpeed(uint speed)
{
uint direction = forward;
if (CurrentDirection == DirectionState.reverse)
{
direction = reverse;
}
timings[0] = direction;
timings[1] = (100 - speed) * 1000;
oc.Set(true, timings, 0, 2, true);
}
public void Stop()
{
timings[0] = stop;
timings[1] = 5000 * 1000;
oc.Set(true, timings, 0, 2, true);
}
}
}
}
Servo.cs
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;
namespace GHIElectronics.NETMF.FEZ
{
public static partial class FEZ_Components
{
public class ServoMotor : IDisposable
{
OutputCompare oc;
uint[] timings = new uint[5];
public void Dispose()
{
oc.Dispose();
}
public ServoMotor(FEZ_Pin.Digital pin)
{
oc = new OutputCompare((Cpu.Pin)pin, true, 5);
}
public void SetPosition(byte angle_degree)
{
uint pos = (uint)(((float)((2500 - 400) / 180) * (angle_degree)) + 400);
timings[0] = pos;
timings[1] = 50000;
oc.Set(true, timings, 0, 2, true);
}
public void GoForward()
{
SetPosition(90);
}
public void GoLeft()
{
SetPosition(120);
}
public void GoRight()
{
SetPosition(65);
}
}
}
}
VB.NET Option Strict and Option Explicit
Development
Option Explicit On forces you to declare all your variables, which makes your code easier to read and maintain. Be sure to use the As clause in every declaration, including procedure arguments. If you do not specify As, your variables and arguments take data type Object, which is usually not the optimal type. Using As improves performance because it moves type inference from run time to compile time. For more information, see Option Explicit Statement.
Option Strict On disallows implicit narrowing, requires the As clause in every declaration, and disallows late binding regardless of the Option Explicit setting. You can still perform narrowing type conversions, but you must use explicit conversion keywords such as CInt and CType. Explicit declaration improves performance because it protects your code from inadvertent late binding. For more information, see Option Strict Statement.
Option Compare Binary specifies that strings are to be compared and sorted based on the binary representation of their characters, without considering equivalent characters such as uppercase/lowercase pairs. You should use binary comparison whenever your application's logic permits it. It improves performance because the code does not need to deal with case insensitivity, or with groups of characters considered alphabetically the same in a given culture.
VB.NET Short Circuiting (AndAlso OrElse)
Development
When possible, you should use the short-circuiting Boolean operators, AndAlso and OrElse. These can save time by bypassing the evaluation of one expression depending on the result of the other. In the case of AndAlso, if the result of the expression on the left is False, the final result is already determined and the expression on the right is not evaluated. Similarly, OrElse bypasses the expression on the right if the one on the left evaluates to True. Note also that the Case statement can short-circuit a list of multiple expressions and ranges, if it finds a match value before the end of the list.
Ibotec B.V. heeft een vernieuwde website
Development
Ingenieursbureau Ibotec b.v. is opgericht in 1993 en is gespecialiseerd in VvE beheer. Voor onze opdrachtgevers staat een team klaar dat thuis is in alle aspecten m.b.t. VvE beheer. Ons team van ervaren medewerkers bestaat uit VvE Accountmanagers, administratieve-, technische en financiële medewerkers. Daarnaast staat de afdeling bouwadvies desgewenst de VvE terzijde met bouwadviezen, begeleiding groot onderhoud alsmede voor het opstellen van groot onderhoudsplannen.
About me
Application & Web Developer
at The Cre8ion.Lab
Application Developer, Database Administrator, and Project Manager in a wide variety of business applications. Particularly interested in client/server and relational database design using MS-SQL Server. Always interested in migration projects, as well as close interaction with the .NET and DB manufacturers.
Skills
Microsoft Visual Studio 6.0, 2002, 2003, 2005, 2008 & 2010, Macromedia Flash (8.0, CS3, AS2, AS3) en Dreamweaver, Microsoft SQL Server 2000, 2005 & 2008, MySQL Server, Microsoft IIS WebServer 5, 6 en 7, Apache Webserver, Microsoft Commerce Server 2000, HTML, dHTML, XHTML, CSS, W3C, Javascript, ASP, VBscript, ASP.NET, VB.NET, C#.NET, basis PHP, XML, jQuery + Plugins, Diverse Frameworks & Content Management Systemen, TCP/IP, DHCP, LAN, WAN, WLAN, Microsoft .NET Micro Framework 4.1.
Tagcloud
colin raaijmakers, vb.net, logitech, g19, applet, plugin, application, g19app, xfire, teamspeak, winamp, asp, windows, remote, vista, internet, booty, suit, of, sin, sql, function, ie8, app, applets, microsoft, ie7, android, samsung, google, 2.3.5, 2.3.6, update, kies, upgrade
