Participants in this workshop will get hands on experience building the TI-RSLK MAX robot platform. It is a wheeled robotic vehicle using the TI SimpleLink MSP432 LaunchPad and the CC3100 SimpleLink™ Wi-Fi® BoosterPack, an Internet-of-Things solution. Using Energia, TI's equivalent to simple Arduino-style scripting code, you'll come away with a full lab set up as well as teaching materials. This is a great low cost way to introduce the excitement of electronics and integrating wireless connectivity with IoT examples. Because the TI LaunchPad is open source and modular hardware, we can also add BoosterPack modules to augment our circuits. In our case we are going to add Wi-Fi to give our circuits a lot more capability by interacting with optional cloud services.
For more Robotics learning check out the TI-RSLK MAX, a comprehensive open source curriculum and hardware bundle that teaches the fundamentals of embedded systems through the application of mechatronics. TI-RSLK provides an advanced stepping stone to Robotic systems knowledge but still accessible for beginners with full lectures and lab activities.
PreworkBefore we begin, please ensure you:
1. Download and install the latest version of Energia. Energia can be downloaded from http://energia.nu/download/
You can also use the Installer which is a bit easier:
https://txn.box.com/s/nmvxuzdctdja3d7d796z2v6mvd4k8lkx
a. Below the download links there are specific installation instructions for each operating system version. Please follow these instructions as you may also need to install drivers depending on your OS.
b. NOTE: In Windows, Energia must be installed to a path without spaces in order to function properly.
c. NOTE: Windows users must have Energia Driver Package installed if they don't have it from CCS or other means. http://s3.amazonaws.com/energiaUS/files/energia_drivers.zip
2. Create a myTI account at my.ti.com if you don't have one so you can access CCS Cloud. You can also use your TI account to order kits from the TI store, request samples of silicon devices, and access other features.
Lab 1 - Build the TI-RSLK MAX robotHardware Required- TI-RSLK MAX kit
- 6x AA Batteries
In this lab we will put together our robot.
You also need a power source that we can equip to the robot to make it truly wireless. The TI-RSLK takes 6 standard AA batteries.
1. Follow these instructions to assemble your robot
http://www.ti.com/lit/pdf/SEKP164
2. Go ahead and attach the CC3100 BoosterPack on top of your LaunchPad. Make sure it is oriented correctly. You can line up the triangle arrow on P1 header of the BoosterPack with the 3V3 triangle on the P1 header of the LaunchPad. If you can read the english text and logos printed on the BoosterPack silkscreen then it is likely in the right direction. If the text is upside down compared to the LaunchPad text then you likely have it plugged in the wrong way.
3. Your robot is assembled. Hopefully it feels pretty stable and ready to roll. You can plug in your USB cable to the PC and we will test the robot using the debug tool. Navigate to www.ti.com/rslkdebugtool in Chrome or Firefox browser and follow the instructions to install the browser extension and TI Cloud Agent.
Lab 2 - Energia IntroductionHardware Required- TI-RSLK MAX
- Energia IDE
- Robot Library for TI-RSLK MAX
Energia IDE allows you to start rapid prototyping with the TI LaunchPad using Arduino style programming. This makes it really great at the beginning of a project to test out different community hardware solutions and integrate them into a custom application.
In this lab we are going to get our development environment set up. The first thing we can do is blink an LED to make sure we can program our microcontroller with our computer.
1. Open up the Energia IDE. Unzip your download and click the executable or app icon and it should start up.
2. First thing, make sure you select your board by going to Tools > Board and look for "LaunchPad with MSP432" on the menu. If your LaunchPad board is not present, go to the Boards Manager and install your LaunchPad board package. MSP432 boards should be the third option. Note: MSP432 EMT means Multitasking and has RTOS capability, but we don't need that right now.
3. If you properly installed your drivers, then you should see COM ports under Tools > Port. Select the port with UART capability if there are multiple options. You can verify the COM port in your computer's device manager.
4. Go to File > Examples > Basics > Blink. We will use the Green LED instead of the Red LED in our code in the case when the out of box code is a blinking Red LED. Uncomment the #define LED GREEN_LED line and comment out the RED_LED line.
Install robot library
1. We need to add the robot library to our Energia. Normally you can go to Sketch > Include Library > Library Manger...
Troubleshooting
Code not uploading?
- Check for errors in Energia debug window. The compiler will tell you what is happening. Errors are in red text.
- Sometimes your LaunchPad gets stuck or hung up on the previous code. Unplug your LaunchPad and plug it back in to perform a full reset. This is called a power on reset. Sometimes using the RESET button can work but taking away the power and letting the microcontroller fully reset is often best.
- If you have a failure to upload it could be your drivers are not properly installed. Energia will sometimes give the error “No unused FET Found” which means it can’t find a LaunchPad connected to your computer. Make sure you download the drivers for your operating system found on the Getting Started Guide.
- If you had no problem with the previous Blink example, your Energia should be correctly set up. Restart your LaunchPad and restart Energia IDE if you encounter any problems. Make sure to select the right serial port and board type under the Tools menu.
LED not lighting up?
- Make sure you properly uploaded the code and that you properly named your variables for the LED pins. There is very little chance that your LED is broken, but we can verify by blinking a different LED with the same code.
- Hit the reset button, sometimes this is needed for the LaunchPad to run the newly uploaded program.
- Assembled TI-RSLK MAX
Does it spin?
We will go ahead and test our robot out now with some sample code. Open up a new sketch by going to File > New. Paste in the sample code below and run it.
#include "Energia.h"
#include "SimpleRSLK.h"
bool hit_obstacle = false;
void waitBtnPressed() {
while(digitalRead(LP_S2_PIN) == 1){
digitalWrite(LP_RGB_LED_GREEN_PIN, HIGH);
delay(500);
digitalWrite(LP_RGB_LED_GREEN_PIN, LOW);
delay(500);
}
}
void checkCollision() {
for(int x = 0;x<6;x++)
{
/* Check if bump switch was pressed
* Parameter:
* bump switch number -> 0-5
* Returns:
* true -> if specific switch was pressed
* false -> if specific switch was not pressed
*/
if(isBumpSwitchPressed(x) == true) {
hit_obstacle = true;
Serial.println("Collision detected");
disableMotor(BOTH_MOTORS);
break;
}
}
}
void setup() {
/* Set serial communication to 115200 baud rate for MSP432 */
Serial.begin(115200);
delay(500);
/* Run setup code */
setupRSLK();
/* Initialize LED pins as outputs */
pinMode(LED_FR_PIN, OUTPUT);
pinMode(LED_FL_PIN, OUTPUT);
pinMode(LED_BR_PIN, OUTPUT);
pinMode(LED_BL_PIN, OUTPUT);
pinMode(LP_RED_LED_PIN, OUTPUT);
pinMode(LP_RGB_LED_RED_PIN, OUTPUT);
pinMode(LP_RGB_LED_BLUE_PIN, OUTPUT);
pinMode(LP_RGB_LED_GREEN_PIN, OUTPUT);
/* Initialize LaunchPad buttons as inputs */
pinMode(LP_S1_PIN, INPUT_PULLUP);
pinMode(LP_S2_PIN, INPUT_PULLUP);
}
void loop() {
Serial.println("Waiting until left button is pushed");
/* Wait until button is pressed to start robot */
waitBtnPressed();
/* Wait two seconds before starting */
delay(2000);
digitalWrite(LP_RGB_LED_BLUE_PIN, HIGH);
/* Enables specified motor.
* Parameter:
* Motor your referencing -> LEFT_MOTOR RIGHT_MOTOR BOTH_MOTORS
*/
enableMotor(BOTH_MOTORS);
/* Set direction of motor rotation.
* Parameter:
* Motor your referencing -> LEFT_MOTOR RIGHT_MOTOR BOTH_MOTORS
* Direction -> MOTOR_DIR_FORWARD MOTOR_DIR_BACKWARD
*/
setMotorDirection(LEFT_MOTOR,MOTOR_DIR_FORWARD);
setMotorDirection(RIGHT_MOTOR,MOTOR_DIR_FORWARD);
/* Set speed of motor.
* Parameter:
* Motor your referencing -> LEFT_MOTOR RIGHT_MOTOR BOTH_MOTORS
* Speed -> 0 - 100
*/
setMotorSpeed(BOTH_MOTORS,10);
while(!hit_obstacle) {
/* Move robot in place */
/* Right turn in place */
setMotorDirection(LEFT_MOTOR, MOTOR_DIR_BACKWARD);
setMotorDirection(RIGHT_MOTOR, MOTOR_DIR_FORWARD);
delay(1000);
/* Left turn in place */
setMotorDirection(LEFT_MOTOR, MOTOR_DIR_FORWARD);
setMotorDirection(RIGHT_MOTOR, MOTOR_DIR_BACKWARD);
delay(1000);
/* 360 spin right */
setMotorDirection(LEFT_MOTOR, MOTOR_DIR_FORWARD);
setMotorDirection(RIGHT_MOTOR, MOTOR_DIR_BACKWARD);
setMotorSpeed(BOTH_MOTORS,50);
delay(800);
setMotorSpeed(BOTH_MOTORS,10);
/* 360 spin left */
setMotorDirection(LEFT_MOTOR, MOTOR_DIR_BACKWARD);
setMotorDirection(RIGHT_MOTOR, MOTOR_DIR_FORWARD);
setMotorSpeed(BOTH_MOTORS,50);
delay(800);
setMotorSpeed(BOTH_MOTORS,10);
/* Left turn in place */
setMotorDirection(LEFT_MOTOR, MOTOR_DIR_BACKWARD);
setMotorDirection(RIGHT_MOTOR, MOTOR_DIR_FORWARD);
delay(500);
/* Right turn in place */
setMotorDirection(LEFT_MOTOR, MOTOR_DIR_FORWARD);
setMotorDirection(RIGHT_MOTOR, MOTOR_DIR_BACKWARD);
delay(1000);
/* Left turn in place */
setMotorDirection(LEFT_MOTOR, MOTOR_DIR_BACKWARD);
setMotorDirection(RIGHT_MOTOR, MOTOR_DIR_FORWARD);
delay(1000);
/* 360 spin right */
setMotorDirection(LEFT_MOTOR, MOTOR_DIR_FORWARD);
setMotorDirection(RIGHT_MOTOR, MOTOR_DIR_BACKWARD);
setMotorSpeed(BOTH_MOTORS,50);
delay(800);
setMotorSpeed(BOTH_MOTORS,10);
/* 360 spin left */
setMotorDirection(LEFT_MOTOR, MOTOR_DIR_BACKWARD);
setMotorDirection(RIGHT_MOTOR, MOTOR_DIR_FORWARD);
setMotorSpeed(BOTH_MOTORS,50);
delay(800);
setMotorSpeed(BOTH_MOTORS,10);
}
}
This code let's your robot spin around in place to show the simple motor control we have. You will probably need to modify it as the surface the robot is on can effect it's turn speeds. Don't get too hung up on this part as we will add remote control in the next lab. This just proves again that our motors do work and gives us a feel for the motor logic.
Does it navigate?
We will go ahead and test our robot out now with some sample code. Open up a new sketch by going to File > New. Paste in the sample code below and run it.
#include "Energia.h"
#include "SimpleRSLK.h"
/* Defines struct for state machine states */
typedef enum
{
START = 0,
WAIT,
GO,
GO2,
BUMPED1a,
BUMPED1b,
DRIVE,
STOP
} my_state_t;
/* Initialize state machine in START state */
my_state_t state = START;
/* Variable that will take the state machine to the STOP state */
bool done;
/* Initialize objects */
void setup() {
/* Set serial communication to 115200 baud rate for MSP432 */
Serial.begin(115200);
delay(500);
Serial.println("Initializing.....");
setupRSLK();
/* Initialize LED pins as outputs */
pinMode(LED_FR_PIN, OUTPUT);
pinMode(LED_FL_PIN, OUTPUT);
pinMode(LED_BR_PIN, OUTPUT);
pinMode(LED_BL_PIN, OUTPUT);
pinMode(LP_RED_LED_PIN, OUTPUT);
pinMode(LP_RGB_LED_RED_PIN, OUTPUT);
pinMode(LP_RGB_LED_BLUE_PIN, OUTPUT);
pinMode(LP_RGB_LED_GREEN_PIN, OUTPUT);
/* Initialize LaunchPad buttons as inputs */
pinMode(LP_S1_PIN, INPUT_PULLUP);
pinMode(LP_S2_PIN, INPUT_PULLUP);
Serial.println("Initializing System Complete.");
}
void loop() {
// Emergency stop switch S2
// Switch to state "STOP" if pressed
if (digitalRead(LP_S2_PIN) == 0) state = STOP;
//-----------------------------------
// Main State Machine
//-----------------------------------
switch (state) {
case START:
Serial.println("Enter START state");
state = WAIT;
break;
case WAIT:
Serial.println("Enter WAIT state");
digitalWrite(LP_RGB_LED_GREEN_PIN, HIGH);
delay(200);
digitalWrite(LP_RGB_LED_GREEN_PIN, LOW);
delay(200);
if (digitalRead(LP_S1_PIN) == 0) {
state = GO;
}
break;
case GO:
Serial.println("Enter GO state");
/* Start running the motors */
/* Enables specified motor.
* Parameter:
* Motor your referencing -> LEFT_MOTOR RIGHT_MOTOR BOTH_MOTORS
*/
enableMotor(BOTH_MOTORS);
setMotorDirection(BOTH_MOTORS, MOTOR_DIR_FORWARD);
setMotorSpeed(BOTH_MOTORS, 25);
state = GO2;
break;
case GO2:
Serial.println("Enter GO2 state");
/* Detect a bump and then switch to bump correction state */
for(int x = 0;x<6;x++)
{
if(isBumpSwitchPressed(x) == true) state = BUMPED1a;
}
/* Continue to rotate until done condition is met */
/* Certain distance traveled or other conditions can be set */
if (getEncoderLeftCnt() > 50000) {
done = 1;
}
if (done) state = STOP;
break;
case BUMPED1a:
Serial.println("Enter BUMPED1a state");
/* Stop the motors */
setMotorSpeed(BOTH_MOTORS,0);
/* Reverse the robot */
setMotorDirection(BOTH_MOTORS, MOTOR_DIR_BACKWARD);
setMotorSpeed(BOTH_MOTORS,25);
delay(500);
state = BUMPED1b;
break;
case BUMPED1b:
Serial.println("Enter BUMPED1b state");
/* Turn robot to avoid obstacle */
setMotorSpeed(LEFT_MOTOR,0);
setMotorSpeed(RIGHT_MOTOR,25);
delay(100);
state = DRIVE;
break;
case DRIVE:
Serial.println("Enter DRIVE state");
/* Put motors back to forward direction */
setMotorDirection(BOTH_MOTORS, MOTOR_DIR_FORWARD);
setMotorSpeed(BOTH_MOTORS, 25);
state = GO2;
break;
case STOP:
Serial.println("Enter STOP state");
Serial.println("Press Reset to begin again");
/* Stop all motors */
disableMotor(BOTH_MOTORS);
break;
}
delay(10);
}
This code will use a basic state machine to show the robot how to bump into walls and objects and avoid them.
Lab 5 - Wi-Fi + EnergiaHardware Required- TI-RSLK MAX
- CC3100 SimpleLink Wi-Fi BoosterPack
Wi-Fi
Now we can add Wi-Fi. The CC3100 is TI's Wi-Fi adapter for microcontrollers. It's very easy to interface with using SPI and can be used with both TI LaunchPads and Arduinos because they both support the same programming language (Wiring). Writing a sketch that uses the CC3100 is also very easy as the web examples for both LaunchPad and Arduino will both work on this platform. You can get this board here: http://www.ti.com/tool/cc3100boost
Testing Local Wi-Fi Server Energia Remote ControlFor the last part of the lab, we are going to use the Energia Wi-Fi remote example to show how to set up the LaunchPad as an access point and host websites directly on the microcontroller. For this part we don't need Wi-Fi access and can just use a local connection.
1. In Energia, import this example as a new project.
Note there are many other Wi-Fi examples in Energia, so be sure to check those out if you want to learn more. The Wi-Fi library is closely based on the Arduino Wi-Fi library APIs which makes it easy to interface with community software.
#include "SimpleRSLK.h"
#include "Wifi_Remote.h"
/*
* Robot Wifi Example
*
* This example will demonstrate controlling the remote via Wifi
* by Franklin S. Cooper Jr.
*/
String wifi_name = "rslk";
String wifi_password = "rslkwifi";
void setup()
{
Serial.begin(115200);
wifi_setup();
setupRSLK();
setMotorDirection(BOTH_MOTORS,MOTOR_DIR_FORWARD);
setMotorSpeed(BOTH_MOTORS,50);
}
void loop()
{
wifiLoop();
}
void custom_logic() {
if (left_button_pressed)
setMotorSpeed(RIGHT_MOTOR,70);
else
setMotorSpeed(RIGHT_MOTOR,50);
if (right_button_pressed)
setMotorSpeed(LEFT_MOTOR,70);
else
setMotorSpeed(LEFT_MOTOR,50);
if (up_down_pressed) {
enableMotor(BOTH_MOTORS);
if(up_button_pressed)
setMotorDirection(BOTH_MOTORS,MOTOR_DIR_FORWARD);
if(down_button_pressed)
setMotorDirection(BOTH_MOTORS,MOTOR_DIR_BACKWARD);
}
else
disableMotor(BOTH_MOTORS);
}
2. Change the name of your Robot's SSID to something unique if there are multiple robots nearby. This is the network you will connect to on your phone wi-fi after we program the robot and get ready to drive around.
In the wifiLoop() section is where we wait for a client to connect to the LaunchPad and then we serve up an HTML webpage.
3. Upload the code to the LaunchPad. When that is complete you can disconnect your LaunchPad robot from the PC.
4. Now unplug the LaunchPad from the USB cable and turn on the TI-RSLK MAX with the on/off switch. The LaunchPad green power LED and Chassis blue power LED should come on as well as the LEDs on the CC3100 BoosterPack. If the code is working properly it will start up in Access point mode with the name you picked and the Red LED on the LaunchPad should turn on when it is ready. When you see the Red LED, go to your phone or tablet or PC Wi-Fi and select that network with password "rslkwifi" unless you changed it in the code. When you are successfully connected, then you can go to a local page like 192.168.1.1 to access the web page with the arrows hosted on the robot's webserver. You may notice some slight lag in the beginning but this should go away. Press and hold the arrow to go back and forward and hold down left and forward to turn left and right and forward together to turn right and same for reverse.
5. Go ahead and do a one lap race around the room.
Challenge: Can you create custom features for your racer bot? You can use additional cloud services to add useful features. You can also add additional BoosterPacks to sense the environment or add other types of wireless connectivity.
ConclusionThat is a good sample of basic mechatronics prototyping with TI LaunchPad + Wi-Fi + Inputs & Outputs. We used off the shelf components and open source software to quickly build out and program a system. There is obviously a lot more to do with Blynk or other cloud services that are accessible through Energia libraries. There are also many hardware combinations to try when connecting things wirelessly. You can learn more about the TI LaunchPad ecosystem at www.ti.com/launchpad and explore the Energia website for more ideas and help. www.energia.nu/reference/wifi Continue your training at http://training.ti.com where there are videos for TI LaunchPad and software tools.
TI has a robust ecosystem for IoT. Learn more about cloud services and reference designs at www.ti.com/iot
Comments
Please log in or sign up to comment.