ROBOTC.net forumshttp://robotc.net/forums/ RobotC question with datatypeshttp://robotc.net/forums/viewtopic.php?f=52&t=10218 Page 1 of 1

 Author: RoboRams [ Fri Jan 09, 2015 4:12 pm ] Post subject: 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 -> 127Any 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!

 Author: MHTS [ Fri Jan 09, 2015 5:55 pm ] Post subject: 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.

 Author: RoboRams [ Fri Jan 09, 2015 7:03 pm ] Post subject: 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.

Author:  MHTS [ Sat Jan 10, 2015 4:42 am ]
Post subject:  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?

 Page 1 of 1 All times are UTC - 5 hours [ DST ] Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/