Go to Post Redfoo is actually a really awesome guy. He discussed the future of engineering and talked about C programming with our software team. - SM987 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-14-2015, 06:42 PM
1024Programming 1024Programming is offline
Registered User
FRC #1024
 
Join Date: Jan 2014
Location: Indiana
Posts: 43
1024Programming is an unknown quantity at this point
Cutting down motor power

I've encountered a problem with reducing the power on motor outputs when slowing the robot down for demos. The original lines of code are:
Lifter.lift1.set(Robot.oi.xBox.getRawAxis(1));
Lifter.lift2.set(-Robot.oi.xBox.getRawAxis(1));
which run the lift at full speed as expected. When I change it to:
Lifter.lift1.set(Robot.oi.xBox.getRawAxis(1)/(5/3));
Lifter.lift2.set(-Robot.oi.xBox.getRawAxis(1)/(5/3));
the lift runs slightly slower, which makes sense. Now where it starts making less sense. When I change it again to:
Lifter.lift1.set(Robot.oi.xBox.getRawAxis(1)*(0.6) );
Lifter.lift2.set(-Robot.oi.xBox.getRawAxis(1)*(0.6));
it runs slower than dividing by 5/3, which it shouldn't. The worst one is:
Lifter.lift1.set(Robot.oi.xBox.getRawAxis(1)*(3/5));
Lifter.lift2.set(-Robot.oi.xBox.getRawAxis(1)*(3/5));
which causes the lift to stop responding to input altogether. Has anyone else encountered this, does anyone know why this happens, and is there a way to make dividing by 5/3, multiplying by 0.6, and multiplying by 3/5 all do the same thing?
Thanks!
Reply With Quote
  #2   Spotlight this post!  
Unread 09-14-2015, 07:02 PM
Caleb Sykes's Avatar
Caleb Sykes Caleb Sykes is offline
Registered User
FRC #4536 (MinuteBots)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2009
Location: St. Paul, Minnesota
Posts: 1,033
Caleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond repute
Re: Cutting down motor power

You are likely running into problems with integer division. If you do not put decimal points on your numbers, the compiler will assume that you are using integers. In integer land, multiplying by 5/3 is the same as multiplying by 1, which should cause no change in the elevator motion, and multiplying by 3/5 is the same as multiplying by 0, which explains your lack of elevator movement.

You have already found the easiest solution, which is to just use 0.6 instead of 3/5. If you want to use 3 and 5, write them as 3.0 and 5.0, which will tell the compiler that these are floating point numbers, and thus can have a floating point quotient.
Reply With Quote
  #3   Spotlight this post!  
Unread 09-14-2015, 08:56 PM
GeeTwo's Avatar
GeeTwo GeeTwo is online now
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,539
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
Re: Cutting down motor power

Another way is shown below, not perfect but the way you'd do it if you really did want to do integer arithmetic:
Code:
Lifter.lift1.set(Robot.oi.xBox.getRawAxis(1)*3/5);
Lifter.lift2.set(-Robot.oi.xBox.getRawAxis(1)*3/5);
This way multiplies by 3 and then divides by five. In integer arithmetic (especially division), the order of operations absolutely matters.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:01 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi