TXT + python

Alles rund um COMPUTING inkl. Microcontroller & Co.
Everything about COMPUTING incl. Microcontrollers
Forumsregeln
Bitte beachte die Forumsregeln!

TXT + python

Beitragvon bluatigro » 25 Jun 2018, 21:04

hello ft fans
i want to buy a TXT at the end of the yeari
i have a problem i see 30%
so using robopro is not a option for realy complex code
so i decided to use python insted
i have some coding experiance
see :
www.libertybasiccom.proboards.com [ bluatigro ]
www.justbasiccom.proboards.com [ bluatigro ]
www.freebasic.net/forum [ bluatigro ]
www.helpmij.nl [ dutch ][ blua tigro ]
www.vbforums.com [ bluatigro ]
www.codeproject.com [ bluatigro ]
www.ai.hcc.nl [ dutch ][ titus ]
i m already buzzy whit python
i already found some info on this site
i have some questions :
how do i active python on the TXT ?
how do i get a program on the TXT ?
can anyone give me a list of instruction's
on how to code a moblie robot ?
Code: Alles auswählen
# bluatigro 18 jun 2018
# mecrano wheel robot remote control

import ftrobopy
import time

txt = ftrobopy.ftrobopy( 'auto' )
motorleftfore = txt.motor( 1 )
motorrightfore = txt.motor( 2 )
motorleftback = txt.motor( 3 )
motorrightback = txt.motor( 4 )
joylow = -.5
joyhigh = .5

def move( a , b , c , d ) :
    motorleftfore.setSpeed( a )
    motorrightfore.setSpeed( b )
    motorleftback.setSpeed( c )
    motorrightback.setSpeed( d )

def go( a ) :
    move( a , -a , a , -a )

def turn( a ) :
    move( a , a , a , a )

def sideway( a ) :
    move( a , a , -a , -a )

joystickLeft  = txt.joystick( 0 , remote_number = nr )
joystickRight = txt.joystick( 1 )
# remote_number = 0 ( any ) is the default
buttonON      = txt.joybutton( 0 )
buttonOFF     = txt.joybutton( 1 )
while not buttonOFF.pressed():
    joyleftx = joystickLeft.leftright()
    joylefty = joystickLeft.updown()
    joyrightx = joystickRight.leftright()
    joyrighty = joystickRicht.updown()
    if ( joyleftx < joylow ) :
        sideway( -512 )
    elif ( joyleftx > joyhigh ) :
        sideway( 512 )
    elif ( joyrightx < joylow ) :
        turn( 512 )
    elif ( joyrightx > joyhigh ) :
        turn( -512 )
    elif ( joyrighty < joylow ) :
        go( -512 )
    elif ( joyrighty > joyhigh ) :
        if ( txt.ultrasonic( 1 ) > 10 ) :
            go( 512 )
   
    time.sleep( 0.04 )

WARNING :
this code was not tested jet !!
Benutzeravatar
bluatigro
 
Beiträge: 17
Registriert: 25 Jun 2018, 15:44

Re: TXT + python

Beitragvon Lars » 25 Jun 2018, 21:30

Hallo bluatigro,

have a look at http://cfw.ftcommunity.de/ftcommunity-TXT/en/.

Best regards
Lars
Lars
 
Beiträge: 220
Registriert: 25 Okt 2016, 21:50

Re: TXT + python

Beitragvon olagino » 25 Jun 2018, 22:27

Hello,
I've just a few things to say extending Lars' answer a bit:

For the TXTs usage with ftrobopy you don't have to use the community firmware necessarily. You can start any python script (with the instructions in it) on your computer, while the TXT is connected via USB, Bluetooth or WiFi. ftrobopy establishes a connection via any of this interfaces to control the Inputs and Outputs of the TXT. (This can be also helpful when testing :) )
Also, you may want to use the TXT as a standalone device. Then you will need the community firmware: It contains the python interpreter and a few other very useful modules so you can start your programs directly without any computer nearby.



kind regards,

olagino
olagino
 
Beiträge: 76
Registriert: 02 Aug 2014, 13:13

Re: TXT + python

Beitragvon bluatigro » 26 Jun 2018, 21:12

@ lars :
i found it . thanks !!

i wil know if this work after 27 okt 2018
then i wil buy a TXT

i wil post python code when written
especialy if it did not give the desired results

this is what i found earlyer in ft:pedia
i hope that this can help others
Code: Alles auswählen
https://github.com/ftrobopy/ftrobopy/blob/master/manual.pdf

import ftrobopy
import timer

txt = ftrobopy.ftrobopy( 'auto' )
  .motor( 1 ... 4 ) M1 ... M4
    .setSpeed( -512 ... 512 )
    .setDistace( 72 / revole , syncto = motor2 )
    .finished() = bool
    .stop()
    .getCurrentDistance() = from last .setDistance
  .output( 1 ... 8 , level = 0 , Wait = True ) O1 ... O8
     .setLevel( 1 ... 512 )
  .input( 1 ... 8 , Wait = True ) I1 ... I8
     .state() = bool 
  .resistor( 1 ... 8 ) I1 ... I8
    .value() = ohm <= 15000
    .ntcTemperature() = celsius
  .ultrasonic( 1 ... 8 , Wait = True ) I1 ... I8
    .distance() = cm
  .voltage( 1 ... 8  , Wait = True ) = mV    I1 ... I8
  .colorsensor( 1 ... 8 , Wait = True ) I1 ... I8
    .value()
    .color() = string
  .trailfollower( 1 ... 8 ) I1 ... I8
    .state()
  .joystick( 0 = left or 1 = right
    , remote_number = 0 or 1 ... 4
    , remote_type = 0    0 = ir or 1 = bluetoth )
    .leftright() = -1.0 ... 1.0
    .updown() = -1.0 ... 1.0
  .joybutton( 0 = left or 1 = right
    , remote_number = 0 , remote_type = 0 )
    .pressed() = bool
  .joydipswith( remote_type = 0 ) only ir makes sense
    .setting() = 0 ... 3
  .play_sound( 0 ... 29 , repeat = 1x , volume = 100% )
  .stop_sound()
  .sound_finished() = bool

timer.sleep( sec )

class ftroboproftTXT( host = '127.0.0.1' , port = 65000 , serport = '/dev/tty02'
, on_error = , on_data = )
consts
C_VOLTAGE
C_SWITCH
C_RESISTOR
C_ULTRASONIC
C_ANALOG
C_DIGITAL
C_OUPUT
C_MOTOR

  .queryStatus() = name , version
  .getDivicename() = TXTname
  .getVersionNumber() = int
  .getFimwareVersion() = string
  .startOnline( update_interval = 0.02 )
  .stopOnline()
  .setConfig( M   int[ 4 ] , I   int[ 8 ][ 2 ] )
    M = 0 = output
    M = 1 = motor
# example
  M = [ txt.C_MOTOR , txt.C_MOTOR , txt.C_MOTOR , txt.C_MOTOR ]
  I = [ ( txt.C_SWITCH     , txt.C_DIGITAL ) ,
        ( txt.C_SWITCH     , txt.C_DIGITAL ) ,
        ( txt.C_ULTRASONIC , txt.C_ANALOG ) ,
        ( txt.C_VOLTAGE    , txt.C_ANALOG ) ,
        ( txt.C_RESTISTOR  , txt.C_ANALOG ) ,
        ( txt.C_SWITCH     , txt.C_DIGITAL ) ,

Benutzeravatar
bluatigro
 
Beiträge: 17
Registriert: 25 Jun 2018, 15:44


Zurück zu Robo Pro / Computing / Software

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 4 Gäste