Joystick - buggy - rules??

Moderators: Voyager, BertB, rtenklooster, Stuntteam, grovkillen, TD-er

Post Reply
Message
Author
User avatar
dynamicdave
Normal user
Posts: 54
Joined: 30 Jan 2017, 20:25

Joystick - buggy - rules??

#1 Post by dynamicdave » 11 Aug 2018, 09:10

Hi,
I'm planning on starting a WiFi-based buggy project (with my students) using an on-board Wemos D1 Mini to drive two motors using PWM from Node-RED.

I plan to use a dual axis joystick (as the control box) where the analog values are sent to two ESP8266s and then via MQTT to Node-RED.

My question is... what's the best way to handle/process the readings?

For example, I don't really want to send the same value each time (as that seems unnecessary).

What I'd like to do is compare the current and the previous reading, and send them if they are different, otherwise do nothing.

I was also considering dividing the reading by say 10, to reduce the sensitivity of the joystick.

Can the above be achieved using RULES ??

Any input/feedback would be appreciated.

Kind regards from David

TD-er
Normal user
Posts: 1125
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Joystick - buggy - rules??

#2 Post by TD-er » 11 Aug 2018, 13:20

Changing the sensor reading range can also be done using the formula present on most plugins.
Only sending an update on change -given some threshold in change- is currently not implemented, but I like the idea of that.

I am not that much into rules, to know about comparing with previous values.
I guess you could add a dummy device and use that as some kind of register for the last known value. If it has changed, set the new value to that dummy device and do you thing with this new value.

Don't forget that sending the same value over and over might not be a bad idea, since the receiver may also miss an update.

And as last remark, I like the word "buggy" in the title. My initial interpretation of the title was completely different from what was meant :)

User avatar
dynamicdave
Normal user
Posts: 54
Joined: 30 Jan 2017, 20:25

Re: Joystick - buggy - rules??

#3 Post by dynamicdave » 11 Aug 2018, 14:49

Thanks for your response.

Yes I know I could change the numerical range by using the formula (which I've done with my soil moisture sensor).

I know roughly what I want to do, the problem is getting my head around how to use "rules" to achieve it.

Really sorry I created some concern with the title "buggy" - should have used robot I suppose.

Thanks again for your response.

TD-er
Normal user
Posts: 1125
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Joystick - buggy - rules??

#4 Post by TD-er » 12 Aug 2018, 12:22

It wasn't a problem, I like language-kind of jokes where words are being used in a totally different meaning than expected.

The rules are quite simple, but may be a bit too simple to get an idea of their possibilities.

User avatar
dynamicdave
Normal user
Posts: 54
Joined: 30 Jan 2017, 20:25

Re: Joystick - buggy - rules??

#5 Post by dynamicdave » 12 Aug 2018, 17:07

I've been writing some "rules" for one of my Wemos D1s - whilst I wait for my dual-axis joysticks to arrive (for my buggy project).

Here's the rule-set...

on System#boot do
TaskValueSet,12,1,200
publish /node42/previous_value, [previous#value]
timerSet,1,1
endon

on rules#timer=1 do
if [current#value] <> [previous#value]
TaskValueSet,12,1,[current#value]
publish /node42/previous_value, [previous#value]
publish /node42/current_value, [current#value]
endif
timerSet,1,1
endon

I set up a "Generic - Dummy Device" and gave it a name/value of "previous/value".
I set up an analog input (reading the voltage from an Light Dependent Resistor LDR - until my joysticks arrive).
This had a name/value of "current/value".

My idea was to read the output from ADC as quickly as possible and only send the current value if it was different from the previous value.
I didn't really want to keep sending the same value as this would use up MQTT bandwidth.
The fastest/shortest time to read the ADC is once per second, so I suppose I haven't really gained anything.
I might ask the people that maintain ESPeasy if there is anyway to speed-up the data acquisition.
When I used to play around with PIC micro-controllers, they would perform an ADC in 10us.

Kind regards from David.

TD-er
Normal user
Posts: 1125
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Joystick - buggy - rules??

#6 Post by TD-er » 12 Aug 2018, 21:53

Well, I happen to 'know' at least one of those guys from ESPeasy ;)

I am working on changing the way how timers are working in ESPeasy and one of the things I want to make is a general GPIO handler that will run a much higher sampling speed. Only this is for (all) GPIO pins to detect changes, not for sampling.
I think it will be hard to perform tasks in ESPeasy with require some real time deadlines to perform tasks.
It is something I really like to achieve, but with 1 core and a lot of tasks sometimes blocking for over 100 msec, it is quite hard to even run the 10/sec task at 10 times per second.

The A/D converter in the ESP isn't that accurate by the way and since it is processing an analog value, you should also think of some hysteresis window in which you will consider a value to not have changed. This may require more than just the "last" sample.
I guess you should keep the last value that was used to decide it is a new value and keep comparing against that one. Or else a very gradual change in values will go unnoticed.

User avatar
dynamicdave
Normal user
Posts: 54
Joined: 30 Jan 2017, 20:25

Re: Joystick - buggy - rules??

#7 Post by dynamicdave » 12 Aug 2018, 22:14

Thanks for your feedback - which I do appreciate.

I should have edited the text I sent to ZenOfMud (about his ESP Display Home - node management project) on Discourse before I posted it here.

I realise you are one of the key players working on ESP Easy.

I've been using ESP Easy and Wemos D1 Minis for over a year with the students on my after-school IoT Computer Club - great fun.

Thanks for all your hard working making ESP Easy what it is today.

Regarding the joysticks - I'm probably getting too pessimistic about the MQTT bandwidth.
It will be interesting to see how the buggy - oh I mean robot behaves when the joysticks arrive from China.

Cheers from David

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests