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)
Nice implementation!
One note: I noticed that you put three 'd's in the list to increase their chance. There should be some Python functions to define specific probabilities for certain choices. It's necessary to stop Nybble from staying in a walking state for too long.