Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions earthrover/embgpio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://sanusb.blogspot.com/2023/01/descricao-do-projeto-gesture-controlled.html
Binary file added earthrover/embgpio/Webcam.mp4
Binary file not shown.
Binary file added earthrover/embgpio/Wpicam.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions earthrover/embgpio/ajax_gpio.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
//include_once '../vars.php';

$msg=$_POST["message"];

if ($msg=="pin40on"){
set_gpio('40','1');
}

elseif ($msg=="pin40off"){
set_gpio('40','0');
}

elseif ($msg=="pin38on"){
set_gpio('38','1');
}

elseif ($msg=="pin38off"){
set_gpio('38','0');
}

elseif ($msg=="allon"){
set_gpio('40','1');
set_gpio('38','1');
}

elseif ($msg=="alloff"){
set_gpio('40','0');
set_gpio('38','0');
}

function set_gpio($pin,$x){
system("sudo gpio -1 mode $pin out"); // seta o pino físico 40 (gpio -1 ) como sada (out)
system("sudo gpio -1 write $pin $x"); // Liga o pino físico 40
echo "gpio $pin $x <br>";
//switch($x){
// case '1': $z='dh';break;
// case '0': $z='dl';break;
// case 'output': $z='op';break;
//}
//$cmd="sudo raspi-gpio set $pin $z";
//system($cmd);

//echo"$x: $cmd <br>";
}

?>
142 changes: 142 additions & 0 deletions earthrover/embgpio/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>replit</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div>Teachable Machine Image Model</div>
<button type="button" onclick="init()">Start</button>
<div id="webcam-container"></div>
<div id="label-container"></div>

<!--
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.3.1/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/image@0.8/dist/teachablemachine-image.min.js"></script>
-->
<script src="js/tf.min.js"></script>
<script src="js/teachablemachine-image.min.js"></script>

<script src="js/jquery.min.js"></script>

<script type="text/javascript">
// More API functions here:
// https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/image

// the link to your model provided by Teachable Machine export panel
var delay = 200;

var prob = 0.9;

const URL = "/ml/";

let model, webcam, labelContainer, maxPredictions;

// Load the image model and setup the webcam
async function init() {
const modelURL = URL + "model.json";
const metadataURL = URL + "metadata.json";

// load the model and metadata
// Refer to tmImage.loadFromFiles() in the API to support files from a file picker
// or files from your local hard drive
// Note: the pose library adds "tmImage" object to your window (window.tmImage)
model = await tmImage.load(modelURL, metadataURL);
maxPredictions = model.getTotalClasses();

// Convenience function to setup a webcam
const flip = true; // whether to flip the webcam
webcam = new tmImage.Webcam(200, 200, flip); // width, height, flip
await webcam.setup(); // request access to the webcam
await webcam.play();
window.requestAnimationFrame(loop);

// append elements to the DOM
document.getElementById("webcam-container").appendChild(webcam.canvas);
labelContainer = document.getElementById("label-container");
for (let i = 0; i < maxPredictions; i++) { // and class labels
labelContainer.appendChild(document.createElement("div"));
}
}

async function loop() {
webcam.update(); // update the webcam frame
await predict();
window.requestAnimationFrame(loop);
}

// run the webcam image through the image model
async function predict() {
// predict can take in an image, video or canvas html element
const prediction = await model.predict(webcam.canvas);

for (let i = 0; i < maxPredictions; i++) {
const classPrediction = prediction[i].className + ": " + prediction[i].probability.toFixed(2);

//labelContainer.childNodes[i].innerHTML = classPrediction;
if(prediction[i].probability > prob)
labelContainer.childNodes[i].innerHTML = "<b style='color:green'>" + classPrediction + "</b>";
else
labelContainer.childNodes[i].innerHTML = "<b style='color:blue'>" + classPrediction + "</b>";


if(prediction[i].className=="Cinco" && prediction[i].probability>prob){
cmd_to_rpi="pin40on"

sleep(delay);
send_data(cmd_to_rpi);

console.log(classPrediction);
//display_msg(prediction[i].className, cmd_to_rpi);
}

if(prediction[i].className=="Zero" && prediction[i].probability>prob){
cmd_to_rpi="pin40off"

sleep(delay);
send_data(cmd_to_rpi);

console.log(classPrediction);
//display_msg(prediction[i].className, cmd_to_rpi);
}

if(prediction[i].className=="Vazio" && prediction[i].probability>prob){
cmd_to_rpi=""

sleep(delay);
send_data(cmd_to_rpi);

console.log(classPrediction);
//display_msg(prediction[i].className, cmd_to_rpi);
}


}
}

function send_data(msg){
console.log(msg);
$.post("ajax_gpio.php",
{
message: msg
}
);

}

function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}

</script>
</body>

</html>
134 changes: 134 additions & 0 deletions earthrover/embgpio/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/bin/bash

echo "*********Checking Raspberry Pi OS*****************************"

