Diddiborg with Ultraborg over Web UI
Forums:
Hi !
Need some help with my project.
I like to run the Diddiborg with Ultraborg over Web UI. I'm using the code I found on this Forum. https://www.piborg.org/node/1846
Two HC-SR04 are in the front of the Diddiborg. I get correct readings in the Web UI.
But when I try to use "Semi" or "Auto-mode" there is no reaction.
Another thing is to control LED lights over the Web UI but I'm not sure how to put inside. Right now I turn on the lights when I start the script and turn off when the script ends. >> # Settings Light
Thanks :-)
Andreas
piborg
Sat, 01/23/2016 - 20:43
Permalink
Diddiborg with Ultraborg over Web UI
The reason that semi-automatic and automatic modes are not really working is that they are currently unfinished.
In its current state the automatic mode does nothing at all.
The semi-automatic mode should:
I do not remember if they have made any progress with the functionality since that version, but I think they were intending to make the automatic mode move around in a simlar fashion to the automaic carpet cleaners.
What you would need to do to make the LEDs do something entirely depends on what you want them to do.
For example if you were to change the values inside the various movement mode sections then they would show you which mode you are in.
e.g.
4ndr345
Sat, 01/23/2016 - 23:14
Permalink
Hi again !
Thanks for the hint to see which mode I'm in.
The semi-automatic mode doesn't work for me and I have no idea whats wrong.
Doesn't slow down and don't stop below 50 mm.
4ndr345
Sun, 01/24/2016 - 00:09
Permalink
Finally I found the problem
Finally I found the problem with the semi-automatic mode.
Instead <=50 I have 150 and <=100 I have 300.
Diddiborg slow down and stop directly before the obstacle.
Web UI show 50 mm to obstacle...
4ndr345
Sun, 01/24/2016 - 09:13
Permalink
Now I'm testing the Auto mode
Now I'm testing the Auto mode but having trouble getting the code free of buggs.
Need a little help to get ahead :-)
piborg
Sun, 01/24/2016 - 15:09
Permalink
Semi and Auto mode logic
The distances shown in the web UI in that code are divided by 10, so they display as cm.
The values in the code are in mm, so they need to be 10 times larger.
e.g.
will be for distances below 15 cm as shown on the web UI.
The code you have shown for the auto mode has a couple of coding mistakes that will cause it to not work:
elif
for each additional condition,else
is only used to mean "anything that is not covered by anyif
orelif
above".I guess you were trying to make him stop when too close.
You can simply the code a bit by only doing the
maxPower
calculation and the setting of the motors once.This is because each time you want to set the motors, the only difference is the speed you are setting.
I think something like this would do what you were intending:
4ndr345
Sun, 01/24/2016 - 16:00
Permalink
Thanks for your help.
Thanks for your help.
I will trying to make him turning left or right when too close.
When I run the script I get an error .
>> line 260
driveRight = 0.3
^
IndentationError: expected an indented block <<
4ndr345
Sun, 01/24/2016 - 17:40
Permalink
Here is my slightly working
Here is my slightly working update for the "Auto Mode"
In "Auto Mode" the Borg have to turn right when obstacle is detected. But it seems there is to much time between the Sono readings. The Borg turns around 45° degrees and don't see that the obstacle is still there.
Hoppe you can help me with this.
piborg
Mon, 01/25/2016 - 12:53
Permalink
Fast ultrasonic updates
I think the reason the code is slow to react to changes is due to the onboard filtering performed by the UltraBorg.
UltraBorg has two modes for reading ditances:
Cleans up the distance readings to give better accuracy and stability.
The filtered readings update slowly, they may take up to 2 seconds to change to a new value.
Used by calling the
UB.GetDistanceX()
functions.Provides the latest reading from the sensor without any filtering.
These raw readings update quickly, but they suffer from 'noise' and may be less accurate for measuring a fixed distance.
Used by calling the
UB.GetRawDistanceX()
functions.I would suggest replacing
UB.GetDistance1()
andUB.GetDistance2()
withUB.GetRawDistance1()
andUB.GetRawDistance2()
and see if the response is faster.4ndr345
Mon, 01/25/2016 - 19:54
Permalink
Thanks again!
UB.GetRawDistanceX() works perfect; reading and response are much better.
Now I have to tune the setup for the moves. I will also try with one more ultrasonic module rear.
4ndr345
Tue, 01/26/2016 - 12:05
Permalink
Hello again ...
I wonder if I can read the direction?
When I'm in the "Semi" mode and the Borg stops I need to push the Stop button before I can move backwards. When "Semi" is on I can't drive backwards.
Like ...
Maybe end the "Semi mode"
piborg
Tue, 01/26/2016 - 12:43
Permalink
Checking direction
What you could do is make another couple of global variables for the users set speeds.
You can then do some simple tests to see what direction the DiddyBorg is set to move in.
Here are the basic bits to get a "direction" value which you can compare to presets:
4ndr345
Thu, 01/28/2016 - 17:08
Permalink
Thanks ...
I will try :-)
4ndr345
Thu, 02/04/2016 - 17:35
Permalink
Hello again !
The Raspberry Pi doesn’t have a power switch, which means I have to remember to properly shut it down every time I want to turn it off. So the idea is to add a Shutdown Switch to the Borg. The script alone runs fine but having trouble getting the code free of buggs when I try to put into the diddy script.
piborg
Thu, 02/04/2016 - 17:58
Permalink
Power switch code
That is a good idea :)
It should be fairly easy to put that code into the diddyWeb.py script.
I think the simplest way would be to add these blocks of code:
At the bottom of the import list:
Before the "Timeout thread" code:
And add the highlighted lines to the section "Stream delegation loop" which is run each time an image is taken:
4ndr345
Thu, 02/04/2016 - 19:13
Permalink
Thanks :-)
Works fine, but I have to replace "sudo shutdown-h now" with "sudo init 0"
How to put in the code into the "metalJoy.py" script ?
piborg
Fri, 02/05/2016 - 11:40
Permalink
Adding code to metalJoy
Adding the button code to metalJoy.py is fairly simple:
4ndr345
Fri, 02/05/2016 - 20:05
Permalink
...
unfortunately it didn't work :-(
File "metaljoy.py", line 133
os.system("sudo shutdown-h now")
^
IndentationError: expected an indented block
piborg
Sun, 02/07/2016 - 00:44
Permalink
Python and indentation
That line needs to be further to the right than the
if
line above it.Put simply Python is sensitive to the use of tabs or spaces at the start of the line.
The error you are seeing is telling you it expected a line to start to the right of a line above.
cleric boomer
Wed, 02/10/2016 - 13:24
Permalink
Question about the switch
Hi PiBorg.
I am planning on having a power (battery power) switch, and also a button to switch off the pi.
The on/off switch is easy.
But the shut down switch using the code above, what sort of switch would that need to be?
push to break (momentary) or
push to make (momentary)?
Thanks in advance
Chris
piborg
Wed, 02/10/2016 - 13:53
Permalink
Shutdown switch
You could use either, but I would suggest a push to make would be best.
You should wire it with a weak pull-down resistor like this:
Use a nice large value like 10 KΩ for R1, Vcc will be the 3V3 pin.
cleric boomer
Tue, 03/29/2016 - 17:30
Permalink
Please forgive my ignorance
OK, I know I am going to sound stupid here..
But here goes.
Following on from your diagram, and also considering that the 6 pins are taken by the reverse board.
so cable to pin 17 - 3.3v
other end to switch.
2 wires attached to other side of switch.
one to pin 40 (GPIO 21)
other to pin 39 (Ground) via a low value resistor.
Then code which says when GPIO goes high run sudo shutdown now
does that sound right?
Cheers
Chris
piborg
Tue, 03/29/2016 - 17:40
Permalink
That's it
That is the basic idea, yes.
The only thing is that you want a large value resistor.
A larger value means less wasted power when the switch is on.
Too low and you might exceed the 50 mA maximum for the 3.3v pin.
For the resistor I would use at least 1 KΩ, which would use 3.3 mA when turned on.
Ideally something like 10 KΩ would be better, that would use 0.33 mA when turned on.
cleric boomer
Tue, 03/29/2016 - 17:55
Permalink
Thanks
10k resister.
I have some of those
4ndr345
Fri, 04/01/2016 - 17:48
Permalink
Turn on and off lights
Now I'm playing around with some ideas.
I try to turn on light over the Web UI. Unfortunately i have now luck.
To put the buttons on the Web UI was easy, but so easy to activate :-(
I was trying ...
But it won't work.
It will be very nice if you could lock at this. Thanks
piborg
Sat, 04/02/2016 - 09:58
Permalink
Turn on and off lights
This might be a problem cause by your text editor :)
Programming languages are very picky about the character symbols used in code.
In particular the quoting marks for Python and HTML need to be of the
"
or'
type.At the moment you have:
httpText += ' iframe.src = ”/Lightoff";\n'
and
httpText += ' iframe.src = ”/Lighton;\n’
for example which look like the text editor has swapped some of the quotes and double-quotes with the fancier style ones.
What you wanted to have was:
httpText += ' iframe.src = "/Lightoff";\n'
and
httpText += ' iframe.src = "/Lighton";\n'
The symbols you want to use are:
" '
The ones you want to watch out for are:
“ ‟ ‘ ‛
These are often used by editors such as Word to make you text look nicer.
There are a fair number of lines with these rouge symbols, and they can be quite hard to spot.
I would suggest either using the find tool on your editor if it has one, otherwise turning the font size up helps a lot.
In the section of code you posted there appear to be bad quote symbols on lines: 101, 105, 200, 204, 240, 242.
4ndr345
Sat, 04/02/2016 - 17:40
Permalink
Thanks so much :-)
Thanks so much :-)
These “ ‟ ‘ ‛ characters was killing all, now it works perfect.