Code - Barrier detect

Wink setup, hardware, basic programming. User to user support.
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
User avatar
sil
Posts: 40
Joined: Thu Oct 01, 2015 1:04 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Code - Barrier detect

Postby sil » Wed Feb 17, 2016 5:25 am


wclift
Posts: 32
Joined: Sun Feb 07, 2016 6:10 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Code - Barrier detect

Postby wclift » Wed Feb 17, 2016 8:47 pm


User avatar
sil
Posts: 40
Joined: Thu Oct 01, 2015 1:04 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Code - Barrier detect

Postby sil » Wed Feb 17, 2016 10:13 pm

thanks keep forgetting that one. Not used to using "==" in my scripting at work its just "=" . However it doesnt explain what i had been seeing and as i mentioned doesn't hinder the Wink behaviour, it still bounces around avoiding headon collisions. I spent a while just printing to the serial monitor a random() output (not a variable) and trying different randomSeed options, and i couldn't get an output that would give me two values (a 0 and 1 seemed easiest to go for. had better success with randomSeed(A0) but sitting on my table random(0, 1) might give me a zero first then nothing but 1s afterwards. If i picked Wink up I started getting zeros so A0 must be be from a light sensor. Hopefully a decent random generator is part of an upcoming lesson. Doesn't concern me too much right now, just wanted to share the code, which does work fine for me, would be interesting to see if it works fine for others.

I had used "else" too and its a good point to raise for others to help. I didnt do anything in particular to optimise this code, its small and uncomplicated. At one point I had a few "if else" conditions to do different turns to pick a new direction to head off in and whittled it down to two explicit checks with a beep on one so I could let it lose and didnt have to watch each turn to see which it chose.

another thing i hadn't considered at the start, which makes sense, is this method is affected by light levels too. I tried playing with the barrier detection as an extension to some light following stuff i was playing with to combine them together. I still might be able to make progress combining them, my light reactions were dependant on the left/right sensors and not the center, while the barrier detect is opposite.

wclift
Posts: 32
Joined: Sun Feb 07, 2016 6:10 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Code - Barrier detect

Postby wclift » Wed Feb 17, 2016 11:44 pm


User avatar
sil
Posts: 40
Joined: Thu Oct 01, 2015 1:04 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Code - Barrier detect

Postby sil » Thu Feb 18, 2016 2:40 am

like i said i spent a lot of time trying things my aim was to get 0 & 1 from random but the code i posted is not about using random and i wrote many things following tuorials to get a random sequence of any sort up to 10 and unless i picked up the wink the sequences all settled into returning a single value. sorry but i did try all you suggested and much more and i've moved onto other things right now.

with or without a seed, everything tested returns a single value.sometimes the first returned value is different, its not like its returning a repeating sequence which you get from a random function, hence the need for a seed. a lot in theory should have worked, what i was seeing from the serial monitor clearly shows different. there doesnt appear to be any seeds used in the plumgeek includes either. if you want to write some code and post a thread for random number generation it might be best for others, it just happened to be a dead part of the code i posted, didnt think it'd cause a stir as its irrelevant to what i posted or how the bot runs with it.

wclift
Posts: 32
Joined: Sun Feb 07, 2016 6:10 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Code - Barrier detect

Postby wclift » Fri Feb 19, 2016 8:39 am


User avatar
sil
Posts: 40
Joined: Thu Oct 01, 2015 1:04 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Code - Barrier detect

Postby sil » Tue Feb 23, 2016 2:12 am

wclift
Thanks for the input, I don't think I put enough effort into making my code more presentable, and I can appreciate pouncing on an obvious mistake and glad you did. Also glad you moved the random subject to a dedicated thread, randomness is a good way to get some character and behaviour into something, in robotics it can mean the difference between a robot that can roam until its out of power or one that quickly finds a corner to get trapped in.

Sorry i havent fired up my Wink for a while to test your code yet and fix up that part of the code, been sick and also picked up a 3D printer from Aldi which has held my interest, I'm hoping to design something for Ringo and Wink.

User avatar
sil
Posts: 40
Joined: Thu Oct 01, 2015 1:04 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Code - Barrier detect

Postby sil » Tue Mar 29, 2016 8:28 am

Finally got around to cleaning up the code a little, no real improvements from original post. Randomly picks a turn direction, only uses one sensor but works well for a very simple example. Extract the attached zip archive into your Arduino installation, upload to your Wink robot (not Ringo), and it starts running when you turn it on. On a tabletop you can put your hand in front for it to detect, I used a flat baking tray with a ridge all around and it just "bounces" around until the battery runs out.

Feel free to explore and play with my code and find fun ways to add features!
Attachments
sil-wink-barrier_detect_01a.zip
Wink - barrier detect 01a code
(8.03 KiB) Downloaded 682 times


[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 1 guest