View unanswered posts | View active topics It is currently Fri Nov 22, 2019 6:16 am






Reply to topic  [ 4 posts ] 
RobotC question with datatypes 
Author Message
Rookie

Joined: Fri Jan 09, 2015 4:05 pm
Posts: 6
Post RobotC question with datatypes
Good afternoon!

Quick question before I try to assist my kids more with robotc.

If I try to do different varying levels of power (say a gain multiplied by joystick value) and it changes based on what button was pressed, I seem to be overflowing the gain to a large number.

The motor power if I recall goes from -128 -> 127

Any overflow should result in 127, so a saturated gain of big number * joystick value will pretty much have the robot driving at full throttle even with your finger barely lifting the joystick.

How would somebody do the math of motor[mymotor]=joyval*gain and have it be tunable (say a gain of .25,.5,.75 and 1) and have it work? Thanks!


Fri Jan 09, 2015 4:12 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: RobotC question with datatypes
Are you talking about the NXT Mindstorms platform? If so, the motor value range is -100 to 100 not -128 to 127. However, the joystick range is -128 to 127. You can assign a motor value greater than 100 (or smaller than -100) but it will be clipped at absolute value of 100. So usually that doesn't matter. People do direct assignment of the joystick value to the motors even though the joystick value has a wider range that the motor range. Having said that, it means when the absolute value of the joystick exceeds 100, the motor can't go any faster (i.e. saturation). If you want to avoid saturation, then you need to scale the range -128 to 127 to -100 to 100. Similarly, if you want to use a multiplier and also trying to avoid saturation, you need to determine the max range of the resulting multiplier and scale the range back to -100 to 100.


Fri Jan 09, 2015 5:55 pm
Profile
Rookie

Joined: Fri Jan 09, 2015 4:05 pm
Posts: 6
Post Re: RobotC question with datatypes
If I have a gain of .25 and take the joystick value, aren't I limiting it to 100*.25 = 25 so it should be slower than normal? Doesn't seem to be responding that way.


Fri Jan 09, 2015 7:03 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: RobotC question with datatypes
RoboRams wrote:
If I have a gain of .25 and take the joystick value, aren't I limiting it to 100*.25 = 25 so it should be slower than normal? Doesn't seem to be responding that way.

Yes, it should be but be mindful the difference between integer and floating point arithmetic. Since I don't see your code, I can't tell you why it doesn't work for you. What symptoms did you have?


Sat Jan 10, 2015 4:42 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.