Go to Post To the best engineers, scientists, and thinkers, something that is "hard" isn't something to avoid; it is something that begs for us to prove that we can do it. STEM is built on the very idea of trying something, failing, and trying something different. - Bryan Herbst [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
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 23-02-2015, 16:03
ironmare ironmare is offline
Registered User
FRC #5072
 
Join Date: Jan 2015
Location: United States
Posts: 7
ironmare is an unknown quantity at this point
Using xbox thumbstick to control servos on pan/tilt

Here's a good one.

I am using the right thumbstick (let's say axis 1 and 2) of an xbox controller to control the two servos for the pan and tilt for our axis camera. The servos are plugged right into the PWM8 and PWM9 spots on the roboRIO. Now, the thumbstick is already running these servos, but the problem is once you let the thumbstick go back to center, the servos also return to there zero position (far left and straight down). This is an issue when you have to constantly compensate to keep the camera in the right position at all times. What I need is the servos to start at the centered position (camera looking straight ahead) so that when you move the thumbstick around to view, the camera follows the joystick commands and stays there without returning to the far left and straight down position. Can anyone provide some sample coding for this?

Thank you ahead of time for any effort to help!
Reply With Quote
  #2   Spotlight this post!  
Unread 23-02-2015, 16:20
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Using xbox thumbstick to control servos on pan/tilt

I don't fully understand what you're asking for. Do you want the camera position to follow the joystick, except for when the joystick is at neutral/center? Or do you want the joystick to control the camera's motion, such that the camera continuously tries to pan right while the joystick is right of center, or to stay in motion downward while the joystick is positioned down, and stay where it is when the joystick is returned to center?

Depending on what you really want, you might need to add a button that must be pressed in order to tell the camera servos when you want the joystick to control them. That way, releasing the button will make the camera position hold in place, regardless of the joystick position.
Reply With Quote
  #3   Spotlight this post!  
Unread 24-02-2015, 08:03
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,748
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Using xbox thumbstick to control servos on pan/tilt

Like Alan, I'm not sure what you want, but here are the two things I'd suggest.

1. Instead of setting the servo to the X and Y values of the joystick, use them to increment the value of the servo. You'll want to have a shift register that is initialized to zero, and add a fraction of the joystick each time through the loop. Send that to the servos.

2. Only update the servo value based on a button.

I'm also testing to see if the code snippets work when attached like this, but they should at least show you what the code should look like.

Greg McKaskle
Attached Thumbnails
Click image for larger version

Name:	Servo Tilt Code.png
Views:	20
Size:	18.6 KB
ID:	18473  Click image for larger version

Name:	Servo Button Code.png
Views:	11
Size:	14.9 KB
ID:	18474  
Reply With Quote
  #4   Spotlight this post!  
Unread 24-02-2015, 11:06
ironmare ironmare is offline
Registered User
FRC #5072
 
Join Date: Jan 2015
Location: United States
Posts: 7
ironmare is an unknown quantity at this point
Re: Using xbox thumbstick to control servos on pan/tilt

Right on, Alan,

Alan and Greg, I am looking for the second option you listed. When the thumbstick is moved to the right, the camera pans to the right. When the thumbstick is moved down, the camera pans down. When you release the thumbstick, the camera stays exactly in the position it is is, and stops moving.

Thank you for your past and future help!
Reply With Quote
  #5   Spotlight this post!  
Unread 24-02-2015, 11:34
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Using xbox thumbstick to control servos on pan/tilt

Greg's first snippet is probably what you want.

The constant going into the multiply should be changed based on how quickly you want the servo to be able to move when the joystick is at full travel. If you make it 0.001, it will take at least a thousand loops of the code to pan all the way from one side to the other. In teleop, at 50 Hz or 20 ms per loop, that's a very long 20 seconds.
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 08:27.

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