Home STEM HQ TI-Nspire Authoring TI-Nspire Scripting HQ Scripting Tutorial - Lesson 47

           


Scripting Tutorial - Lesson 47: Lua Scripting and the TI Innovator™ Hub:

7. Build your own Innovator™ Hub Robot



Download supporting file for this tutorial

Texas Instruments TI-Nspire Scripting Support Page

       
  

Scripting for the Innovator Hub: Lesson 7: Build your own Innovator™ Hub Robot

Top of Page

As in the previous tutorial, we see two different ways to use the Innovator Hub for a "practical" purpose - this time, driving a home-made robot: using a Lua script, and also using TI-BASIC.

This robot vehicle is driven by two light servo motors. In order to limit the power demand, we will connect the voltage lead for both of these to the one 3.3V BB connection (I "piggy-backed" one onto the other). Using the more usual 5V BB9 port would require the other wheel to also use 5 volts, and together this is too much, so using 3.3 volts for each gives us a more reliable (if slightly slower) experience.

The best option (if not the simplest) is to run the servos from an external battery. Use either a 9 volt "transistor" (D-type) battery or a 4-pack battery case. Either way, you will have a positive (red) and a negative (ground, black) lead. Using a breadboard (or even part of a breadboard), connect the red (positive) lead on the same line as the red (voltage) leads from your servos. The black ground lead needs to be connected to a ground pin on your board, along with the black/ground leads from the servos, connected to other ground pins (I just used three ground BB pins). Connect the other (signal) leads from the servos to the appropriate pins on your board, and you now have a circuit which runs through your board but with no risk of frying it!

In addition to sending instructions to two attached servo motors to go forward, back, left and right, we also extend the activity to have the robot follow a bright light using the on-board brightness sensor, and auto-drive to avoid obstacles using an ultrasonic ranger (if you have one).

As with LaunchPad lesson 9 (in which we built a BLE robot using a bare MSP432 LaunchPad board and spare LEGO from my grandchildrens' toybox) we will supplement our main chassis - in this case, our TI Innovator™ Hub - with a few extra components:


  • Two servo motors - I used Feetech FS90R micro continuous rotation servo from eBay and paid around $AUD6 each (total around $USD10) - NOTE: NOT the identical-looking Feetech FS90 which will NOT work for our purposes!


  • Pololu wheel are designed specifically for the FeeTech FS90R servo motor.

  • You will also need a light-weight power source.

     

    I found a great 2500 mAh power bank on eBay for $AUD15! (around $USD10)

    The form factor is ideal for our robot -it sits perfectly on top of the Innovator.

  

 
    
  1. We add one new variable: drive.

    Our menu continues to grow with more examples.

  2.   
      

  3. No changes, other than adding values to the new variables.
  4.   
      

  5. Note the changes to mouseDown and mouseUp.

  6.   
      
  7. are defined here: individually for the four directions, and then the lightSeeker and autoDrive functions.

  8.   
      

  9. OneShotTimer is added to the Innovator functions, which are otherwise unchanged.

  
  

At this point, it is also instructive to compare the Lua functions we are defining to their TI-BASIC counterparts.

Define fd(t)=Prgm

Send "BEGIN " DelVar iostr.str0:GetStr iostr.str0:Disp iostr.str0
Disp "FORWARD"
Send "CONNECT SERVO 1 BB9 "
Send "CONNECT SERVO 2 BB10 "
Send "SET SERVO 1 CCW 100 "&" TIME "&string(t)
Send "SET SERVO 2 CW 100 "&" TIME "&string(t)
EndPrgm

Define bk(t)=Prgm

Send "BEGIN " DelVar iostr.str0:GetStr iostr.str0:Disp iostr.str0
Send "CONNECT SERVO 1 BB9 "
Send "CONNECT SERVO 2 BB10 "
Send "SET SERVO 1 CW 100 "&" TIME "&string(t)
Send "SET SERVO 2 CCW 100 "&" TIME "&string(t)
EndPrgm

Define lt(t)=Prgm

Send "BEGIN " DelVar iostr.str0:GetStr iostr.str0:Disp iostr.str0
Send "CONNECT SERVO 1 BB9 "
Send "CONNECT SERVO 2 BB10 "
Send "SET SERVO 1 CW 100 "&" TIME "&string(t)
Send "SET SERVO 2 CW 100 "&" TIME "&string(t)
EndPrgm

Define rt(t)=Prgm

Send "BEGIN " DelVar iostr.str0:GetStr iostr.str0:Disp iostr.str0
Send "CONNECT SERVO 1 BB9 "
Send "CONNECT SERVO 2 BB10 "
Send "SET SERVO 1 CCW 100 "&" TIME "&string(t)
Send "SET SERVO 2 CCW 100 "&" TIME "&string(t)
EndPrgm

Define lightseeker(m,x)=Prgm

Send "BEGIN " DelVar iostr.str0:GetStr iostr.str0:Disp iostr.str0
Local b
b:=0
Send "CONNECT SERVO 1 BB9 "
Send "CONNECT SERVO 2 BB10 "
Send "READ BRIGHTNESS "
Get b
Disp "Brightness "&string(b)
Send "SET SOUND eval(b*100) 0.1"
While b>m
Send "READ BRIGHTNESS "
Get b
Disp "Brightness "&string(b)
Send "SET SOUND eval(b*100) 0.5"
If b>x Then
Disp "FORWARD"
Send "SET SERVO 1 CCW 100 TIME 1 "
Send "SET SERVO 2 CW 100 TIME 1 "
Wait 1
Else
Disp "BACK"
Send "SET SERVO 1 CW 100 TIME 0.5 "
Send "SET SERVO 2 CCW 100 TIME 0.5 "
Wait 0.5
Disp "RIGHT"
Send "SET SERVO 1 CCW 100 TIME 0.5 "
Send "SET SERVO 2 CCW 100 TIME 0.5 "
Wait 0.5
EndIf
EndWhile
EndPrgm

Define auto()=Prgm

Send "BEGIN " DelVar iostr.str0:GetStr iostr.str0:Disp iostr.str0
Local d
d:=0
Send "CONNECT RANGER 1 IN1 "
Send "CONNECT SERVO 1 BB9 "
Send "CONNECT SERVO 2 BB10 "
Send "READ RANGER 1 "
Get d
Disp "Distance "&string(d*10)&" cm"
Send "SET SOUND eval(d*1000) 0.1"
While d>0.15
Send "READ RANGER 1 "
Get d
Disp "Distance "&string(d*10)&" cm"
Send "SET SOUND eval(d*1000) 0.5"
If d>0.3 Then
Disp "FORWARD"
Send "SET SERVO 1 CCW 100 TIME 1 "
Send "SET SERVO 2 CW 100 TIME 1 "
Wait 1
Else
Disp "BACK"
Send "SET SERVO 1 CW 100 TIME 0.5 "
Send "SET SERVO 2 CCW 100 TIME 0.5 "
Wait 0.5
Disp "RIGHT"
Send "SET SERVO 1 CCW 100 TIME 0.5 "
Send "SET SERVO 2 CCW 100 TIME 0.5 "
Wait 0.5
EndIf
EndWhile
EndPrgm

  
 
 

 
 

In our next lesson, we take these principles and create a more versatile document, which accepts user input into a text field, allowing you to try out variations, and to create your own Innovator hub commands.


  

Back to Top

  

Home STEM HQ TI-Nspire Authoring TI-Nspire Scripting HQ Scripting Tutorial - Lesson 47