Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Geschrieben

Hi,

Im building a robot and want to write a programm so it can drive. Since I'm really unexperienced with programming I'm asking for some help. I have two continuous Servomotors and want to make them work. I've taken this as an example:

 

#!/usr/bin/env python

# -*- coding: utf-8 -*-

 

HOST = "localhost"

PORT = 4223

UID = "XXYYZZ" # Change XXYYZZ to the UID of your Servo Brick

 

from tinkerforge.ip_connection import IPConnection

from tinkerforge.brick_servo import BrickServo

 

# Use position reached callback to swing back and forth

def cb_position_reached(servo_num, position):

    if position == 9000:

        print('Position: 90°, going to -90°')

        servo.set_position(servo_num, -9000)

    elif position == -9000:

        print('Position: -90°, going to 90°')

        servo.set_position(servo_num, 9000)

    else:

        print('Error') # Can only happen if another program sets position

 

if __name__ == "__main__":

    ipcon = IPConnection() # Create IP connection

    servo = BrickServo(UID, ipcon) # Create device object

 

    ipcon.connect(HOST, PORT) # Connect to brickd

    # Don't use device before ipcon is connected

 

    # Register position reached callback to function cb_position_reached

    servo.register_callback(servo.CALLBACK_POSITION_REACHED, cb_position_reached)

 

    # Enable position reached callback

    servo.enable_position_reached_callback()

 

    # Set velocity to 100°/s. This has to be smaller or equal to the

    # maximum velocity of the servo you are using, otherwise the position

    # reached callback will be called too early

    servo.set_velocity(0, 10000)

    servo.set_position(0, 9000)

    servo.enable(0)

 

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

    servo.disable(0)

    ipcon.disconnect()

 

I don't know what to type in for ipconnection and i don't think I need the position stuff. I only want it to accelerate and slow down again. How can I do that?

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.