May 23, 2016 | Written by: usiddiqui
Categorized: How-tos | Mobile | Watson
Share this post:
Imagine you are the controller of road traffic in your town. Wouldn’t it be nice to set up an app which automatically directs cars to slow down when they enter a residential zone, or if it is raining in that area? What if you could reduce the number of cars that wander into your residential neighborhood? How about telling cars to slow down and turn around if they are approaching the scene of an accident? What if you could decide to call emergency medical services for that accident? What if you could do all this without leaving the comfort of your
couch home office?
Now that you are salivating at the thought of all that power at your fingertips, let’s do this and save (your little corner of) the world!
Extending the connected vehicle kit with Bluemix services
We start with the traffic simulator kit that extends the connected vehicle kit by Bryan Boyd. We use it to model 4 traffic zones in your urban area.
We use the Geospatial Analytics service on Bluemix to detect when cars enter and exit a traffic zone, and then we publish corresponding traffic alerts which contain ID of the car entering/exiting the zone, and the type of zone and the number of cars and accidents currently in it.
When two cars are involved in an accident, a circular red Accident zone appears around the scene of the accident. The cars’ drivers are asked the question “Are you doing alright?” and the drivers’ responses are published in a collision alert, which also contains the speeds of the cars when they hit each other. The accident clears after an amount of time specified by the car’s
collisionDelay property, which is 30000 milliseconds by default in our fast-moving small world.
Below is a video demonstration showing how to use the traffic simulator kit to configure traffic zone types, and how accident zones are created and removed:
The following diagram shows an overview of the messaging alerts in the traffic simulator kit:
Here are examples of the traffic and collision alerts.
Now that we have all this information at our disposal, let’s tell those cars what to do!
Design a Node-RED flow to determine the speed limit and traffic density of traffic zones
We use the Watson IoT platform and a Node-RED app on IBM Bluemix whose secret power is that it can harness all those data, analytics and cognitive services on Bluemix. We design a Node-RED flow, where we listen in on traffic alerts on the Watson IoT platform. The figure below shows a simplified version of the Node-RED flow. (For a complete version, refer to the tutorial for the traffic simulator kit).
If a car enters a traffic zone, we first check if it is raining in that zone using the Insights for weather service.
Next, we use Business Rules to determine the speed limit of the zone, given the type of zone, and if it is raining in the zone.
We also use business rules to determine the traffic density of a traffic zone, depending on its type and the number of cars and collisions in it. If it is an Accident zone, the density is always HIGH. Additional rules determine any warnings to be sent to the cars, such as the type of zone and if there is an accident ahead.
Next, in the Node-RED flow, we tell the cars to adjust their speed to the speed limit of the zone, and to reverse out of the zone if the traffic density of the zone is HIGH.
Let’s go for a (simulated) drive!
We deploy the Node-RED flow, and take another look at our town’s traffic. When a car now enters a traffic zone, it is notified of the speed limit of the zone, which is determined by the business rules.
The car’s speed is adjusted to within a close range of the speed limit.
If the car enters a HIGH traffic zone (determined by the business rules), it is directed to reverse out of the zone.
If it enters an Accident zone, the density is always HIGH in such a case, and the car is directed to reduce its speed by 5mph. It is also directed to reverse out of the Accident zone.
Modify the rules
This is great, but you decide you want to reduce the speed limit in residential areas because your kids are old enough to ride their bikes on the streets. No worries. Just update the business rules with the new value for the speed limit of a residential zone, and deploy them to the Business Rules service, et voila. There is no need to reconfigure or redeploy your Node-RED app if you do not change the version of the deployed rules.
Let’s recap. We have used the Insights for Weather and Business Rules services in our Node-RED flow to help us decide the speed limit and traffic density for traffic zones depending on traffic and weather conditions, and accordingly direct cars to adjust their speeds and reverse out of traffic zones if necessary.
Design a Node-RED flow to determine the severity of accidents
How about if an accident occurs? As road traffic controller, with great power comes great responsibility. You do want to make sure that you get emergency medical services out there as soon as possible if it is a high severity accident. However, if it’s a mild accident, let’s not waste city resources!
Let’s go back to our arsenal of choice: a Node-RED flow powered with Business Rules. Let’s also add some helpful artificial intelligence to it. We can use a cognitive service such as Watson AlchemyAPI to determine the sentiment of the drivers’ response to the question “Are you doing alright?”, right after the accident. If the sentiment is “negative”, we can decide to bump up the severity of an accident and call emergency medical services.
We design the Node-RED flow to listen for collision alerts on the Watson IoT platform. The figure above shows a simplified version of the Node-RED flow. (For a complete version, refer to the tutorial for the traffic simulator kit). If a collision occurs, we use the Watson AlchemyAPI service to determine the sentiment of the drivers’ responses to the post-collision question. Then we feed the sentiment (“positive”, “negative” or “neutral”), and the speeds of the 2 cars at the time of the accident into the business rules.
These are the business rules that determine the severity of the accident and if medical attention is needed.
Next in the Node-RED flow, we tell the cars to set the
collisionDelay property depending on the severity of the accident determined by the business rules. The
collisionDelay property determines how long each car takes to recover from an accident. For a SEVERE accident, we set it to 60000 milliseconds. We also call EMT, if the rules determine that medical attention is needed.
See the flow in action
Now we deploy the Node-RED flow and take another look at our town’s traffic. (Un)fortunately, an accident occurs and the drivers answer the question “Are you doing alright?”.
The rules determine the severity of the accident and if medical attention is needed, and how long the cars take to recover from the accident.
Now you can call emergency medical services if needed (from the comfort of your couch), and be the hero!
We used the Watson IoT Platform and Node-RED, as well services such as Geospatial Analytics, Business Rules, Insights for weather and Watson AlchemyAPI on Bluemix to build this traffic management app. (For technical details of the implementation, refer to the tutorial in the traffic simulator kit.)
We used business rules to implement decisions, and also to introduce logic changes without having to modify the application. You can spend less time re-coding and testing the application, when the logic can be changed and tested within the Business Rules service. This allows for greater business logic agility.
Going forward, you can use the many cognitive, data and analytics services on Bluemix to expand the power of business rules within your IoT applications.