Close

Command the robot to do something with a voice response!

A project log for Anna The Multibot!

Multifunctional robot to help bring the dream of a personal robot into reality.

DennisDennis 07/22/2016 at 00:230 Comments

To have a robot with a lot of different functions, it is necessary to come up with a way to call the different functions. Ideally, any one off the street could be able to tell the robot to perform a task. On that thought, plain text commands seem the most obvious way to accomplish this, and a voice response also seems like a good idea.
To add very complex capabilities with lots of functions to any project, I like to add a new class to house the functions and subs. It makes the program a bit easier to follow and keeps it looking neater.
On that note, I added two new classes to the Visual Studios program “command and speech.”
I added a “command” text box to receive the commands. As text is typed in the text box, the command class is called as each character is typed to determine if the command matches any of the command keywords with the below sub.


Private Sub Command_TextChanged(sender As Object, e As EventArgs) Handles Command_text.TextChanged, Command_text.TextChanged
command_input = Command_text.Text
Command.text_decode()

End Sub


The Speech Class at the moment just contains one sun that speaks a string of text that is send when the sub is called. Below is the speech class.


Imports System.Speech.Synthesis
Public Class Speech
Private speaker As New SpeechSynthesizer()

Public Sub speak_text(text As String)
Dim speech
speech = CreateObject("bot.voice")
speech.speak(text)
End Sub
End Class


The Command class determines if any command key word is typed and if one or a combination of keywords is typed it responds with a voice response and calls the operation. The command class at the moment calls the robots motor and head commands. It also opens a second thread for the voice so both subs run at the same time.

Imports System.Threading

Public Class Command
Dim Speech As New Speech
Public Sub text_decode()
If command_input.Contains("look") Then headcommand()
If command_input.Contains("head") Then headcommand()
If command_input.Contains("move") Then movecommand()
If command_input.Contains("turn") Then movecommand()
If command_input.Contains("backup") Then movecommand()
If command_input.Contains("back up") Then movecommand()
End Sub
Public Sub headcommand()
If command_input.Contains("up") Then
Machine_vision.head_up(1500)
Dim Thread2 As New Thread(Sub() Speech.speak_text("looking up by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
If command_input.Contains("down") Then
Machine_vision.head_down(1500)
Dim Thread2 As New Thread(Sub() Speech.speak_text("looking down by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
If command_input.Contains("forward") Then
Machine_vision.head_forward()
Dim Thread2 As New Thread(Sub() Speech.speak_text("looking forward by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
If command_input.Contains("left") Then
Machine_vision.head_left(1500)
Dim Thread2 As New Thread(Sub() Speech.speak_text("looking left by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
If command_input.Contains("right") Then
Machine_vision.head_right(1500)
Dim Thread2 As New Thread(Sub() Speech.speak_text("looking right by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
If command_input.Contains("stop") Then
Machine_vision.drive_stop()
Dim Thread2 As New Thread(Sub() Speech.speak_text("stop by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
End Sub
Public Sub movecommand()
If command_input.Contains("forward") Then
Machine_vision.drive_forward(1500)
Dim Thread2 As New Thread(Sub() Speech.speak_text("moveing forward by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
If command_input.Contains("turn left") Then
Machine_vision.drive_left_f(500)
Dim Thread2 As New Thread(Sub() Speech.speak_text("turning left by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
If command_input.Contains("turn right") Then
Machine_vision.drive_right_f(500)
Dim Thread2 As New Thread(Sub() Speech.speak_text("turning right by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
If command_input.Contains("back up") Then
Machine_vision.drive_reverse(500)
Dim Thread2 As New Thread(Sub() Speech.speak_text("backing up by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
If command_input.Contains("backup") Then
Machine_vision.drive_reverse(1500)
Dim Thread2 As New Thread(Sub() Speech.speak_text("backing up by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
If command_input.Contains("rotate left") Then
Machine_vision.drive_left(500)
Dim Thread2 As New Thread(Sub() Speech.speak_text("rotateing left by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
If command_input.Contains("rotate right") Then
Machine_vision.drive_right(500)
Dim Thread2 As New Thread(Sub() Speech.speak_text("rotateing right by your command"))
Machine_vision.Command_text.Text = Nothing
Thread2.Start()
End If
End Sub

End Class

We now have a way to call different Automated processes. Just add the if statement with the word and call the process.

Below is a screen shot of the command text box.

Below is Anna receiving text commands with voice response.


Discussions