Coder Social home page Coder Social logo

ssis-robotics / makeblock-ultrasonicsensor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lolmrdabbydab/makeblock-ultrasonicsensor

0.0 0.0 0.0 1.92 MB

Contribution to the SAMK competition 2022

License: MIT License

Shell 1.08% Python 98.92%

makeblock-ultrasonicsensor's Introduction

MakeBlock-UltraSonicSensor

GitHub release MIT license

This passion project by the students My Nguyen, Thai Le, Phu Le and Triet Do. They applied for the SAMK robot competition 2022.

SAMK Competition

More about the competition of the SATAKUNTA UNIVERSITY OF APPLIED SCIENCES (SAMK) and this competition:

https://www.samk.fi/en/education/master-robot-builders/

Stage 1: May 10th, 2022

We submitted the first version of our robot on May 9th and was one of the 17 teams (out of 78) to be selected to the finals. A video about this project can be found on YouTube

Final round: May 20th, 2022

We have to wait for the outcome.

Build

And that is how it looks like:

Screen Shot 2022-05-18 at 16 40 53

Code

The program was running on the Raspberry Pi in python, addressing the MegaPi via serial interface. For transportation the megapi library was imported, for audio output the pygame library.

This is the final code from May 17th for the final round in this competition:

from megapi import *
import time
import pygame
import RPi.GPIO as GPIO

announce = time.time()
turning = time.time()
distance = 123

# -=Function=-
def Forward(port, speed):
	sleep(0.4)
	bot.encoderMotorRun(port,-speed)

def Backward(port, speed):
	bot.encoderMotorRun(port, speed)

def Left(port, speed, dist):
	bot.encoderMotorMove(port, speed, dist, Forward)

# -=UltrasonicSensor=-
def UltraSonic(port):
	global distance
	distance = port
	print(distance)

# -=SoundPlay=-
def SoundPlay(SoundFile):
	SoundList = ["Ms C.mp3", "Mr Williams.mp3", "beep.mp3"] # Ms. C = 0 | Mr. W = 1 | beep = 2
	pygame.mixer.init()
	pygame.mixer.music.set_volume(0.2) # Volume: (0 - 1)
	pygame.mixer.music.load(SoundList[SoundFile])
	pygame.mixer.music.play()
	while pygame.mixer.music.get_busy() == False:
		continue

def LightOn(pin):
	GPIO.output(pin, GPIO.HIGH) # Green = 40 | Blue = 36 | Red = 38

def LightOff():
	GPIO.output(36, GPIO.LOW)
	GPIO.output(38, GPIO.LOW)
	GPIO.output(40, GPIO.LOW)

# -=GPIO=-
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

	# Speaker
speaker_buttonPin1 = 32
speaker_buttonPin2 = 22
GPIO.setup(speaker_buttonPin1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(speaker_buttonPin2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(40,GPIO.OUT)
GPIO.setup(38,GPIO.OUT)
GPIO.setup(36,GPIO.OUT)

    # Sound Sensor
sound_sensorPin = 18
GPIO.setup(sound_sensorPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

# -=Main=-
if __name__ == '__main__':
	bot = MegaPi()
	bot.start()
	output = 0
	LightOn(40)
	SoundPlay(2)

	while True:
		# -=SET UP=-
		if GPIO.input(speaker_buttonPin1) == GPIO.HIGH:
			output = 1
		
		if GPIO.input(speaker_buttonPin2) == GPIO.HIGH:
			output = 2
			Forward(4, 0)
			Backward(1, 0)

		# -=GO OUT=-
		if output == 1:
			LightOff()
			LightOn(36)
			
			# Sound
			if time.time() - announce > 10:
				announce = time.time()
				SoundPlay(0)
				
			# Measure Distance (Store in "Distance" global variable)
			bot.ultrasonicSensorRead(6,UltraSonic)
			
			# Movement
			if distance < 20:
				turning = time.time() + 3.5
			
			if (turning - time.time()) > 0:
				# turn
				Left(4, 50, 150)
				Backward(1, 0)
			
			else:
				# drive straight
				Forward(4, 50)
				Backward(1, 50)
		
		# -=BE QUIET=-
		elif output == 2:
			LightOff()
			LightOn(38)
			Forward(4, 0)
			Backward(1, 0)
			if GPIO.input(sound_sensorPin) == GPIO.HIGH:
				SoundPlay(1)
		
		else:
			pass

Remarks

makeblock-ultrasonicsensor's People

Contributors

matthiaskreier avatar kreier avatar lolmrdabbydab avatar millyng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.