Pages: [1]   Go Down
Author Topic: Interfacing Servo motors using USB gamepad  (Read 555 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone. I want to make a robotic arm which i can control it by a USB gamepad. I will give you the link how to communicate arduino using USB gamepad
http://teamprincipia.wordpress.com/2008/04/08/arduino-python-4-axis-servo-control/comment-page-4/#comment-537

I have a problem in controlling the servo motors. I want to do something like this, if i press a button on my usb gamepad the servo will rotate clockwise and if I press another button that same servo will rotate anticlockwise. What happens is that if I press a button ti goes from 0 to 180 degrees and 180 to 0 degrees. but i cant control them independently. Could anyone plz post a code how to control servos independently.
Logged

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 82
Posts: 3842
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Seems like at the moment you have a variant of the standard sweep tutorial but with a button in the mix somewhere.

Why don't you post what you have so far... and what you've tried that incorporates the other button?
Logged

The Elders of the Internet know who I am.....
Get me on LinkedIn: za.linkedin.com/in/jimbrownza/

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is my python code
https://github.com/aeropunk/Arduino-Python-4-Axis-Servo/blob/master/multijoystick.py

Here is a part of the whole code to show actually which one I am using
 
Code:
def handleJoyEvent(e):
    # Assign actions for Button DOWN events
    if e.type == pygame.JOYBUTTONDOWN:
        # Button 1 (trigger)
        if (e.dict['button'] == 0):
            print "Trriger Down"
            # Set pin 13 LED to HIGH for digital on/off demo
            servo.move(99, 180)
        # Button 2
        if (e.dict['button'] == 1):
            print "Button 2 Down"
            servo.move(5, 180) #This is used to select servo no. 5 and rotate it to 180 degrees
        # Button 4
        if (e.dict['button'] == 3):
            servo.move(5, 0) # #This is used to select servo no. 5 and rotate it back to 0 degrees
            print "Button 4 Down"
Here button == 1 will rotate the servo clockwise and button == 3 will rotate that servo anticlockwise . Also there is another file servo.py where there is move(servo, angle) function. here servo means number which sends data to switch statement below.
Here is my arduino code

https://raw.github.com/aeropunk/Arduino-Python-4-Axis-Servo/master/MultipleSerialServoControl.pde


Below is a part of my ardiono code
Code:
        case 5:
          if(pos == 180)
          {
            //What code should be written to rotate it clockwise as long as the button is pressed
          }
          if(pos == 0)
          {
            ////What code should be written to rotate it anti-clockwise as long as the button is pressed
          }
          servo5.write(fpos);
          delay(1000);
          break;
I have used the switch statement because its easier to communicate with usb gamepad through serial.read()
Logged

Pages: [1]   Go Up
Jump to: