Esempio n. 1
0
    def __init__(self):
        self.output_topic = rospy.get_param('~output_topic', '/cmd_vel')
        self.joy_UID = rospy.get_param('~tinkerforge_joy_UID', 'waz')
        self.tinkerforge_host = rospy.get_param('~tinkerforge_host',
                                                'localhost')
        self.tinkerforge_port = rospy.get_param('~tinkerforge_port', 4223)

        self.actual_steering = 0

        self.pub = rospy.Publisher(self.output_topic, Twist, queue_size=1)

        self.ipcon = IPConnection()  # Create IP connection
        self.joy = BrickletJoystick(self.joy_UID, self.ipcon)

        self.ipcon.connect(self.tinkerforge_host, self.tinkerforge_port)
Esempio n. 2
0
class Joy:
    def __init__(self):
        self.output_topic = rospy.get_param('~output_topic', '/cmd_vel')
        self.joy_UID = rospy.get_param('~tinkerforge_joy_UID', 'waz')
        self.tinkerforge_host = rospy.get_param('~tinkerforge_host',
                                                'localhost')
        self.tinkerforge_port = rospy.get_param('~tinkerforge_port', 4223)

        self.actual_steering = 0

        self.pub = rospy.Publisher(self.output_topic, Twist, queue_size=1)

        self.ipcon = IPConnection()  # Create IP connection
        self.joy = BrickletJoystick(self.joy_UID, self.ipcon)

        self.ipcon.connect(self.tinkerforge_host, self.tinkerforge_port)

    @staticmethod
    def valmap(ivalue, istart, istop, ostart, ostop):
        """
        map a value from one input range to output range, like the Arduino map function
        :param ivalue: input value to map
        :param istart: input from
        :param istop: input to
        :param ostart: output from
        :param ostop:  output to
        :return: mapped input
        """
        return ostart + (ostop - ostart) * ((ivalue - istart) /
                                            (istop - istart))

    def run(self):
        cmd_vel = Twist()
        while not rospy.is_shutdown():
            x, y = self.joy.get_position()
            pressed = self.joy.is_pressed()

            # if not pressed:
            #     cmd_vel.linear.x = 0
            # else:
            cmd_vel.linear.x = self.valmap(y, 100, -100, -1, 1)
            cmd_vel.angular.z = self.valmap(x, -100, 100, -1, 1)

            self.pub.publish(cmd_vel)
Esempio n. 3
0
 def try_bricklet(self, uid, device_identifier, position):
     if device_identifier == 210:
         self.inputs["joystick"] = BrickletJoystick(uid,
                                                    self.controller.ipcon)
         self.inputs["joystick"].set_debounce_period(400)
         self.inputs["joystick"].register_callback(
             self.inputs["joystick"].CALLBACK_POSITION_REACHED,
             self.joystick_position)
         self.inputs["joystick"].register_callback(
             self.inputs["joystick"].CALLBACK_PRESSED, self.joystick_pushed)
         self.inputs["joystick"].set_position_callback_threshold(
             "o", -99, 99, -99, 99)
     if device_identifier == 234:
         self.inputs["multitouch"] = BrickletMultiTouch(
             uid, self.controller.ipcon)
         self.inputs["multitouch"].set_electrode_sensitivity(125)
         self.inputs["multitouch"].register_callback(
             self.inputs["multitouch"].CALLBACK_TOUCH_STATE,
             self.multitouch)
def cb_position_reached(x, y):
    if y == 100:
        print('Top')
    elif y == -100:
        print('Bottom')

    if x == 100:
        print('Right')
    elif x == -100:
        print('Left')

    print("")

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    j = BrickletJoystick(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Get threshold callbacks with a debounce time of 0.2 seconds (200ms)
    j.set_debounce_period(200)

    # Register position reached callback to function cb_position_reached
    j.register_callback(j.CALLBACK_POSITION_REACHED, cb_position_reached)

    # Configure threshold for position "outside of -99, -99 to 99, 99"
    j.set_position_callback_threshold("o", -99, 99, -99, 99)

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()
Esempio n. 5
0
    if y == 100:
        print('Top')
    elif y == -100:
        print('Bottom')

    if x == 100:
        print('Right')
    elif x == -100:
        print('Left')

    print("")


if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    j = BrickletJoystick(UID, ipcon)  # Create device object

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected

    # Get threshold callbacks with a debounce time of 0.2 seconds (200ms)
    j.set_debounce_period(200)

    # Register position reached callback to function cb_position_reached
    j.register_callback(j.CALLBACK_POSITION_REACHED, cb_position_reached)

    # Configure threshold for position "outside of -99, -99 to 99, 99"
    j.set_position_callback_threshold("o", -99, 99, -99, 99)

    input("Press key to exit\n")  # Use raw_input() in Python 2
    ipcon.disconnect()
from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_joystick import BrickletJoystick


# Callback function for pressed callback
def cb_pressed():
    print("Pressed")


# Callback function for released callback
def cb_released():
    print("Released")


if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    j = BrickletJoystick(UID, ipcon)  # Create device object

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected

    # Register pressed callback to function cb_pressed
    j.register_callback(j.CALLBACK_PRESSED, cb_pressed)

    # Register released callback to function cb_released
    j.register_callback(j.CALLBACK_RELEASED, cb_released)

    input("Press key to exit\n")  # Use raw_input() in Python 2
    ipcon.disconnect()
Esempio n. 7
0
        print("Stepper -> Zurück")
        stepper.drive_backward()
    else:
        print("Puffer erreicht")
        stepper.stop()


if __name__ == "__main__":

    ipcon = IPConnection()
    dcb = BrickDC(UIDdcb, ipcon)
    oled = BrickletOLED128x64(UIDoled, ipcon)
    poti = BrickletLinearPoti(UIDpoti, ipcon)
    ropoti = BrickletRotaryPoti(UIDropoti, ipcon)
    stepper = BrickStepper(UIDstepper, ipcon)
    joystick = BrickletJoystick(UIDjoystick, ipcon)
    irsensor = BrickletDistanceIR(UIDirsensor, ipcon)

    ipcon.connect(HOST, PORT)
    print("Verbindung unter folgenden Daten: \nIP: " + HOST + "\nPort: " +
          PORT)

    o_clear()
    print("Einstellungen werden gesetzt")
    o_write(1, 5, "Einstellungen")
    o_write(1, 5, "werden gesetzt")

    ctrl_hz_fan = 5000
    dcb.set_pwm_frequency(5000)
    dcb.set_acceleration(5000)
HOST = "localhost"
PORT = 4223
UID = "XYZ" # Change XYZ to the UID of your Joystick Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_joystick import BrickletJoystick

# Callback function for pressed callback
def cb_pressed():
    print("Pressed")

# Callback function for released callback
def cb_released():
    print("Released")

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    j = BrickletJoystick(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Register pressed callback to function cb_pressed
    j.register_callback(j.CALLBACK_PRESSED, cb_pressed)

    # Register released callback to function cb_released
    j.register_callback(j.CALLBACK_RELEASED, cb_released)

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()
Esempio n. 9
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XYZ" # Change XYZ to the UID of your Joystick Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_joystick import BrickletJoystick

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    j = BrickletJoystick(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Get current position
    x, y = j.get_position()

    print("Position[X]: " + str(x))
    print("Position[Y]: " + str(y))

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()