Go to Post "Don't make me call my flying monkeys..." - Joe Johnson [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 03-02-2016, 13:05
Lesafian Lesafian is offline
Registered User
AKA: Jeremy Styma
FRC #6077 (Wiking Kujon)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2016
Location: Posen, Michigan
Posts: 20
Lesafian is an unknown quantity at this point
Re: Is my Java code ok?

Quote:
Originally Posted by MaGiC_PiKaChU View Post
the last line where you set your solenoid to kOff: it will cut the input pressure to your mechanism, meaning it will not hold the last position. you likely don't want this line
Thank you, I'll fix that! As far as everything else does it look ok?
  #2   Spotlight this post!  
Unread 03-02-2016, 13:13
Joey1939's Avatar
Joey1939 Joey1939 is offline
Registered User
AKA: Joey Holliday
FRC #1939 (Kuhnigits)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Kansas City, Missouri
Posts: 139
Joey1939 has a spectacular aura aboutJoey1939 has a spectacular aura aboutJoey1939 has a spectacular aura about
Re: Is my Java code ok?

I see that you initialized the RobotDrive with the port numbers of your speed controllers. I believe that this will work correctly because you are using victors, but it would be better practice to initialize it with the two speed controllers you already initialized.

Code:
drive = new RobotDrive(drivermotor1, drivemotor2);
__________________


  #3   Spotlight this post!  
Unread 03-02-2016, 15:51
Stimpy1901 Stimpy1901 is offline
Registered User
AKA: Bobby
FRC #2348 (Cool Geeks)
Team Role: Mentor
 
Join Date: Dec 2007
Rookie Year: 2008
Location: Honolulu
Posts: 57
Stimpy1901 will become famous soon enough
Re: Is my Java code ok?

For us, although the code said "build successful" for code similar as shown below, it will throw an error (on the robot) and the driver station noted no code on the robot.

Code:
		drivemotor1 = new Victor(0);
		drivemotor2 = new Victor(2);
...
		drive = new RobotDrive(0, 2);
So use the correction shared by Joey:
Quote:
Originally Posted by Joey1939 View Post
Code:
drive = new RobotDrive(drivermotor1, drivemotor2);
Once we did this change, everything worked fine.
__________________
"The person who says it cannot be done should not interrupt the person doing it."
- Chinese Proverb
  #4   Spotlight this post!  
Unread 03-02-2016, 14:00
MaGiC_PiKaChU's Avatar
MaGiC_PiKaChU MaGiC_PiKaChU is offline
Drive Coach
AKA: Antoine L.
FRC #3360 (Hyperion)
Team Role: Mentor
 
Join Date: Mar 2014
Rookie Year: 2012
Location: Sherbrooke
Posts: 608
MaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond repute
Re: Is my Java code ok?

Quote:
Originally Posted by Lesafian View Post
Thank you, I'll fix that! As far as everything else does it look ok?
i guess the goal with using an axis for your sliding mechanism was to control the speed? Then you should use your joystick axis value instead of 1 and -1 (full speed)

also, your condition testing with Math.abs removes the negative sign, so your second if test will never work

This is how it could be made

Code:
// Move sliding mechanism forwards and backwards
			
                        //if your axis is not between -0.1 and 0.1
			if (Math.abs(xboxController.getRawAxis(5)) > .1) {
                               
                                //set your motor output to the axis value
				slideMotor.set(xboxController.getRawAxis(5));

			
			}else {
				slideMotor.set(0);
                        }
__________________
2012 - 3360 - Junior member
2013 - 3360 - Lead Programmer, Human player
2014 - 3360 - Lead Programmer, Human player
2015 - 3360 - Lead Programmer, Driver
2016 - 3360 - Mentor, Drive coach



  #5   Spotlight this post!  
Unread 03-02-2016, 14:54
Lesafian Lesafian is offline
Registered User
AKA: Jeremy Styma
FRC #6077 (Wiking Kujon)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2016
Location: Posen, Michigan
Posts: 20
Lesafian is an unknown quantity at this point
Re: Is my Java code ok?

Won't this only work if I move the stick up? Shouldn't I need both > and < .1 if I'd like to both increase and decrease

Example of what I mean:
Code:
			if (Math.abs(xboxController.getRawAxis(5)) > .1) {
                               
                                //set your motor output to the axis value
				slideMotor.set(xboxController.getRawAxis(5));

			
			}else if (Math.abs(xboxController.getRawAxis(5)) < .1 {
                                slideMotor.set(xboxController.getRawAxis(5));
                        }
  #6   Spotlight this post!  
Unread 03-02-2016, 15:20
soundfx's Avatar
soundfx soundfx is offline
Registered User
AKA: Aaron J
FRC #3238 (Cyborg Ferrets)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2014
Location: Anacortes, WA
Posts: 14
soundfx is an unknown quantity at this point
Re: Is my Java code ok?

Quote:
Won't this only work if I move the stick up? Shouldn't I need both > and < .1 if I'd like to both increase and decrease
MaGiC_PiKaChU is correct. His code will test the absolute value for the threshold, then set the motor power to the joystick. Yours would probably work just as well, but the else if is redundant since it will never evaluate to true.
  #7   Spotlight this post!  
Unread 03-02-2016, 18:05
MaGiC_PiKaChU's Avatar
MaGiC_PiKaChU MaGiC_PiKaChU is offline
Drive Coach
AKA: Antoine L.
FRC #3360 (Hyperion)
Team Role: Mentor
 
Join Date: Mar 2014
Rookie Year: 2012
Location: Sherbrooke
Posts: 608
MaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond repute
Re: Is my Java code ok?

Quote:
Originally Posted by Lesafian View Post
Won't this only work if I move the stick up? Shouldn't I need both > and < .1 if I'd like to both increase and decrease

Example of what I mean:
Code:
			if (Math.abs(xboxController.getRawAxis(5)) > .1) {
                               
                                //set your motor output to the axis value
				slideMotor.set(xboxController.getRawAxis(5));

			
			}else if (Math.abs(xboxController.getRawAxis(5)) < .1 {
                                slideMotor.set(xboxController.getRawAxis(5));
                        }
No. The math.abs function transforms your value to positive.

if (Math.abs(xboxController.getRawAxis(5) < .1) is equivalent to if(xboxController.getRawAxis(5) < .1 && xboxController.getRawAxis(5) > -.1)

Let's say you put Math.abs(-0.05). that will output 0.05. I recommend you try it out and print in the Riolog. That saves you a few lines in your code, instead of testing for both positive and negative values.
__________________
2012 - 3360 - Junior member
2013 - 3360 - Lead Programmer, Human player
2014 - 3360 - Lead Programmer, Human player
2015 - 3360 - Lead Programmer, Driver
2016 - 3360 - Mentor, Drive coach




Last edited by MaGiC_PiKaChU : 03-02-2016 at 19:42. Reason: fixed operator
  #8   Spotlight this post!  
Unread 03-02-2016, 19:33
mmaunu's Avatar
mmaunu mmaunu is offline
Registered User
FRC #2485 (W.A.R. Lords)
Team Role: Mentor
 
Join Date: Mar 2013
Rookie Year: 2010
Location: San Diego, CA
Posts: 88
mmaunu is a jewel in the roughmmaunu is a jewel in the roughmmaunu is a jewel in the roughmmaunu is a jewel in the rough
Re: Is my Java code ok?

Quote:
Originally Posted by MaGiC_PiKaChU View Post
No. The math.abs function transforms your value to positive.

if (Math.abs(xboxController.getRawAxis(5) < .1) is equivalent to if(xboxController.getRawAxis(5) < .1 || xboxController.getRawAxis(5) > -.1)
That should be an && (and) in your compound statement instead of an or.
__________________
2014 Las Vegas (Winners with 987, 2478; Excellence in Engineering)
2014 San Diego (Finalists with 987, 3250; Quality Award)
2013 Inland Empire (Winners with 1538, 968; Excellence in Engineering Award)
2013 San Diego (Finalists with 2984, 4322; Creativity Award)
2012 Las Vegas (Finalists with 2034, 3187; Quality Award)
  #9   Spotlight this post!  
Unread 03-02-2016, 19:42
MaGiC_PiKaChU's Avatar
MaGiC_PiKaChU MaGiC_PiKaChU is offline
Drive Coach
AKA: Antoine L.
FRC #3360 (Hyperion)
Team Role: Mentor
 
Join Date: Mar 2014
Rookie Year: 2012
Location: Sherbrooke
Posts: 608
MaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond reputeMaGiC_PiKaChU has a reputation beyond repute
Re: Is my Java code ok?

Quote:
Originally Posted by mmaunu View Post
That should be an && (and) in your compound statement instead of an or.
you're right. Fixed it
__________________
2012 - 3360 - Junior member
2013 - 3360 - Lead Programmer, Human player
2014 - 3360 - Lead Programmer, Human player
2015 - 3360 - Lead Programmer, Driver
2016 - 3360 - Mentor, Drive coach



Closed Thread


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 05:34.

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