Wednesday, February 15, 2012

Feb.15 Adaptors explained well

Today adaptors were explained to me and a real example with a mechanical BotBall Lego arm shown. Maybe oversimplified, but in summary:


Adaptors are like:
Interfaces because they are used within other FBs
Connectors because they can be used on the input or mirrored on the output of a FB 


Their example opened questions about whether the LMS FB interfaces are really 1499 enough?

  • When should REQ and data inputs be used to set state like dir(ection).
  • When should an event like FWD / BK be used to set the direction state internally.
  • In part when the event will cause a state change.
  • Is it 1499 like enough, if the Event Control Chart has to look at the event && data for transition?

The LMS FBs are SIFBs so no ECCs, but light calibration and line follower application could be.

Sunday, February 12, 2012

Feb.8 Smaller Stacksize

When the LMS regression test didn't have enough space, the Dec.30 Stacksize information was useful.
The eCos stack was reduced from 4098(=800 in hex) to 1536(=600 in hex).
Using the Dec.30 Stacksize info. that's space for :
the 29 minimum eCos variables + 19 more INT spaces.


The avr_ctl thread stacksize was reduced from 2048 to 1312:
the 29 minimum eCos variables + 12 more INT spaces.


The LMS regression test now works with touch sensor, 3 leds, a motor, 1 button test, and 3 buttons pressed in same test case.


Patches submitted

Tuesday, January 31, 2012

Feb. 2 LMS in 4diac hg + Tutorials

LMS FBs (forte C++ and FBs xml)) was pushed into the Fordiac mecurial hg for the upcoming 1.1 release. 
Function Blocks: 
Sensors: LC_LED, LC_LT, LC_TOUCH, LC_SOUND, LC_AD, 
     Other: L_M_PWR, L_BATTERY, L_BUTTON, L_OFF
    Utilitiy: FBs L_AD, L_LED, L_S_PORT  as well as L_avrctl 


Tutorials: See  fordiac dev wiki 4DIAC Framework tutorials 
Currently text and soon videos
1. Supplied system - updated so the Publish/Subscribes are in the resource
2. Flip-flop (on PC) - tutorial covers the IDE interface using different ways to implement the same application.
3. Flip-flop (on LMS) - a first application with Lego NXT Brick, Sensors and motors


Soon under LMS tutorials ...
4. LMS Line Follower.  The tutorial text will be used as a script for a video version of the tutorials.


Of course further FBs for more LMS HW is under development.

Friday, December 30, 2011

Dec.30 Stacksize

This post documents information from studying stacksizes, because the choice of the AVR thread stacksize (2048) was not clear.  
Summary:
used AVR stacksize =2048 is:
    min  < avr < typical 
  1120 < 2048 < 2400
So 2048 is probably ok.  
2048/size(int) = 2048/32 = 75 int variables would be allowed.
Since minimum is 1120, then 2048-1120=928 ==>  928/32= 29 automatic variables could be used by receiveThread function.  

.
Background: AVR control code was written in C. Updating it from C to C++, it  needed the most care due to its direct HW communication between the ARM and AVR.  There may still be improvements, but changes need to be made carefully to not break working code.
.
Studying the code during the code review update.
1. Why the stack size of 2048 was chosen?
Answer: Value used in sample code in eCos Book:: Embedded SW Dev  with eCos p.111 Code Listing 6.1: Thread Initialization Example 
.
2. Is it really the best stacksize for the avr communication thread?
Still unknown, but the min stacksize and typical stacksize suggested via the eCos include comments and other references are:
.
p.117 ecos reference explains the constants used for CYGNUM_HAL_STACK_SIZE_MINIMUM and CYGNUM_HAL_STACK_SIZE_TYPICAL stacksizes and were found in  hal_arch.h. The caclulated values are:

CYGNUM_HAL_STACK_FRAME_SIZE = (4 * 20) = 80
.
CYGNUM_HAL_STACK_INTERRUPT_SIZE=
((4 * 20) + 2 * CYGNUM_HAL_STACK_FRAME_SIZE) =
((4 * 20) + 2 * (4*20) = 240
.
CYGNUM_HAL_MAX_INTERRUPT_NESTING = 4
.
CYGNUM_HAL_STACK_SIZE_MINIMUM =
        (CYGNUM_HAL_MAX_INTERRUPT_NESTING * CYGNUM_HAL_STACK_INTERRUPT_SIZE 
         4     *     240
         + 2 * CYGNUM_HAL_STACK_FRAME_SIZE) + 2 * 80
         = 4* 240 + 2*80 = 1120
.
CYGNUM_HAL_STACK_SIZE_TYPICAL = (CYGNUM_HAL_STACK_SIZE_MINIMUM 
         + 16 * CYGNUM_HAL_STACK_FRAME_SIZE)
= 1120 +16*(4*20) =2400
.
Info from comments;
// ...Idle thread stack should be this big.
.
//    THESE ARE NOT INTENDED TO BE MICROMETRICALLY ACCURATE FIGURES.
//           THEY ARE HOWEVER ENOUGH TO START PROGRAMMING.
// YOU MUST MAKE YOUR STACKS LARGER IF YOU HAVE LARGE "AUTO" VARIABLES!
.
// This is not a config option because it should not be adjusted except
// under "enough rope" sort of disclaimers.
.
This leads to the Summary at the top of this post.

Thursday, December 29, 2011

Dec.29 + Jan. 6.AVR Firmware version FB

For complete access to all information in the Battery word, a Function Block to access AVR firmware major and minor version has been created. It will not be automatically compiled by LMS cmake, but commented out by default.
Curious what versions of the AVR firmware version of various LMS will be. (will post test here)


Jan. 6 AVR firmware version # is all zeros.
Jan. 23 AVR FB abandoned because we do not need the information and it would never be used.

Monday, December 26, 2011

Dec.26 Battery FB start

Lego original Battery info documentation:
Battery info is part of the data recieved from the AVR as explained on  p.20 in  Lego Mindstorms NXT (TM)  Hardware Developers Kit 
Battery word contains the 
  • voltage (mV) = bits 0-9 * 13.848
    • not supporting float so multiply by 1024 * 13.848=  14180 then divide by 1024
    • alternative: would be to just use relative power of 0-1023
  • accu pack inserted bit (bool)  bit 15
    • The accu pack has peg-like tab that pushes battery setting, when its inserted.
  • avr firmware major.minor version (xx.yyy) bits 13-14 major; bits 10-12 minor
    • AVR firmware version will be given its own FB if its ever needed.
    Interesting lms Battery links:
    Battery discussion in thenxtstep blog
    Interesting study of NXT battery power levels: