hi folks,
i'm from germany and my english isn't fine, but maybee somebody here can help me.
i have a nybble with nyboard 1_2 - i namend him "chaos" - and wish me, he "life" like a cat, go around in my room, avoid obsticals, make catstuff, so what.
i'm an absolutely beginner in programming and calibrate nybble with petoi desktop app and loading up firmware.
with arduino ide and c++ i don't cope, nothing works... but with mind+ coding blocks it is better. i make a little crash-curs online in python.
the script here (https://www.petoi.camp/forum/software/make-nybble-run-around-at-home-and-avoid-obstacles?searchTerm=avoid) works fine - thanks for that! - (in the mind+ mode), chaos walk, sit and so forth, but he can't see and i don't now, how i should the ultrasonicsensor make work.
first i try so:
while True:
writeDigitalValue(6, 1)
time.sleep(1)
writeDigitalValue(6, 0)
time.sleep(1)
writeDigitalValue(6, 1)
time.sleep(1)
ultrasonic(readDigitalValue(6))
if (readDigitalValue(6))
print("yes")
else:
print("no")
the output is "yes", but only, when the trigger- and echopin is pin 6. with pin 7 for echo the output is "no". in the ultrasonic-mode the sensor works and the led blinks, but chaos no walk or make other action. the sensor is ok, i think.
in this reason i try it with the software from the pinpong-library in mind+ for the urm10-sensor.
i have written this code:
# -*- coding: UTF-8 -*-
# MindPlus
# Python
from pinpong.board import SR04_URM10
from pinpong.board import Board
from PetoiRobot import *
import time
openPort("COM8")
def pin6_read_digital():
class pin6_read_digital:
def __init__(self):
self.read_digital = None
def sonar_distance_cm():
global sonar_distance_cm
class sonar_distance_cm:
def __init__(self):
self.sonar_distance_cm = None
self.duration = start - end
self.start = time.time()
self.end = time.time()
self.TimeElapsed = end - start
def dis():
class dis:
def __init__(self):
self.dis = None
def __call__(self):
self.dis = None
def ultrasonic(read_digital):
pass
def TRIGGER_PIN():
pass
def ECHO_PIN():
pass
def pin6():
pass
def distance():
pass
def cm():
pass
def SR04_URM10():
pass
def sonar1():
pass
def read_digital():
pin6_read_digital
def Pin(TRIGGER_PIN, ECHO_PIN):
pass
def dis():
sonar_distance_cm()
def DigitalValue():
dis
readDigitalValue(6)
setattr(Pin, "D6", None)
TRIGGER_PIN = Pin.D6
ECHO_PIN = Pin.D6
setattr(pin6, "input", str)
while pin6.input(ECHO_PIN) == 0:
start = time.time()
setattr(pin6, "input", str)
while pin6.input(TRIGGER_PIN) == 1:
end = time.time()
start = time.time()
end = time.time()
distance = cm
sonar = SR04_URM10
duration = start - end
TimeElapsed = (end - start)
Pin(TRIGGER_PIN, ECHO_PIN)
ultrasonic(read_digital)
pin6()
distance()
cm()
SR04_URM10()
sonar1()
read_digital()
dis()
DigitalValue()
pin6_read_digital()
sonar_distance_cm()
while True:
dis = sonar_distance_cm()
writeDigitalValue(6, 1)
time.sleep(1)
writeDigitalValue(6, 0)
time.sleep(1)
writeDigitalValue(6, 1)
time.sleep(1)
ultrasonic(readDigitalValue(6))
ultrasonic(pin6_read_digital())
print("distance = %d cm"%dis)
the output is an error: print("distance = %d cm"%dis), %d format: a number is required, not sonar_distance_cm
ok, i now, in this line are placeholders and i try it with many numbers, for example 34300/2 or 17150 because of the speed of ultrasound, but the output is no distance who changes, is every this, what i wrote instead of "dis" in the last line of code. when i worte ("distance = %d cm"%1), the output is 1.
what exactly are the placeholders and what i must write there? i think, in the code are mistakes, are not? what must i change?
or give it an other way, nybble make randomly walk around home and see, avoid and so forth? maybee somebody has written a code and would share it?
thanks for reading and maybee help,
greetings from germany
briquila
So if you comment the last line of your code :
print("distance = %d cm"%dis)
Can it work fine? what' the effect? Could you take a video for running your code above?