Question on Code
 
Share:
Notifications
Clear all

Question on Code  

  RSS

dab7c46ccfa5db3c7a17d45205488877?s=80&d=mm&r=g
(@john-marcolina)
Active Member Customer
Joined: 11 months ago
Posts: 13
29/01/2020 5:56 am  

I’ve been studying the B-Robot code in order to make some changes for something I’m working on, but I see something strange that I don’t understand. In the main loop part of the code, the variable “throttle” is assigned a value based on the OSCfader[0] variable, which is a “float”, and equal to a value in the range 0-1.0.
The line in question is:
throttle = (OSCfader[0] – 0.5) * max_throttle;

The subtraction of 0.5 changes the range of the input to be -0.5 to +0.5. Then multiplying by max_throttle gives a larger positive or negative number.

The problem? The variable “throttle” is an *unsigned* int (uint16_t). So what is going on here? Can anyone explain how this works? Clearly it does, I just don’t see how.


Quote
JoseJulio
(@josejulio)
Eminent Member Admin
Joined: 6 years ago
Posts: 29
29/01/2020 12:36 pm  

Hi,
The throttle variable is defined as signed int16, this is the line:
int16_t throttle;
(line 159 of BROBOT_EVO2… M0.ino file. Link from assembly guide)
Maybe you are testing a different code?

Jose.

I’ve been studying the B-Robot code in order to make some changes for something I’m working on, but I see something strange that I don’t understand. In the main loop part of the code, the variable “throttle” is assigned a value based on the OSCfader[0] variable, which is a “float”, and equal to a value in the range 0-1.0.
The line in question is:
throttle = (OSCfader[0] – 0.5) * max_throttle;

The subtraction of 0.5 changes the range of the input to be -0.5 to +0.5. Then multiplying by max_throttle gives a larger positive or negative number.

The problem? The variable “throttle” is an *unsigned* int (uint16_t). So what is going on here? Can anyone explain how this works? Clearly it does, I just don’t see how.


ReplyQuote
350a26dd49eb55d3494500240423a207?s=80&d=mm&r=g
(@robotn1)
Honorable Member Admin
Joined: 5 years ago
Posts: 688
29/01/2020 2:29 pm  

I’ve been studying the B-Robot code in order to make some changes for something I’m working on, but I see something strange that I don’t understand. In the main loop part of the code, the variable “throttle” is assigned a value based on the OSCfader[0] variable, which is a “float”, and equal to a value in the range 0-1.0.
The line in question is:
throttle = (OSCfader[0] – 0.5) * max_throttle;

The subtraction of 0.5 changes the range of the input to be -0.5 to +0.5. Then multiplying by max_throttle gives a larger positive or negative number.

The problem? The variable “throttle” is an *unsigned* int (uint16_t). So what is going on here? Can anyone explain how this works? Clearly it does, I just don’t see how.

Are you using the code for the DEVIA board or Arduino Leonardo?


ReplyQuote
dab7c46ccfa5db3c7a17d45205488877?s=80&d=mm&r=g
(@john-marcolina)
Active Member Customer
Joined: 11 months ago
Posts: 13
29/01/2020 3:38 pm  

Oh brother,
You are right – I misread this. I was looking at this on a small screen, it was late, and it was the first time I had encountered this type of variable declaration (I had to look it up). Sorry for the confusion (mine) about this. And thanks, Jose, for straightening me out. All looks good now – moving forward!

Hi,
The throttle variable is defined as signed int16, this is the line:
int16_t throttle;
(line 159 of BROBOT_EVO2… M0.ino file. Link from assembly guide)
Maybe you are testing a different code?

Jose.

I’ve been studying the B-Robot code in order to make some changes for something I’m working on, but I see something strange that I don’t understand. In the main loop part of the code, the variable “throttle” is assigned a value based on the OSCfader[0] variable, which is a “float”, and equal to a value in the range 0-1.0.
The line in question is:
throttle = (OSCfader[0] – 0.5) * max_throttle;

The subtraction of 0.5 changes the range of the input to be -0.5 to +0.5. Then multiplying by max_throttle gives a larger positive or negative number.

The problem? The variable “throttle” is an *unsigned* int (uint16_t). So what is going on here? Can anyone explain how this works? Clearly it does, I just don’t see how.


ReplyQuote
5de5d80571e5d2eca670c2c47771f34a?s=80&d=mm&r=g
(@mathew)
New Member
Joined: 2 months ago
Posts: 1
18/10/2020 4:06 pm  

When I try to upload the code it comes up with an error message for multiple lines of code that it hasn’t been defined. Thanks


ReplyQuote
350a26dd49eb55d3494500240423a207?s=80&d=mm&r=g
(@robotn1)
Honorable Member Admin
Joined: 5 years ago
Posts: 688
20/10/2020 10:44 pm  

When I try to upload the code it comes up with an error message for multiple lines of code that it hasn’t been defined. Thanks

What errors?


ReplyQuote
Share: