Recommended Posts

Apologies if this is in the wrong section, but I'm having a spot of bother with a custom controller I've been working on in the PUp app and wondered if anyone could provide some insight.

I'm attempting to control two Technic L motors using what I believe is referred to as the City Hub (PN:88009). The custom controller does not control them directly but rather calculates the necessary power level based on a single input. I wanted to use the Set Motor Speed block as this would ensure the accuracy of the function, but this doesn't seem to be working as I expected it should. The motors respond correctly to the first button press but then the program appears to freeze and the motors will not respond to any other input. After a few seconds of this the hub disconnects and the motors stop. I did wonder if there was an issue with the hub reading the inputs from the rotation sensors, but that doesn't seem to be the case because I can get the controller to display motor speed satisfactorily. For the time being I'm using the Set Motor Power block instead which works fine, but it's not the solution I really want.

Is this a bug in the app, a limitation of the hardware/software or some other issue? I'm running the app on an iPhone 8 Plus and wondered if it could be the cause of the issue.

Please bear in mind that I am neither an electronics nor computer expert, so please don't baffle me with science. I'm just hoping that there is a simple answer that will avoid the need for a long and complicated workaround in the custom controller.

Share this post


Link to post
Share on other sites

@Hod Carrier

I believe the app gurus here would like to glance over your program as it seems to be a more serious thing as the app essentially crashes, right? It initially responds correctly and then it doesn't respond anymore, and then it looses connection. May there be a hidden endless loop or the like? When you don't press anything, but just wait for a while and then press the button, this works, right?

Also, when you press the button once and then you don't press anything anymore, does it still disconnect?

Best
Thorsten

Share this post


Link to post
Share on other sites
16 hours ago, Tcm0 said:

Can you post pictures of the program and the model?

Apologies. I didn't want to waste a lot of people's time doing all that if the answer was as simple as "this is a known issue with the app" or "it won't work with that combination of hardware". I'll have to get some screenshots done when I get a moment.

17 hours ago, Toastie said:

@Hod Carrier

I believe the app gurus here would like to glance over your program as it seems to be a more serious thing as the app essentially crashes, right? It initially responds correctly and then it doesn't respond anymore, and then it looses connection. May there be a hidden endless loop or the like? When you don't press anything, but just wait for a while and then press the button, this works, right?

Also, when you press the button once and then you don't press anything anymore, does it still disconnect?

Best
Thorsten

Apologies to you too, as I think my opening post isn't as clear as it should have been.

As you probably have guessed, it's a train controller that I'm working on which uses three variables; train speed (set directly using buttons) and motor speed/power inferred from the train speed. I've put three dials on the controller to monitor these variables. When I start the controller it remains stable and the bluetooth connection is maintained. When I start the motors after pressing to increase or decrease the train speed the motors will begin at their first speed position, but after that they will not respond to the app. However, the controller continues to work on my phone because the indicated values for train and motor speeds continue to rise and fall as intended in response to the buttons. Throughout this, the app itself does not crash and the controller does not freeze or stop working, but after a few seconds the motors will stop and the bluetooth connection to the hub is lost.

Subject to checking, I don't think that there's any issue with the code. If I substitute the Set Motor Speed block for the Set Motor Power block and leave the rest of the code exactly the same the controller works perfectly; it's just when I use the Set Motor Speed block. There are no loop expressions except for those that control the dials and the motor inputs, as per the examples on @kbalage's YouTube tutorials.

Share this post


Link to post
Share on other sites

First i would like to promote these two threads:

I would recommend the first thread for help requests. The second is more intended to collect working code.

Regarding the issue you are facing: We can help you best, if you post a screenshot of at least the code in question (if you don't want to publish the whole code for whatever reason). From what i have read, it seems that you are missing a loop. But that's hard to say, until you post a screenshot. If you don't know how to post one then let us know.

 

 

Share this post


Link to post
Share on other sites
8 minutes ago, Andman said:

it seems that you are missing a loop.

@Hod Carrier - first of all: No need to apologize! You had a question, which raises more questions - that's the fun of it!

What @Andman said makes really sense - it came to my mind when I was walking the dog this morning :). I could be that you branch off into a dead end, which then terminates the program ... could be. We'll see. Very interesting issue!

Best
Thorsten


 

14 minutes ago, Andman said:

I would recommend the first thread for help requests. The second is more intended to collect working code.

Very good idea - however, shouldn't these two threads not be here, in the Mindstorms and Robotics forum? Just asking.

Best
Thorsten

Share this post


Link to post
Share on other sites
23 minutes ago, Toastie said:

Very good idea - however, shouldn't these two threads not be here, in the Mindstorms and Robotics forum? Just asking.

Powered Up as a hardware platform might be related to Mindstorms and robotics, but the app is more related actually to the current Technic offerings since Mindstorms has its own app environment that is independent from the Powered Up app.

@Hod Carrier as others said, posting a screenshot would definitely help more than a long explanation. It makes it much easier to troubleshoot your code and also to replicate it on our devices and test it. It can easily be a bug, because what you describe is definitely not a standard behavior. 

