thecause17
Newbie
I'm not sure if the title of the thread makes a lot of sense, so let me explain what I'm trying to do. Currently I'm reading sensors from the phone and displaying them on the app. I will also be sending these values over a network later. I'm looking at the phone's orientation, but I only care about two of the axes.
I've converted one to degrees and it can stay that way. The other one, I want to use as a speed demand and want to display and transmit it as a percentage of a range which I have predetermined. This range also has constraints where certain angle ranges need to provide zero demand. For example, from 45 degrees to 20 degrees, demand will range from 0-100%, but from 45-80 degrees needs to stay 0. There are other ranges as well. I don't know how to make this happen in code. I can see using a "if" and "else if" statements to break up the blocks, and then specifying in each statement what I need, but inside of those I don't know how to assign a percentage value to a degree value for a range like this. Here's the section of code that pertains to this that I've come up with so far. The if and first else if statement are where I'm not sure what to do. Thanks.
I've converted one to degrees and it can stay that way. The other one, I want to use as a speed demand and want to display and transmit it as a percentage of a range which I have predetermined. This range also has constraints where certain angle ranges need to provide zero demand. For example, from 45 degrees to 20 degrees, demand will range from 0-100%, but from 45-80 degrees needs to stay 0. There are other ranges as well. I don't know how to make this happen in code. I can see using a "if" and "else if" statements to break up the blocks, and then specifying in each statement what I need, but inside of those I don't know how to assign a percentage value to a degree value for a range like this. Here's the section of code that pertains to this that I've come up with so far. The if and first else if statement are where I'm not sure what to do. Thanks.
Code:
//Change from radians to degrees, inverting throttle
double steering = mValuesOrientation[1] * (180/Math.PI);
double throttle = mValuesOrientation[2] * (-180/Math.PI);
//Formatting to one decimal place
DecimalFormat precision = new DecimalFormat("0.0");
final CharSequence steerpos;
final CharSequence speeddemand;
double speedpercent = 0;
//Specify throttle response
if(throttle <= 45 && throttle >= 20) {
//Range speedpercent from 1% to 100 %
}
else if(throttle >= 80 && throttle <= 120) {
//Range speedpercent from -1% to -50%
}
else {
speedpercent = 0;
}
//Send to text boxes
steerpos = "Steering: " + precision.format(steering);
txt1.setText(steerpos);
speeddemand = "Throttle: " + precision.format(speedpercent);
txt2.setText(speeddemand);