Probably I should say Yet Another NXT Wrapper. The idea around this one was my strict need of having something with minimal dependency and clutter. Most Bluetooth adapters and stacks have different kind of limitations I found hard to cope, but once one managed to have his adapter connected to NXT and expose that connection as serial port, we can access the NXT with only minimal programming.
I often use python as prototyping language, but sadly lacks native serial port handling support. However there are third party modules to do this, and pyserial is doing a pretty good job, also compatible with multiple platforms and python 3.x line.
Today I just want to share this wrapper with the possible users, there is no documentation yet but once there are other people interested in using it, I can spend more time and create some sort of tutorial.
I use this wrapper to command the NXT unit this is where some of my conversion blocks come handy. I am looking forward to receive feedback on this.
GSA Technical Playground
Tuesday, March 13, 2012
Thursday, March 1, 2012
NXT Blocks - Conversion Utils - String To Float (GSAString2Float)
In my last post I presented a way of serializing one or multiple numbers to string GSAFloat2String. As may you already expected I will provide you today with the counter part or mirror function block GSAString2Float.
This block provide us with the possibility to deserialize a string or a portion of a string (previously serialized by GSAFloat2String or any other means to have the IEEE 754 format contained in the string) to a floating point number.
In case of strings containing multiple numbers we can de-serialize all one by one providing the offset for each number within the string. Remember each value is encoded on 4 bytes (IEEE 754).
You can download GSAString2Float here.
This block provide us with the possibility to deserialize a string or a portion of a string (previously serialized by GSAFloat2String or any other means to have the IEEE 754 format contained in the string) to a floating point number.
Inputs: 1. Input String - any string containing IEEE 754 blocks 2. Value Offset - the offset of the IEEE 754 block within the Input String. 3. Default Value - the value provided in case of conversion errors Outputs: 1. Output value - a single point precision floating number
In case of strings containing multiple numbers we can de-serialize all one by one providing the offset for each number within the string. Remember each value is encoded on 4 bytes (IEEE 754).
You can download GSAString2Float here.
Labels:
Conversion Utils,
NXT,
NXT Blocks,
string2float,
stringtofloat,
text2number
Wednesday, February 29, 2012
NXT Blocks - Conversion Utils - Float To String (GSAFloat2String)
One of the challenges of NXT programming is to be able to quickly move data between different NXT units, or NXT-PC. Most usually we need to move numbers, for example sensor data, measurements, command parameters, etc.
We can already move numbers one by one with the Bluetooth Send and Receive, but is quite inefficient. First we can move only one number, true/false (boolean) value or one string at time. Combine this with the slowish Bluetooth ping-pong, moving sightly bigger number of data can be a problem.
Now wait! The string can have up to 50 characters... if we are able to serialize and un-serialize numbers to string then we most probably can have more than a number in one Bluetooth packet!
In my last post I presented a way to de serialize Integer numbers from string (GSAText2Int), an inverse function fro the NXT Number To String block. However pairing the original block with my GSAText2Int has some pretty serious limitations like: being limited to integers, the size of the resulting text is not optimal and maybe the most unpleasant thing is the fact that each number can have a different size.
The solution is to have some fixed size serialization-deserialization blocks with a compact format. Single precision floating point numbers are representable on 4 bytes (IEEE 754) or 4 characters of space.
So first I will present a way to serialize a floating point number to a 4 bytes string with GSAFloat2String NXT block.
We can concatenate (using NXT Text block) up to 12 serialized floating point number in one string (48bytes) that fits a Bluetooth message!
You can download GSAFloat2String here.
We can already move numbers one by one with the Bluetooth Send and Receive, but is quite inefficient. First we can move only one number, true/false (boolean) value or one string at time. Combine this with the slowish Bluetooth ping-pong, moving sightly bigger number of data can be a problem.
Now wait! The string can have up to 50 characters... if we are able to serialize and un-serialize numbers to string then we most probably can have more than a number in one Bluetooth packet!
In my last post I presented a way to de serialize Integer numbers from string (GSAText2Int), an inverse function fro the NXT Number To String block. However pairing the original block with my GSAText2Int has some pretty serious limitations like: being limited to integers, the size of the resulting text is not optimal and maybe the most unpleasant thing is the fact that each number can have a different size.
The solution is to have some fixed size serialization-deserialization blocks with a compact format. Single precision floating point numbers are representable on 4 bytes (IEEE 754) or 4 characters of space.
So first I will present a way to serialize a floating point number to a 4 bytes string with GSAFloat2String NXT block.
Inputs: 1. Float Number - actually can be any numeric value Outputs: 1. Output String - a 4 bytes string
We can concatenate (using NXT Text block) up to 12 serialized floating point number in one string (48bytes) that fits a Bluetooth message!
You can download GSAFloat2String here.
Labels:
Conversion Utils,
float2string,
floattostring,
NXT,
NXT Blocks,
serialize
Monday, February 27, 2012
NXT Blocks - Conversion Utils - Text to Int (GSAText2Int)
Now that we have means of manipulating strings (splitting, concatenating, etc.) I started to think on ways of expanding the usage of strings. One usage is for storage and transport of other type of data. So next come to mind is to build ways to serialize and un-serialize different kind of data.
We already have means to serialize numbers within the NXT software: the Number To Text Building Block. So I decided the inverse of this Block is needed: Text To Int (GSAText2Int).
Practically this Block is capable to convert a a string containing a number in decimal notation to an integer, given the string and the starting offset of the number. The end of the number is marked by the first non numeric character.
Notice this Block converts integers so the '.' (decimal point) is treated as non numeric.
You can download GSAText2Int here.
We already have means to serialize numbers within the NXT software: the Number To Text Building Block. So I decided the inverse of this Block is needed: Text To Int (GSAText2Int).
Practically this Block is capable to convert a a string containing a number in decimal notation to an integer, given the string and the starting offset of the number. The end of the number is marked by the first non numeric character.
Inputs: 1. Input String 2. Offset 3. Default (in case conversion fails this number will be presented at the output) Outputs: 1. Output Value 2. New Offset (this is the point where our number ends) Example: Input String = "12345", Offset = 0 => Number = 12345, New Offset = 5 Input String = "12345.678", Offset = 0 => Number = 12345, New Offset =5 Input String = "12345.678", Offset = 3 => Number = 45, New Offset = 5
Notice this Block converts integers so the '.' (decimal point) is treated as non numeric.
You can download GSAText2Int here.
Labels:
Conversion Utils,
Lego,
Mindstorms,
NXT,
NXT Blocks,
text2int,
text2number,
textoint,
texttonumber
NXT Blocks - String Utils - String Splitting (GSAStringSplit)
Today I want to present another block from the String manipulation family, named GSAStringSplit.
This block will allow us to split a string (text) in two substrings.
Example usage:
the Output String 1 = "ab" and Output String 2 = "cde".
You can download GSAStringSplit here.
This block will allow us to split a string (text) in two substrings.
Inputs: 1. Input String - the source string 2. Split Point Index - the start position of the second string Outputs: 1. Output String 1 2. Output String 2
Example usage:
the Output String 1 = "ab" and Output String 2 = "cde".
You can download GSAStringSplit here.
Labels:
Lego,
Mindstorms,
NXT,
NXT Blocks,
Split String,
String manipulation
NXT Blocks - String utils - Sub String (GSASubString)
I must confess, I am pretty new with both LEGO and Mindstorms. In searching for a platform to build some of my robot tests I opted for this ingenious kit named LEGO MINDSTORMS® NXT 2.0 [8547].
While trying to write my programs on the LEGO's visual platform I suddenly fall in need of more sophisticated Building Blocks. After a few days of trial and error I found a way to create such of blocks. But there is no joy without sharing no? :)
The first block to share is the GSASubString block from the String manipulation family. This block practically allows us to extract a substring from another string (text).
Example usage:
The example returns "bc".
You can download the GSASubString here.
While trying to write my programs on the LEGO's visual platform I suddenly fall in need of more sophisticated Building Blocks. After a few days of trial and error I found a way to create such of blocks. But there is no joy without sharing no? :)
The first block to share is the GSASubString block from the String manipulation family. This block practically allows us to extract a substring from another string (text).
Inputs: 1. Input String - the source string 2. Offset - the start position of the substring 3. Length - the substring length Outputs: 1. Substring - the resulting substring
Example usage:
The example returns "bc".
You can download the GSASubString here.
Labels:
Lego,
Mindstorms,
NXT,
NXT Blocks,
String manipulation
Subscribe to:
Posts (Atom)