RASPBIAN=$(grep VERSION_ID /etc/os-release | sed 's/VERSION_ID="\([0-9]\+\)"/\1/')
echo "Raspbian Version: $RASPBIAN"
if [ "$RASPBIAN" -gt "10" ]; then
echo "This OS not supported."
echo "Earthrover's software works with Raspberry Pi OS(Legacy), also known as 'Buster' and earlier versions."
echo "Prepare a micro sd card with 'Buster' and try again."
exit 1
fi

echo "***************************************************************"
echo "**********Updating and Upgrading the Raspberry Pi OS***********"
echo "***************************************************************"

sudo apt-get update -y
sudo apt-get upgrade -y


echo "***************************************************************"
echo "*******Installing Apache Webserver and PHP*********************"
echo "***************************************************************"

sudo apt-get install apache2 -y
sudo apt-get install php libapache2-mod-php -y

echo "***************************************************************"
echo "*****Allowing execution of system commands from PHP************"
echo "***************************************************************"

echo "pi ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
echo "www-data ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

echo "***************************************************************"
echo "*******Installing SSL Certificates*****************************"
echo "***************************************************************"

TEMP_DIR="/home/pi/Documents/temp"
FILE_NAME="helloworld_ssl_rpi"

SSL_DIR="/etc/ssl/$FILE_NAME"

if [ -e "$SSL_DIR" ]; then
timestamp=$(date "+%Y-%m-%d_%H-%M-%S")
mv $SSL_DIR $SSL_DIR.$timestamp
fi

sudo cp /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-available/default-ssl.conf.bak1

mkdir -p ${TEMP_DIR}

curl -O https://helloworld.co.in/deploy/${FILE_NAME}.zip

unzip ${FILE_NAME}.zip -d ${TEMP_DIR}

rm ${FILE_NAME}.zip

mv ${TEMP_DIR}/${FILE_NAME} /etc/ssl/


sudo mv /etc/ssl/${FILE_NAME}/default-ssl.conf /etc/apache2/sites-available/

sudo chmod 600 /etc/ssl/${FILE_NAME}/apache*

rm -R ${TEMP_DIR}


#Enable Apache SSL module
sudo a2ensite default-ssl.conf
sudo a2enmod ssl
sudo a2enmod headers

#restart Apache
sudo systemctl restart apache2

echo "***************************************************************"
echo "******Installing espeak (Text to Speech engine)****************"
echo "***************************************************************"

sudo apt-get install espeak -y

echo "***************************************************************"
echo "******Installing Tensorflow Lite and USB Coral ML accelerator Libraries
echo "***************************************************************"

echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install python3-tflite-runtime -y
sudo apt-get install libedgetpu1-std -y
sudo python3 -m pip install numpy
sudo python3 -m pip install Pillow
sudo python -m pip install urllib3

echo "***************************************************************"
echo "********Installing OpenCV**************************************"
echo "***************************************************************"

sudo apt install python3-opencv -y

echo "***************************************************************"
echo "****** Downloading Robot's Software **************************"
echo "***************************************************************"

CODE_DIR="/var/www/html/earthrover"
MODEL_DIR="/var/www/html/all_models"

if [ -e "$CODE_DIR" ]; then
timestamp=$(date "+%Y-%m-%d_%H-%M-%S")
mv $CODE_DIR $CODE_DIR.$timestamp
echo "Current time: $timestamp"
fi


if [ -e "$MODEL_DIR" ]; then
timestamp=$(date "+%Y-%m-%d_%H-%M-%S")
mv $MODEL_DIR $MODEL_DIR.$timestamp
echo "Current time: $timestamp"
fi

git clone https://github.com/jiteshsaini/robotics-level-4 /home/pi/Downloads/tmp
sudo mv /home/pi/Downloads/tmp/earthrover/embgpio /var/www/html/
sudo rm -R /home/pi/Downloads/tmp
sudo chmod 777 -R /var/www/html

echo "**************************************************************************************"
echo "***Your Raspberry Pi has been configured to run the software of Embedded Rpi Gpio*****"
echo "**************************************************************************************"

echo "your IP address is: " $(hostname -I)
echo "Now using a browser of Rpi embedded VNC Viewer or Laptop/PC on the same network, type following in your browser:-"
echo $(hostname -I)"/embgpio"
Binary file added earthrover/embgpio/install.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions earthrover/embgpio/js/jquery.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions earthrover/embgpio/js/teachablemachine-image.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions earthrover/embgpio/js/tf.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions earthrover/embgpio/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"tfjsVersion":"1.3.1","tmVersion":"2.4.5","packageVersion":"0.8.4-alpha2","packageName":"@teachablemachine/image","timeStamp":"2023-01-07T01:01:12.725Z","userMetadata":{},"modelName":"tm-my-image-model","labels":["Cinco","Zero","Vazio"],"imageSize":224}
1 change: 1 addition & 0 deletions earthrover/embgpio/model.json

Large diffs are not rendered by default.

Binary file added earthrover/embgpio/weights.bin
Binary file not shown.