top of page

Software

Public·144 members

Make Nybble do random stuff

Hi there,


For those of you, who are using the Bluetooth-module I wrote some lines to make Nybble do random stuff within random time intervals. All the actions are send from the computer via Python PySerial and give "life" to Nybble. The next step is to read out the ultrasonic sensor via the serial port and implement obstacles avoidance. I already implemented the ultrasonic sensor via protothreading (see my other post named Protothreading) without losing movement performance.

The serial port would be a substitution of the Raspberry Pi as a "Brain" and might be more efficient concerning battery usage.


Make sure to set up the correct serial port in the code.


import time
import serial
import random

# Establish serial connection via PySerial
ser = serial.Serial(
    port='/dev/rfcomm0', # Change according to your port
    baudrate=115200,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
)
catStuff = ['kbalance', 'kwkF', 'kwkF', 'kwkF', 'kwkL','kwkR', 'ksit', 'khi', 'kbuttUp',  'kpee', 'd', 'd', 'd', 'kbk', 'klu']

time.sleep(10)
currentAction = 'kbalance'

while(True):
    ser.write(str.encode(currentAction))
    currentAction = random.choice(catStuff)
    time.sleep(random.random()*20)

216 Views
Gero
21 gen 2021

Thanks!

Yes, your annotation is correct, that I tried to increase chance. I've seen a function, but I have to take a closer look at it.

What is your recommendation for the maximum time in walking state?

bottom of page