Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 37

Thread: Making a Pan Tilt work with Joy stick

  1. #11
    Join Date
    Feb 2008
    Location
    Chicago, IL
    Posts
    9
    Rep Power
    38

    Re: Making a Pan Tilt work with Joy stick

    sure, folks. I'll attach it here once I get home from work.

  2. #12
    Join Date
    Dec 2007
    Location
    Portland, OR
    Posts
    3,198
    Images
    952
    Rep Power
    142

    Re: Making a Pan Tilt work with Joy stick

    Woo! Thanks a ton!

    Learning by example is a great way to go for code

  3. #13
    Join Date
    Feb 2008
    Location
    Chicago, IL
    Posts
    9
    Rep Power
    38

    Re: Making a Pan Tilt work with Joy stick

    So here's the code in the attachment. I did not get a chance to work on it, so it basically won't work out-of-box on your PC because it requires certain set up.

    The code receives data from a USB HID (Human Interface Device, in my case, the joystick), and send corresponding command to a network socket. So to make it work for you, you'll need to send command to serial port instead. I have not got a chance to look into that approach, but I see there's a serial port component in C# library.

    I built this code with MS Visual C# Express Edition.

    Any questions, please let me know.

  4. Thumbs up Re: Making a Pan Tilt work with Joy stick

    Well I got my hands on my first phidgets servo controller over the weekend. I enjoyed Alex W.'s joystick tutorial, but ran into some hurdles integrating it into another project. I just finished this up, and figured out how easy it really is. My version is based on the "motion" sample from AForge, because I wanted a webcam feed/motion detection, joystick control, and phidgets info on the same form. AFAIK, "motion" is what the WaterHobo is based on.

    So here it goes:

    Get Alex W's CSharpUSBJoystick tutorial. (convert to C# 2008 if neccessary, makes no difference)
    Open the USBJoystick.cs file, select all, and copy it to your clipboard.

    Open your current project.
    Add a new class file.
    Paste the clipboard contents into that file.
    Change the namespace entry on line 20 from CSharpUSBJoystick to your project's namespace (in my adapted usage, it's simply "motion").

    So now you have the USBJoystick class setup on your project. Time to use it.

    In your primary form, right under the public class Form1 : blah blah blah { add the lines:

    USB_Joystick js;
    Phidgets.Servo servo = new Phidgets.Servo(); // optional, varies with servo controller

    Under the procedure for the main form, before InitializeComponent(), at the very start, add:

    try
    {
    js = newUSB_Joystick(0, 1000, .20, this);
    }
    catch (Exception)
    {
    throw;
    }
    js.PresetValues(); // possibly optional?

    // Failure to include this exception handler means lots of software crashes.
    // This was learned the hard way, and cost me a few hours.
    // I didn't notice these lines when dissecting CSharpUSBJoystick originally. Do not skip it!

    Okay that should have the js object created and ready to roll. Now comes an important part, how to poll the joystick for new information.

    Create a timer control on your form. Set it to enabled, and go with a low interval (100 works for me). We want to check the joystick positions, and adjust the servo positions accordingly. Double click on that timer and open up the code window. Add this to the timer function:

    js.GetData();
    updatePositions(); // optional, use whatever method to update your servo positions you like

    Now your options to react to the joystick are up to you. Here's how I did it, using 2 servos for pan (0) and tilt (1). The servo and joystick labels simply show their current positions on the form. This technique was liberally taken from Alex W.'s tutorial. You can react to the joystick movements directly from the js.State objects, or copy them to a form control and react to that.

    private void updatePositions()
    {
    Servo0label.Text = servo.servos[0].Position.ToString();
    Servo1label.Text = servo.servos[1].Position.ToString();
    joystickXlabel.Text = js.State.X.ToString();
    joystickYlabel.Text = js.State.Y.ToString();
    double ServoStep = 0.2;
    servo.servos[0].Position = ((111+js.State.X)*ServoStep);
    servo.servos[1].Position = ((119+js.State.Y)*ServoStep);
    }

    // 111 & 119 represent my "center" positions for the servos.
    // on-the-fly adjustments are unncessary with my fixed mount setup.
    // servo step is set for 0-1000 joystick axis ranges

    This should be readily adaptable to any controller that's got C# functionality, and any of the phidgets gear you have attached. I finished it all up in 1 afternoon, with only highschool level prior coding experience, and absolutely none using MS Visual Studio C# Express. With these snippets, anybody can get joystick control running in minutes. Alex is my hero.
    Last edited by indy007; 06-09-2008 at 01:27 PM. Reason: spelling & whatnots

  5. #15
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    177

    Re: Making a Pan Tilt work with Joy stick

    Thanks for posting that back! That's great info! +rep for you!

    Any chance that you might post your merged project back into the downloads? Sounds super interesting!

  6. Re: Making a Pan Tilt work with Joy stick

    Sure thing! This is motion & csharpusbjoystick mashed together.

    It will very likely CRASH if you do not:
    * Have a usb joystick plugged in (I use a Thrustmaster Cougar HOTAS setup)
    * Have a phidgetts usb servo controller plugged in.
    * Have PhidgetsManager running on your task bar.

    Also, the 111 & 119 numbers in the updatePositions function should be changed to your servos center positions (as seen in PhidgetsManager when you double click the device), or else I could see some possible damage happening.
    note: in this template, it's called updateForms() instead of the updatePositions() used in the previous post.

    Be warned, there's a little bit of slop (leftover code from deleted controls used in testing), and the form labels will say "gun turret", because this control system is being built to run a drive-by-wire, ridable, paintball tank that will play in 26hour events... which should explain my burning desire for a hybrid powerplant...
    Last edited by indy007; 06-09-2008 at 02:20 PM. Reason: update function note.

  7. #17
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    177

    Re: Making a Pan Tilt work with Joy stick

    Insanely cool, thanks!

    I've been working on a large long-run battery powered 'bot's drivetrain for awhile. I can offer some advice if you're still working on your drivetrain.

  8. #18

    Re: Making a Pan Tilt work with Joy stick

    Quote Originally Posted by Alex View Post
    That is too cool db, thanks I love seeing these Wiimote applications in action!

    Too bad I don't have a Mac
    Why can't you do that on a PC too? Even under Windows?

    8-Dale
    I can handle complexity. It's the simple things that confound me.
    Do everything in moderation, ESPECIALLY, moderation..
    Sometimes the only way to win, is not to play.. -- Stephen Falken

  9. Re: Making a Pan Tilt work with Joy stick

    Quote Originally Posted by Adrenalynn View Post
    Insanely cool, thanks!

    I've been working on a large long-run battery powered 'bot's drivetrain for awhile. I can offer some advice if you're still working on your drivetrain.
    There will be posts begging for input once I get that far in the fabrication stage. The estimated weight is 250-300 pounds ready for battle. The cruise speed (defined by game rules & insurance regs) is only 5mph... but while the terrain here is nice & flat, other places that I'll travel to can have some pretty nasty grades... so the more torque the better.

  10. #20
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    177

    Re: Making a Pan Tilt work with Joy stick

    Quote Originally Posted by robotguy View Post
    Why can't you do that on a PC too? Even under Windows?

    8-Dale
    I can.

    ----
    Indy - my current platform tops at 15mph right now, chain driven, and weighs 280lbs. Runtimes with a 100lb payload are running about 9hrs, but my turn-over time for spare batteries is only about 6hrs.

    Are you going tracked or wheeled?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Contest Entry Holographic Halloween Robot
    By Rodger Cleye in forum Project Showcase
    Replies: 7
    Last Post: 11-06-2007, 03:37 PM
  2. Kondo web page translated.
    By Droid Works in forum Humanoids, Walkers & Crawlers
    Replies: 4
    Last Post: 10-06-2007, 05:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •