View unanswered posts | View active topics It is currently Tue Jun 02, 2020 4:02 am

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
RobotC question with datatypes
Author Message
Rookie

Joined: Fri Jan 09, 2015 4:05 pm
Posts: 6
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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Rookie

Joined: Fri Jan 09, 2015 4:05 pm
Posts: 6
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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning