OCCRA
Go to Post MAKE SURE THE BATTERY DOES NOT FALL OUT - magnets [more]
Home
Go Back   Chief Delphi > Technical > Programming > Python
CD-Media  
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 02-11-2018, 12:09 PM
Zamula Zamula is offline
Registered User
no team
 
Join Date: Feb 2018
Location: Alabama
Posts: 4
Zamula is an unknown quantity at this point
90 degree turn

I am pretty new to programming and I am having some trouble programming the autonomous mode to rotate 90 degrees and then move 4ft forward. The robot wheels are 6in in diameter and we are using a NavX board. There is a high chance that I am just over thinking this, but what would be the best way to go about this.
Reply With Quote
  #2   Spotlight this post!  
Unread 02-11-2018, 01:08 PM
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #6367 (), FRC #7240 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,409
virtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond repute
Re: 90 degree turn

There's an example demonstrating this.

https://github.com/robotpy/examples/...otate-to-angle
__________________
Maintainer of RobotPy (Python for FRC) & WPILib Contributor
Creator of pyfrc (Robot Simulator + utilities for Python), pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript), and lots more...

Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #3   Spotlight this post!  
Unread 02-11-2018, 04:16 PM
Zamula Zamula is offline
Registered User
no team
 
Join Date: Feb 2018
Location: Alabama
Posts: 4
Zamula is an unknown quantity at this point
Re: 90 degree turn

Ok. If I use self.turnController.setSetpoint(90.0) then the robot will rotate to the left 90 degrees? If I just use drive(outputMagnitude, curve) to get the robot to drive in a straight line how would I go about getting it to stop after moving 4 ft.
Reply With Quote
  #4   Spotlight this post!  
Unread 02-11-2018, 05:59 PM
DonRotolo's Avatar
DonRotolo DonRotolo is offline
Waiting for the storm
FRC #0832
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Atlanta GA
Posts: 7,337
DonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond reputeDonRotolo has a reputation beyond repute
Re: 90 degree turn

I'm not a programmer (and I don't play one on TV).

First, be careful specifying 'exactly' 90 degrees. Figure out how to specify 'about' 90, otherwise you might turn 90.1 and things will get wonky.

======
So, making a robot go 4 feet straight can be done many ways:

One way would be to just deliver power to the motors for x.x seconds. x.x is determined by experimentation. This method is OK but not super-accurate. Slower speeds tend to be more accurate.

Another way would be to fit a rotation sensor on one driven wheel*, and then count the rotations (using the sensor) until you have gone x.x feet. A 6" wheel travels 6 * Pi inches per revolution. Here, you might not travel straight.

Another way would be rotation sensors on left and right sides, that way both sides can be sure to rotate the same number of times (and thus same distance). Unless, of course, something interferes with the movement and causes a wheel or 2 to slip.

If you need to go exactly 4.00 feet and it must be +/- 0.01 foot, you would do the 3rd thing above and add a sensor to determine exact position (ultrasonic, LIDAR, camera...), but this is likely overkill for FRC.


*It can be anywhere that is driven, for example the gearbox, not necessarily the wheel itself.
__________________

*All comments are mine and do not represent my employer*
Reply With Quote
  #5   Spotlight this post!  
Unread 02-11-2018, 06:09 PM
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #6367 (), FRC #7240 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,409
virtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond repute
Re: 90 degree turn

Quote:
Originally Posted by Zamula View Post
Ok. If I use self.turnController.setSetpoint(90.0) then the robot will rotate to the left 90 degrees? If I just use drive(outputMagnitude, curve) to get the robot to drive in a straight line how would I go about getting it to stop after moving 4 ft.
The example I pointed you to works in simulation. Run the sim and play with it, modify it, and see how it works for yourself.
__________________
Maintainer of RobotPy (Python for FRC) & WPILib Contributor
Creator of pyfrc (Robot Simulator + utilities for Python), pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript), and lots more...

Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #6   Spotlight this post!  
Unread 02-12-2018, 11:00 AM
Zamula Zamula is offline
Registered User
no team
 
Join Date: Feb 2018
Location: Alabama
Posts: 4
Zamula is an unknown quantity at this point
Re: 90 degree turn

I will give the simulation a shot. Just for the sake of understanding what is the purpose of this code?

turnController.setInputRange(-180.0, 180.0)
turnController.setOutputRange(-1.0, 1.0)
turnController.setAbsoluteTolerance(self.kToleranc eDegrees)
turnController.setContinuous(True)
Reply With Quote
  #7   Spotlight this post!  
Unread 02-12-2018, 11:28 AM
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #6367 (), FRC #7240 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,409
virtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond reputevirtuald has a reputation beyond repute
Re: 90 degree turn

Quote:
Originally Posted by Zamula View Post
I will give the simulation a shot. Just for the sake of understanding what is the purpose of this code?

turnController.setInputRange(-180.0, 180.0)
turnController.setOutputRange(-1.0, 1.0)
turnController.setAbsoluteTolerance(self.kToleranc eDegrees)
turnController.setContinuous(True)
All of these are methods of the PIDController object, which you can find the documentation for here: http://robotpy.readthedocs.io/projec...ontroller.html

If the documentation isn't clear, let me know and we can fix the documentation.
__________________
Maintainer of RobotPy (Python for FRC) & WPILib Contributor
Creator of pyfrc (Robot Simulator + utilities for Python), pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript), and lots more...

Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #8   Spotlight this post!  
Unread 02-12-2018, 11:30 AM
slibert slibert is offline
Software Mentor
AKA: Scott Libert
FRC #2465 (Kauaibots)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2005
Location: Kauai, Hawaii
Posts: 546
slibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond reputeslibert has a reputation beyond repute
Re: 90 degree turn

Quote:
Originally Posted by Zamula View Post
turnController.setInputRange(-180.0, 180.0)
- Specifies that the input to the PID controller has a range from -180 to 180 (degrees).
Quote:
Originally Posted by Zamula View Post
turnController.setOutputRange(-1.0, 1.0)
- Specifies that the output from the PID controller has a range from -1 to 1. This is the range of the (unitless) ratio that the motor controller uses.
Quote:
Originally Posted by Zamula View Post
turnController.setAbsoluteTolerance(self.kToleranc eDegrees)
- Specifies a particular value (in ~input~ inputs) which defines the range of values which would be considered "on target" for the PID controller. Not strictly requried, but if you wanted to write code that would disable outputs to the motor when it had reached it's target, this value will be used to generate the result from the isOnTarget() method. For example, if your absolute tolearnce is 2, and your setpoint is 90 degrees, then the PID controller will be on target whenever the input angle is 88 to 92 degrees.
Quote:
Originally Posted by Zamula View Post
turnController.setContinuous(True)
- Specifies that when the input value goes past it's maximum, that the value "wraps" around to it's input range. Since degrees are measured in a circle, it's considered a continuous range. This is how you let the PID controller know that the input range "wraps".

In general, you are highly encouraged to review in detail the PIDController class in the online WPILIB Java documentation.
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 01:46 PM.

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


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi