element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Upcycle It
  • Challenges & Projects
  • Design Challenges
  • Upcycle It
  • More
  • Cancel
Upcycle It
Blog [Upcycle It] Interactive Race Car Driver - Software
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Workshopshed
  • Date Created: 28 Mar 2017 9:04 AM Date Created
  • Views 454 views
  • Likes 3 likes
  • Comments 0 comments
  • interactiveracecardriver
  • upcycle_it
  • upcycled_interactiveracecardriver
Related
Recommended

[Upcycle It] Interactive Race Car Driver - Software

Workshopshed
Workshopshed
28 Mar 2017

For the software, I wanted to keep the UI loosely coupled from the control, I also have been wondering about blue tooth vs wifi. By using Node.js for the server side components that means the same language (javascript) can be used for all of the software which should make things simpler. Another advantage of Node is because it is multi-platform it can be written and tested without the need for the Edison. So I've been doing this on Windows so far.

 

Overview

My plan to achieve this is to use an MQTT broker to pass the commands. These will be simple text strings such as "L" for left, "R" for right, "F" for forward etc. Initially, the commands will be sent using WebSockets but it is also possible to send the messages over bluetooth via a client side API and an MQTT-SN to MQTT gateway such as Aquilla . I'm also wondering if I should change these commands to be JSON objects to simplify processing and also to allow the motion controller to queue up commands and hence make the system programmable.

 

image

The broker will be run on the Edison so we don't need to have any external dependencies. The idea is to use Mosca to do this. It is possible to use Mosca directly in the code, but my plan is to have a separate Node application which I'm calling the "motion controller" this will take the messages and call the appropriate APIs to make the hardware move.

 

Code

 

In its the simplest form the motion controller subscribes to a topic and listens for messages.

 

#!/usr/bin/env node
// Listens for messages on a queue and moves car and driver
var mqtt = require('mqtt')
console.log('Connecting to Queue')
var client = mqtt.connect('ws://localhost:1884');

client.on('connect', function () {    
     client.subscribe('E14_UCDC/+/Commands')
})

client.on('message', function (topic, message) {
    console.log(message.toString());
    //Todo: Add movement code here.
})

 

The client side uses a different library as it runs in the browser. In it's simplest form it can send a message to the queue, on response to a button press, as follows:

 

  // Create a client instance
  var client = new Paho.MQTT.Client("ws://localhost:1884", "CarController");

  var message = new Paho.MQTT.Message("F");
  message.destinationName = "E14_UCDC/CarController/Commands";
  client.send(message);

 

For connecting to the hardware I'm looking at MRAA which can be accessed from Node and provides a simple way to access digital pins, I2C and PWM. This will be the first area to test once the Edison has arrived.

 

var mraa = require('mraa');
var pin13 = new mraa.Gpio(13);
pin13.dir(mraa.DIR_OUT);
pin13.write(1);

Reference

https://github.com/mcollina/mosca

https://eclipse.org/paho/clients/js/

https://github.com/Rodmg/aquila-mqtt-sn-gateway

https://github.com/intel-iot-devkit/mraa

Writing JavaScript for an Intel Edison

 

Other Posts

[Upcycle It] Interactive Race Car Driver - Plan of action

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube