The decimal output string

How to define the output string in decimal format

Output string in decimal format

In the output string you define the sequence of bytes sent through the output.

The decimal format sends a string composed of chars. Each char corresponds to a byte value. Bellow you have the ASCII chart, relating each char to it's decimal value (and others).

ASCII Chart from

Usually, the decimal format requires more bytes compared to the binary, but it's simpler to use and easier to read.

If you use a shared memory or UDP output, you get a packet and the bytes order is kept intact and easy to analyze. In UDP, just check the size of the packet, if it's wrong, something is lost.

First, let's look at how the string is interpreted in decimal format and how it converts to a byte array.

Add an output to test the results of a string. You can debug the generated bytes for the string you type in the lower area of the output.

Decimal format string: <123>

Outputs a byte with value 123

If we look at the ASCII chart, we could have used the char {, but this easier to read althought, for Mover it's faster to convert the char.

In decimal, the number inside the <> is converted to a char. But the keywords (see bellow) are converted to multiple chars to generate a string of the value.

The idea, is to allow to use chars that can't be writen with the keyboard like NULL or DEL.

Look at the ASCII table and you can see many chars unreachable unless you use this method. Also notice that the maximum value is 127.

Decimal format string: <<1234>

This gives you an error in decimal.

There's no char with value 1234.


Binary format string: <1234>

This gives you an error in decimal.

There's no char with value 1234.

Decimal format string: AB<123>

You can output chars values. Each char is assigned a byte value.

A as the byte value 65

B as the byte value 66

So the output from above is 3 bytes: 65, 66 and 123.

The chars < and > can't be used, they are reserved for numeric values and actuators keywords.

Decimal format string: 123<123>

ATTENTION!

123 is not the same as <123> in binary format.

<123> is a byte with value 123, while the 123 is 3 chars where:

1 as the byte value of 49

2 as the byte value of 50

3 as the byte value of 51

Decimal format string: A<Axis1a>B<Wind>

In this string, A and B are chars with the values:

A as the byte value 65

B as the byte value 66

Inside the <> we have two keywords. They identify the actuators and they are replaced with the actuators values.

The number of bytes used for each actuator depend on the number of chars used by each value.

So for a number like 9845, we need 4 chars. For the number 34, we need two chars.

The <Wind> actuator as a value of zero, so the output is one byte with the dcimal value of ASCII 0. That's byte 48.

The <Axis1a> is the first actuator of the hexapod and is outputing a value of 511. It needs 3 bytes since it uses 3 chars. They are bytes 53, 49 and 49.

Here is the main difference to the binary output. It's the way the keywords are converted to the byte array.

Actuators keys and number of bits in a rig module.

Actuator key and number of bits in a direct module.

Binary format string: <<<<Wind>

Unlike the numeric values inside the <>, the actuators are defined for a specific number of bits/bytes, so using multiple < is ignored by Mover.

Here the actuator as a value of zero, and uses 10 bits, so it's outputing two bytes with value zero.

If you use an unknow key, everything inside <> is ignored.

Example 1 - Arduino Uno controlling one fan

We have an Arduino controling a fan to simulate wind.

The Arduino needs to receive the speed from Mover and it accepts an 8 bit / 1 byte value.

That's a value between 0 and 255.

So in Mover, add a direct to generate that wind value and set the bit output to 8 bits.

In the serial output put the string, select the port of the Arduino and set the speed of the serial communication.

Notice that I added a marker with the char W.

This is beacuse I need to know in the stream of bytes, when we get a new value.
The idea is that I get a stream of chars. When I get a W I know the other values I received are numbers and they compose the value.

Look at the Arduino code bellow doing this:

// Pin that controls the motor controller speed

int analogSpeedPin = 3;

// Buffer to store the received chars/bytes

String receivedChars = "";


void setup() {

// Start serial communication

Serial.begin(115200, SERIAL_8N1);

// Set pin as output

pinMode(analogSpeedPin, OUTPUT);

}


void loop() {

if (Serial.available())

{

// Get the char

char receivedChar = Serial.read();


// Test for W

if (receivedChar == 'W' && receivedChars.length()>0)

{

// If we got W, and the string we have

// is bigger than 0, get the value from the string

int fanSpeed = receivedChars.toInt();

// Set the pin value

analogWrite(analogSpeedPin, fanSpeed);

// Clear the received chars

receivedChars = "";

}


// If char is a number, add it to the string

else if (isDigit(receivedChar)) receivedChars += receivedChar;


// If we got anything else, clear the received chars

else receivedChars = "";

}

}

We are using speed of veichle to generate the wind and speed comes in m/s.

The way the direct is setup, you get 0 for 0 m/s and 255 for 100 m/s or 360 km/h in the bit output.

We are just mapping the values this way in the example. You can chage this to your preferences or type of vehicle.

Notice that in some sources we have the wind value that takes into account the canopy when availlable.

You can try the slider to see the values changing. All values under 0 or above 100 are cropped. Here the important

Example 2 - Arduino Uno controlling two fans with different speeds

We have an Arduino Uno controling two fans to simulate wind speed.

The Arduino needs to receive the speeds from Mover and it accepts an 8 bit / 1 byte value.

That's a value between 0 and 255.

The idea is to change speeds of the fans depending on vehicle speed and yaw speed.

Yaw speed introduces a difference of speed in the fans.

So in Mover, add two multi directs to generate the wind value and set the bit outputs to 8 bits.

By default speed value is selected. Add the yaw speed value also on the multi direct.

Invert the gain in one of them to work on the opposite way. While one fan increases speed the other one decreases.

Remember to change the keyword of the actuators. They must be different. I used <LWind> and <RWind>.

In the serial output put the string like we have in the figure, select the port of the Arduino and set the speed of the serial communication.

Carefully look at the Arduino code to understand how we get the markes and the values.

// Pins that controls the motors controllers speed

int analogLeftSpeedPin = 3;

int analogRightSpeedPin = 5;

// Buffer to store the received chars/bytes

String receivedChars = "";


void setup() {

// Start serial communication

Serial.begin(115200, SERIAL_8N1);

// Set pins as output

pinMode(analogLeftSpeedPin, OUTPUT);

pinMode(analogRightSpeedPin, OUTPUT);

}


void loop() {

if (Serial.available())

{

// Get the byte with the speed value

char receivedChar = Serial.read();


// Test for L

if (receivedChar == 'L' && receivedChars.length()>0)

{

analogWrite(analogLeftSpeedPin, receivedChars.toInt());

receivedChars = "";

}

// Test for R

else if (receivedChar == 'R' && receivedChars.length()>0)

{

analogWrite(analogRightSpeedPin, receivedChars.toInt());

receivedChars = "";

}

// If char is a number, add it to the string

else if (isDigit(receivedChar)) receivedChars += receivedChar;


// If we got anything else, clear the received chars

else receivedChars = "";

}

}

The above code allows you to add as many values and markers as you want.

It's not 100% fail proof, you might loose some digits, or a tehe start you mighr get an incomplete value, missing the begining digits (we could test if it's the first value and ignore it).