Go to Post There are simply not enough words to say how much the contributions of Dave and Woodie have given to FIRST, and countless students across the world. - Libby K [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Events   CD-Media   CD-Spy   FRC-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 02-25-2004, 09:07 AM
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Exclamation Using a switch to control a PWM

I do know C but i am not directly involved with programming, so i apologize if i don't know some obvious things. We are trying to have two switches move a servo (PWM controlled) between two different values. I assumed this would be as simple as checking the status of the button every iteration of the loop and then assigning a certain value to the PWM via an if statement.

if(p1_sw_some_switch == 1){
pwmxxx=some_value
}

if(p1_sw_some_other_switch == 1) {
pwmxxx=some_other_value


This appears to not be working (ie buttons do not move the servo at all, do the servo does appear to twitch when the OI or the RC is turned on) so my first thought was that maybe the switch takes values other than 0 and 1 like maybe 0 and 255, etc. Any help would be much appreciated
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award
  #2   Spotlight this post!  
Unread 02-25-2004, 09:39 AM
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 7,712
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Using a switch to control a PWM

your code is correct, do you have the backup battery installed?

You may want to do something for you other conditions, though, such as if neither button is pressed or if both buttons are pressed.
  #3   Spotlight this post!  
Unread 02-25-2004, 09:42 AM
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Itinerant Programmer
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 7,188
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Using a switch to control a PWM

Quote:
Originally Posted by maxlobovsky
if(p1_sw_some_switch == 1){
pwmxxx=some_value
}

if(p1_sw_some_other_switch == 1) {
pwmxxx=some_other_value
You have the general idea, however, the joystick buttons have a value of "0" by default, and switch to "1" when pressed. You may be confusing your test by having the later switch override the first switch test.
Try a simpler test like:
Code:
if (p2_sw_trig)
pwmxxx = 254;
else
pwmxxx = 0;
The 7.2v backup battery powers the PWM center pin.

[edit] Joe Ross beat me to an answer. Hey, Ken W. my typing must be slowing down!

[edit 2] deltacoder corrected my reversal of the joystick button values. (I also get left and right confused). Thanks delta!
__________________
"A child of five could understand this. Fetch me a child of five." - Groucho Marx

Last edited by Mark McLeod : 02-25-2004 at 01:22 PM.
  #4   Spotlight this post!  
Unread 02-25-2004, 09:52 AM
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Re: Using a switch to control a PWM

Quote:
Originally Posted by Mark McLeod
Try a simpler test like:
Code:
if (p2_sw_trig)
pwmxxx = 254;
else
pwmxxx = 0;
The problem with that is that this is for a transmission shifter so i want one button press to leave the transmission in a certain gear. But yeah, i should defenitley put initialization values and tell drivers not to press both buttons simultaneously. That servo will go nuts...
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award
  #5   Spotlight this post!  
Unread 02-25-2004, 10:05 AM
Phil_Lutz's Avatar
Phil_Lutz Phil_Lutz is offline
Phil Lutz
#0851 (Froggers)
Team Role: Mentor
 
Join Date: Jan 2004
Location: El Segundo, CA
Posts: 67
Phil_Lutz is on a distinguished road
Send a message via Yahoo to Phil_Lutz
Re: Using a switch to control a PWM

If the servo is "twitching" just on the startup of the code then you are okay.
This is just the servo going to it's initial position.

If the Servo is always twitching it might be a low backup battery.

For a transmission shifter you are best to have it on one switch.
0=low gear, 1=high gear

Also, make sure to stop the motorfor a few loops before shifting, and start the motors back up (to selected speed) after th3e servo has had a chance to move.

The psuedocode would look like this

Code:
// Motor speed 160 In Low Gear
Shift button changed  // have static store last value
Store Motor Speed     // in static for later use
Stop Motor               // 127, neutral
Move Servo    // 0-254 or 254-0  
  count loops for 10 (.2 secs, servo moves full throw in .11)
Start Motor
// Shift on the fly, You got to love it
Setup #defines to track the various points in the shift and switch/case through the shift process.

Hope this helps.

Phil

Last edited by Phil_Lutz : 02-25-2004 at 10:13 AM. Reason: change text
  #6   Spotlight this post!  
Unread 02-25-2004, 10:28 AM
deltacoder1020's Avatar
Happy Birthday! deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Using a switch to control a PWM

Quote:
Originally Posted by Mark McLeod
You have the general idea, however, the joystick buttons have a value of "1" by default, and switch to "0" when pressed. You may be confusing your test by having the later switch override the first switch test.
Try a simpler test like:
Code:
if (p2_sw_trig)
pwmxxx = 254;
else
pwmxxx = 0;
0 does not evaluate to true - it is the only integer that evaluates to false. the joystick buttons have a value of 0 by default, not 1.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #7   Spotlight this post!  
Unread 02-25-2004, 10:32 AM
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Exclamation Re: Using a switch to control a PWM

Quote:
Originally Posted by Phil_Lutz
If the servo is "twitching" just on the startup of the code then you are okay.
This is just the servo going to it's initial position.

If the Servo is always twitching it might be a low backup battery.

For a transmission shifter you are best to have it on one switch.
0=low gear, 1=high gear

Also, make sure to stop the motorfor a few loops before shifting, and start the motors back up (to selected speed) after th3e servo has had a chance to move.

The psuedocode would look like this

Code:
// Motor speed 160 In Low Gear
Shift button changed  // have static store last value
Store Motor Speed     // in static for later use
Stop Motor               // 127, neutral
Move Servo    // 0-254 or 254-0  
  count loops for 10 (.2 secs, servo moves full throw in .11)
Start Motor
// Shift on the fly, You got to love it
Setup #defines to track the various points in the shift and switch/case through the shift process.

Hope this helps.

Phil
That would be ideal, except im not sure that the motors will be still and if they are moving, even if they are being backdrive, it isnt a good idea to shift. I'm afraid if you put something in like this then someone may try to shift while the robot is being pushed or maybe it will keep rolling for longer than expected, etc. Ideally, you could have the shifter only work if an encoder reports no rotation, but we dont have time for an encoder, so i think we will rely on drivers watching the robot and being smart about shifting. (kinda like not shifting without pressing the clutch...)
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award
  #8   Spotlight this post!  
Unread 02-25-2004, 11:14 AM
scottm87 scottm87 is offline
Registered User
AKA: Scott McClure
#0469 (Las Guerrillas)
Team Role: Programmer
 
Join Date: Nov 2002
Rookie Year: 2000
Location: Bloomfield Hills, MI
Posts: 24
scottm87 is on a distinguished road
Re: Using a switch to control a PWM

I haven't used the servos w/ the new control system, but when I have worked with servo's in the past, twitching can also be caused by pushing the servo out of the position you are trying to set it to. The internals of the servo have a potentiometer and simple control circuitry to move the servo to a cooresponding value based on the pot. If you try to move it out of the position, it will try to move back.
  #9   Spotlight this post!  
Unread 02-25-2004, 04:13 PM
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Re: Using a switch to control a PWM

Quote:
Originally Posted by Joe Ross
your code is correct, do you have the backup battery installed?

You may want to do something for you other conditions, though, such as if neither button is pressed or if both buttons are pressed.
After trying countless things, we still cannot get it to work. We have the latest default and Master code. We have even tried reading the values of the relays assigned the values of the switches we want to use. We just cannot seem to set a value to a PWM on a button press.
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award
  #10   Spotlight this post!  
Unread 02-25-2004, 04:15 PM
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
An inspired alumnus
AKA: Jamie Bliss
no team (previously 904 (D-cubed) and 1227 (Techno-Gremlins))
Team Role: Alumni
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Send a message via ICQ to Astronouth7303 Send a message via AIM to Astronouth7303 Send a message via MSN to Astronouth7303 Send a message via Yahoo to Astronouth7303
Re: Using a switch to control a PWM

Does it work with a Victor?
  #11   Spotlight this post!  
Unread 02-25-2004, 04:16 PM
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Re: Using a switch to control a PWM

wow, i feel really really dumb, its because we were setting something to 255 not 254, isnt it?
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award
  #12   Spotlight this post!  
Unread 02-25-2004, 04:20 PM
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
An inspired alumnus
AKA: Jamie Bliss
no team (previously 904 (D-cubed) and 1227 (Techno-Gremlins))
Team Role: Alumni
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Send a message via ICQ to Astronouth7303 Send a message via AIM to Astronouth7303 Send a message via MSN to Astronouth7303 Send a message via Yahoo to Astronouth7303
Re: Using a switch to control a PWM

Quote:
Originally Posted by maxlobovsky
wow, i feel really really dumb, its because we were setting something to 255 not 254, isnt it?
That might be it. Don't worry, I would probably make that mistake if I actually had an oportunity...
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Some EDURobotics Problems squide Robotics Education and Curriculum 9 01-20-2004 09:27 AM
pwm 13-15 wayne 05 Programming 2 10-04-2003 11:08 AM
switch speed control wayne 05 Programming 6 10-01-2003 08:35 AM
PWM and burning out motors patrickrd Technical Discussion 7 06-19-2003 02:30 PM
Need help with 255 Variable Joseph F Programming 18 02-26-2002 01:49 PM


All times are GMT -5. The time now is 12:44 AM.

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


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