Share this post


Link to post
Share on other sites
4 hours ago, kbalage said:

as others said, posting a screenshot would definitely help more than a long explanation. It makes it much easier to troubleshoot your code and also to replicate it on our devices and test it. It can easily be a bug, because what you describe is definitely not a standard behavior. 

Yes of course, and I do understand. As I mentioned, screenshots are coming just as soon as I get an opportunity, hopefully by tomorrow. It’s just that I don’t have a lot of spare time at the moment to devote to hobbies at present. 

Share this post


Link to post
Share on other sites

First I see is that you are always using local variables. That means they only exists inside each code block. Other code blocks cannot "see" them. Have you tried to use global variables? Nevermind, i re-read the definition for local and global variables again. What i wrote before does not apply here. In the meantime I'll clone you code on my end and will test things.

Could you please also share a screenshot of the controller layout in edit mode so we can see the widget numbers. Make sure the resolution is good enough. Some things on the screenshots above are hardly visible.

 

Edited by Andman

Share this post


Link to post
Share on other sites

.. and which icons are replaced bay others for working/not working?

Share this post


Link to post
Share on other sites

My earlier comment about local and global variables is obsolete. Had a wrong understanding.

Share this post


Link to post
Share on other sites
11 minutes ago, Lok24 said:

.. and which icons are replaced bay others for working/not working?

If I use Set Motor Speed for the tacho motor I get the behaviour outlined above. However, the controller works fine if I substitute it with Set Motor Power. The program shown above is the non-functioning version but is identical to the working version except for this one block.

7 minutes ago, Andman said:

My earlier comment about local and global variables is obsolete. Had a wrong understanding.

Thanks for checking, though. Your help is appreciated.

Share this post


Link to post
Share on other sites

On my end the code for widget button 1 is often buggy. It often adds up 10 only one time. Some times, after bulding that code structure it works and adds 10 after each click on the button. That's the first issues i experienced. Can you exclude that code suffers from that issues?

Share this post


Link to post
Share on other sites

Is it conceivable that the loop, in which the set speed command is embedded, is adversely affecting the program? You need to create such a loop for sure to react to changes in the speed setting, but the code behind these blocks is rapidly cycling through this loop, even when there are no changes in the speed value, right?

My question to the gurus here is: Is the SetSpeed command executed each time the loop is encountered - or is it executed only when the speed value actually changes? The latter could also be done in code, should the SetSpeed command behave badly when simly called too often. After all, the PID parameters have to be reset etc.

I have a very simple program here that consists only of Start, define ramp_up_time, define ramp_down_time and then: loop{SetSpeed to constant value}. From the flickering of the block during execution, it appears as if the command is invoked (with constant speed value) each time the loop is executed. The program then does exactly what @Hod Carrier is reporting: It runs for a while, then stops and disconnects from the hub.

When I do this: Start, define ramp_up_time, define ramp_down_time, SetSpeed to constant value (called only once), and then loop{forever} - the program does not crash.

Big difference with the set power command, as this can be called as often as you want - it just sets the PWM ratio. With PID control though, things may go bad when called too often. As judged from what I learned when I coded PID into the RCX, that is. Things here may be very different!

Best
Thorsten

P.S.: I just noticed that when the SetSpeed command is directly in the loop (i.e. executed every loop), it flickers initially, then stops doing that (motor still runs) then after a couple of seconds stops and disconnects from the hub.  

Edited by Toastie

Share this post


Link to post
Share on other sites
4 minutes ago, Toastie said:

but the code behind these blocks is rapidly cycling through this loop, even when there are no changes in the speed value, right?

Correct. The loop runs constantly since there is no condition set, which could start or stop the loop.

5 minutes ago, Toastie said:

Is it conceivable that the loop, in which the set speed command is embedded, is adversely affecting the program?

Actually no. The loop is only receiving and does/should not interfere with the rest of the code.

7 minutes ago, Toastie said:

or is it executed only when the speed value actually changes? The latter could also be done in code,

I think that could possibly reduce battery drain, since the loop would not run constantly. But I don't know how much energy it consumes. I have similar code and my phone battery is drain quite fast. But ion the other hand i have 4 technic hubs connected. Could be worth testing.But that's something for another thread.

 

Share this post


Link to post
Share on other sites
2 minutes ago, Andman said:

Actually no. The loop is only receiving and does/should not interfere with the rest of the code.

 

True, but it fires commands permanently to the Hub, which might  then cause the error.

Idea: add a wait (1 sec, or 0.5 sec or 0.1 sec) into the "motor-loop" for testing, would that change something?

Share this post


Link to post
Share on other sites
Just now, Lok24 said:

True, but it fires commands permanently to the Hub, which might  then cause the error.

Idea: add a wait (1 sec, or 0.5 sec or 0.1 sec) into the "motor-loop" for testing, would that change something?

