Wednesday, May 26, 2021

Scripting Part 1

Overview

Multiple things going on, but mostly been working on the scripting language.  I decided to put my head down and work through the issues.  I am finally at the 98% point.  There are still commands to implement and testing to be done, but it finally works.

Converting to 64 bit instructions was a complicated process.  In the original Brick Buddy, there were 4 motors and 4 LEDs.  This allowed for the state of these devices to be coded into one 32 bit command.  Thus on execution, the 4 motors and the LEDs could be updated in a single instruction.  The Brick Buddy 2 has PWM control for both the motors and the LEDs.  The PWM value is contained in an 8 bit value.  Thus for the 4 motors and 10 LEDs we need 112 bits. 

 

Script Structure

The command format needed to change.  The upper 20 bits are consistent throughout.  The upper 8 bits is the command.  Instead of 4 bits in the previous 32bit format, this provides more flexibility for commands.  The next 12 bits is the time stamp.  I considered expanding this, but 409.6 seconds (over 6 minutes) still seems adequate for any script.  I am sure someone will come up with a need for more, but for 99% of the users this will be adequate.  The remaining 44 bits are command dependent.  

The motor command fit nicely into 64 bits.  The lower 32 bits contain the PWM value for each motor.  The next 8 bits contain the motor state (OFF, FWD, RVS, BRAKE) for each motor.  The LED command got more complicated and was broken into three commands, LED 1-LED 4, LED 5-LED 8 and LED 9-LED 10.  Again the bottom 32 bits contain the PWM value and the next 12 bits contain the LED mode (OFF, STEADY, BURST, CYCLE, PULSE).  

The remaining commands for WAIT, INPUT and MP3 functions still need to be worked out, but these are simple compared to the complexity of the Motor and LED commands.

 

Implementation

The major problem in moving from PC/Mobile control to script control, was changing the underlying structure from a single device update to multiple devices simultaneously.  As pointed out earlier, the 32 bit structure with all the Motors and LEDs in one command was identical to what the PC/Mobile control was doing.  But in the 64 bit structure, many devices could be updated simultaneously with 4 commands or more being executed in the same time period.  Fortunately I had built most of the underlying functionality to handle this, but middle layer was geared toward the single control of the PC/Mobile interface.  This is now fixed, but it came at a price of some major reorganization.

 

 

No comments:

Post a Comment