|Software apps and online services:|
You are about to embark on a journey, and we are excited to be part of it! Get ready to make and program your robot using Windows 10 IoT Core!
By the time you are done with this project you will gain the following experience:
- Understand how Windows 10 Universal Windows Applications (UWA) work
- See how the same application can come alive and change behavior by running on the robot via Windows 10 IoT Core on a Raspberry Pi 2 and on your Windows 10 Desktop PC
- Control digital GPIO from your Raspberry Pi 2
- Process keyboard, mouse clicks and touch events
We are excited to embark on this journey with you - Thank you from the Microsoft IoT Team!
Download the project, load it into Visual Studio compile and deploy the application. Follow this link.
The application can be run in 2 ways:
- Windows 10 desktop UWA - here you can use the mouse or touch to drive the robot. You can also plug in the Xbox 360 controller and use that to drive the robot over the network
- Windows 10 IoT Core UWA for the Raspberry pi 2 - here you can drive the robot directly with the Xbox 360 controller, or via network commands from the Windows 10 UWA
The robot can move in 8 directions:
- Hard left turn
- Hard right turn
- Soft forward left turn
- Soft forward right turn
- Soft backward left turn
- Soft backward right turn
A hard turn rotates the wheels in opposite directions. A soft turn rotates only one wheel in the specified direction.
The robot can be controlled via the left analog stick or digital direction pad. They joystick can be plugged into the robot directly via the USB port on the Raspberry Pi 2 or the Windows 10 Desktop PC via USB.
From the Windows 10 Desktop PC UWA app, the keyboard controls are:
- Forward - Up arrow / W
- Backward - Down arrow / X
- Left - Left arrow / A
- Right - Right arrow / D
- Back Left - Z
- Back Right - C
- Forward Left - Q
- Forward Right - E
- Stop - Enter / Space
When run on the Windows 10 Desktop PC, there is an input screen with the 8 directional movements of the robot. Click or touch any of these to move the robot.
Bill of Materials
To build the robot, you will need the following:
- Wooden Robot Frame in 7 pieces - Get the cutting plans from the Sumo Robot Jr. GitHub repoand submit them to http://ponoko.com. We cut them 4 to a sheet of P3 5.2 mm Veneer Core Birch
- 2x continuous rotation servos, like these
- A ball caster, like this
- A USB Xbox 360 Controller
- a Digital switch, like this
- 6x 6" Male-to-Female Wires (2 red, 2 white and 2 black) like these
- 2x 6" Female-to-Female Wires (1 red and 1 black) like these
- Screws, Nuts, Bolts and standoffs like this
- Raspberry Pi 2, a 2 Amp power supply, SD card, network ethernet cable
- Micro screwdrivers
A picture is worth a 1000 words.
A video is 1000 pictures.
- Tolerances - The robot frame is designed to snap together. We have noticed some slight tolerance differences in the laser cuts of the wood frame. You may want to leave the protective tape on the non-visible side of the parts as a shim when assembling the robot. if you plan to glue the robot frame together or if the pieces fit very tightly, you can choose to remove the protective tape.
- Screw hole alignment - The screw holes were designed for the Raspberry pi 2, but the standoffs may not perfectly align due to tolerance differences in the laser cut frame. This is perfectly ok if the standoffs taper a bit.
- Don't overtighten! - Do not overtighten the screws that go into the standoffs. Overtightening can cause the substrate of the Raspberry pi 2 to crack. It's ok for these to just be a snug fit, or even a bit loose.
The robot kit software is a UWA project with 6 major files:
MainPage.xaml.cs - The main application code and entry point
- XboxHidController.cs - The initialization and handling logic for the Xbox controller
- MotorControl.cs - The main logic for controlling the continuous rotation servos
- Controller.cs - The logic for converting joystick, key press, mouse, and touch events to robot movements
- NetworkCommands.cs - the logic to setup client and server networking threads and create/process network messages
- package.appxmanifest - the manifest file that defines properties of this UAP application
The MainPage class is where the supporting robot classes get started. It is the only UI page for the RobotApp. The onscreen buttons, and key input properties, are setup in MainPage.xaml.
MainPage.xaml.cs is also where RobotApp reads the previously saved mode, and initializes itself to run as a Robot or Controller. When using a remote controller (optional), the robots need to know the name of a host computer, where the controlling app is running. It can be your laptop, or even a phone. The following String is where the default name can be hard-coded. It is also set in config.txt in the application data folder. Change it to your laptop's name or ip address, so the robots can connect to it for directional commands.
// Change to your laptop name or ip address private static String defaultHostName = "tak-hp-laptop";
The XboxHidController class contains the interface logic for getting input from the Xbox game controller. Once the initialization method in Controllers.cs finds an attached gaming HID device, it sets up the delegates in XboxHidController.cs to process the input events. Ultimately, these methods return a direction and a magnitude value, which are used to determine how to drive the servo motors.
There are two types of directional inputs from the game controller, DPad and joystick. The DPad type simply returns one of eight directions, making it easy to work with. The joystick type requires translating an X and Y value into appropriate directions, as well as filtering out minute movements while the stick is closer to its center position.
This MotorCtrl class handles all of the I/O to control the continuous rotation servo motors, and block sensor. The GPIO library is used to control selected I/O pins for this project. The main timing loop generates appropriate pulse signals to drive the motors, for any of the eight selected directions. This loop, is also where other critical system checks are done (i.e. block sensor, device communication breaks, etc.).
The block sensor, is also defined here, and was setup to demonstrate a basic motion-safety feature. With it connected, the robot will stop, and turn-around, if an obstacle triggers the switch.
This Controllers class coordinates the several types of input which can be used to drive the robot. Directional inputs are handled from key presses, mouse or touch input, and Xbox game controller input, which are either connected directly, or sent from a remote RobotApp. The Controllers class provides methods to translate each of these into the basic directional values used by the MotorControl class.
This NetworkCmd class sets up either a client or server stream socket object. If the RobotApp is a basic robot, a client object is used. A basic robot reads in commands from a networked App, to optionally use along with any locally attached input devices. If the App is setup as a remote controller, a server object which listens for connections is used. When the App is in a server mode, it writes directional commands out to connected client robots. Both modes of the RobotApp utilize the same Controllers classes.
See the note about how to set the *defaultHostName* string in *MainPage.xaml.cs* above, to set who the host computer is.
The Capabilities defined in the manifest file, enable networking, and human interface device privileges. Be sure to include these within your modified projects.
<Capabilities> <Capability Name="privateNetworkClientServer" /> <DeviceCapability Name="humaninterfacedevice"> <Device Id="any"> <Function Type="usage:0001 0005"/> </Device> </DeviceCapability> </Capabilities>
- Servo Power - The robot has the servos powered off the Raspberry Pi 2 GPIO ports. This is done as a simple example to demonstrate GPIO. This can cause a significant current draw and potential voltage drop on the Raspberry Pi 2. As long as your power source is rated for 2 amps you will be fine. For prolonged usage you are encouraged to move the control of the servos to a seperately powered and controlled PWM hat for the Raspberry Pi 2, like this one.
- Switch Location - The switch is part of the robot project to demonstrate GPIO inputs. If you want to build autonomous control of the robot, the switch is not in the best location. You are encouraged to move the switch to a more optimal location.
This robot kit (hardware and software) is made available as an Open Source Project.
The kit is a starting point. Let your creativity go wild with the mechanical, electrical and software design. Make the robot kit your own. Decorate it. Improve the cutting plans. Add motors; Add sensors; Submit improvements and bug fixes! No matter what, tell us what you did with it: #MakeInventDo
Thanks from the Microsoft IoT Team!
Love this project? Think it could be improved? Tell us what you think!