I agree. May be the BT connections unstable for whatever reason and cannot handle rapid flow of commands.

Share this post


Link to post
Share on other sites
16 minutes ago, Lok24 said:

Idea: add a wait (1 sec, or 0.5 sec or 0.1 sec) into the "motor-loop" for testing, would that change something

Yes that. (I am right in the middle of a video conference which requires some attention (cool research results, I must say!!!)

What should help as well is changing the Speed only, when (new != old) - this will be often the case for trains - folks usually enjoy seeing them run at constant speed, because that implies: Insane torque ;)

Best
Thorsten 

13 minutes ago, Andman said:

I agree. May be the BT connections unstable for whatever reason and cannot handle rapid flow of commands.

Yes, in contrast to SetPower, which has much less overhead, I believe.

 

And on another thought: The ramp_up/down-time data + final speed value (in addition to the PID control routine, which is bolted into the firmware on the hub) is usually is a fire-and-forget piece of code, client-wise (i.e. on the phone): submit ramp times (which can even further expanded to power restrictions, according to the LWP3.0 protocol) once; submit final speed once and then leave the remote server alone and let it do what you were asking for. It then takes care of things - until you want to change speed again.

When using a slider/dial to set the speed setting on my VB6 program, I am using a delay-time to finally read the terminal speed value I am selecting. Otherwise, the slider control fires change_value events as often as the slider value (1 - 100) changes (duh ...) upon sliding - which then calls the BLE stack to issue the SetPower command as often, which in turn crashes the program (OK, it is VB6 ...) immediately.          

Edited by Toastie

Share this post


Link to post
Share on other sites
18 minutes ago, Toastie said:

What should help as well is changing the Speed only, when (new != old) - this will be often the case for trains -

 

Sure, but for testing if this causes the error a wait is easy, and it would be interesting if it differs when changing the values....so what is the lowest value ?

Share this post


Link to post
Share on other sites

I did not know, that I can multitask that well :pir-laugh:

1s delay: Crash (the set power block is permanently high-lighted)

2s delay: Works: The power block is flashing nicely and constantly every 2 s.

Best
Thorsten

Edited by Toastie

Share this post


Link to post
Share on other sites

Thanks, that's pretty long....

I doubt that a old!= new would work in that case, if you trigger rapidly via the UI

Share this post


Link to post
Share on other sites
1 hour ago, Toastie said:

When using a slider/dial to set the speed setting on my VB6 program, I am using a delay-time to finally read the terminal speed value I am selecting. Otherwise, the slider control fires change_value events as often as the slider value (1 - 100) changes (duh ...) upon sliding - which then calls the BLE stack to issue the SetPower command as often, which in turn crashes the program (OK, it is VB6 ...) immediately.

See above ;) Maybe the 2021 PUp world is not that far away from the 2000 VB6 world with an up-to date BLE OCX control ...  

And for trains: See also above :pir-huzzah2:

 

event_handler(new_slider_value):
Wait 0.1 s: new_slider_value = old_slider_value? No: loop. Yes: old_slider_value = new_slider_value: Call (SetPower(new_slider_value))

More importantly: Others need to confirm these observations; these are my very first PoweredUp "programs"!!!

EDIT: It appears as if the time-to-crash (TTC :)) correlates with the wait time - which in turn >may< correlate with the number of calls to SetPower on the hub??? No idea!

Here's the super code:
setpowerloop.jpg

 

Edited by Toastie

Share this post


Link to post
Share on other sites

OK, here's a little update; I'll stop it here, because I believe that @Hod Carrier has really found a nasty bug in the City hub's (2IO) firmware, regarding the SetPower command. Will try the 4IO hub later (whatever its name is - Technic hub or Control+ hub ...)

PUp program used (note that always the same power setting is used):

timetocrash2.jpg

PUp interface used to count loops until crash:

showloops.jpg

Left button: Start program, right meter: #loops

Data recorded:

timetocrash.jpg

Data interpretation:

  • Yes, there >seems< to be an issue with BLE traffic, when going from 0 to 2 seconds delay time, performance improves running time wise, but that is actually "fake" as the #loops to crash are more or less erratically distributed, and I believe when averaging more, the #loops to crash may actually level out.
  • However, when using 5s delay, a very low number of loops is enough to crash the system; this would mean that the firmware may get confused by simply doing the PID job ...

Conclusion:

Either dumb PUp program I used - or really nasty bug in firmware. The latter sounds more reasonable - but who knows. This also explains to me, why I am having a rather hard time in getting stable operation with multiple trains using this command. And I thought it was VB 6 ...

Here is to VB6! :pir-huzzah2::pir-love:

All the best - and code well :pir-skel:
Thorsten

 

BTW: When taking a screen-shot on the cell phone (lower sound + on/off button for some Android phones, as my Moto g8 power) - the PUp app crashes immediately, shows the program page, and disconnects the hub. Initially I was afraid that it would also trigger the hidden self-destruction feature of the LiPo battery in the phone, but that does NOT happen :sarcasm_smug:  

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.