HectorMB Posted April 24, 2022 Posted April 24, 2022 Hello everyone! After expending a couple of afternoons trying to find a solution, I have to ask is someone among you can help me. The situation is easy: I have a motor and I want to limit its rotation. Asuming that the starting angle is always 0, lets say I want to allow the motor to rotate between +/-180º. I found one solution (which is making a loop that allows move when the angle is below 180º, but the issue is that once reached the limit, the loop is finished and no move is then allowed. Is there any function to easely limit the rotation of a certain motor? All help or feedback will be more than welcome! Thanks a lot! H. Quote
Lok24 Posted April 25, 2022 Posted April 25, 2022 If you turn backwards and the - 180° is reached you have to allow forward turning only. What programming tool do you use? Quote
HectorMB Posted April 25, 2022 Author Posted April 25, 2022 I am making it with the standard Powered UP App (sorry, I am quite naive programming-wise). Quote
Lok24 Posted April 25, 2022 Posted April 25, 2022 Thanks, no problem at all. The way LEGO does: The limitation is given by mechanical(!) stops. Then when starting the programm it moves the complete range (calibration) and from then it uses onle that range. Is that a solution for you, i.e when steering a car? Or would you learn programming with explicit blocks like "loop" and "if" ? And: what is the input for you program, the angle or the speed? Is there a picture of what you have now? Quote
HectorMB Posted April 25, 2022 Author Posted April 25, 2022 Thanks for the help! :) Indeed I am trying to program a MOC which, by now, it doesn't have a mechanical stop and it is a requirement that, when it is switched ON the motor is at a certain possition. My idea was to program with blocks, yes. And the input is the angle. When I arrive home, I will post some descriptive pics of the MOC and the program that I have so far. Quote
Lok24 Posted April 25, 2022 Posted April 25, 2022 Ok, then we'll find a way you just have to delmit the values between -180° and 180 I'll wait for the pics.... Quote
GerritvdG Posted April 25, 2022 Posted April 25, 2022 The code block TachoMotorSpeedPosition is the one you need, see @kbalage documentation for more information: https://racingbrick.com/powered-up-code-block-guide/ Search the guide for 'TachoMotorSpeedPosition' and click on the + icon for full documentation. Does this solves you problem? Cheers, Gerrit Quote
GerritvdG Posted April 25, 2022 Posted April 25, 2022 Of course you also need to create a program, maybe I can make something if I have some time left… Quote
GerritvdG Posted April 25, 2022 Posted April 25, 2022 This is a simple PoweredUp program You need to create three buttons (1, 0, 2) that in this examples moves moter A to a certain position -180, 0, 180 with speed 50 Quote
HectorMB Posted April 25, 2022 Author Posted April 25, 2022 While I was heading home I just came up to an idea for my issue. So: -I wanted to have a button that, when pressed, returns the bed to the original possition. For convenience, I also introduced a "reset button". I didn't find a solution in which this button and the rotation control of the bed are both active at the same time. So, I had to introduce a switch that blocks the rotation and then allows the "return to original possition" button to work. Is not perfect, but it works. -The idea that I came up to set limits to the roation of the bed is, as you see, two consecutive "IF" that only allows to continue when the angle of the motors is lower or higher than 260 or -260º (which is the converted angle after the gearing in the model that corresponds to 90º). As you can see in the video, it works... more or less. To avoid blocking the program because overpassing the set limits, I set a difference for the limit and the possition to which it returns when the limit is thresspassed. Unfortunately, this causes a "negative movement" caused by continuous attemps of rotation if one keeps trying to continue the rotation of the bed. As I said, I am very naive at programming and I am sure that are better and easier solutions than this one, but well, i tried! :) Has someone any alternative to the issues (the need of a swich for the "return to original possition" button and the bed control, the limits of the rotation themselves, and the "negative movement" in the solution I drafted)? https://bricksafe.com/files/HectorMB/public/diverse/JCB 6t test.mp4 PS: Please, I am very sorry if the descriptions are not very clear. As I said I am not familiar with the language to speak about programing and so on. Please, speak up if they are not understandable at all and I will do my best to re-phrase :) 2 hours ago, GerritvdG said: The code block TachoMotorSpeedPosition is the one you need, see @kbalage documentation for more information: https://racingbrick.com/powered-up-code-block-guide/ Search the guide for 'TachoMotorSpeedPosition' and click on the + icon for full documentation. Does this solves you problem? Cheers, Gerrit Thanks! Indeed I knew about this block, but when you mentioned I though that I could use it. 11 minutes ago, GerritvdG said: This is a simple PoweredUp program You need to create three buttons (1, 0, 2) that in this examples moves moter A to a certain position -180, 0, 180 with speed 50 THANKS! :) I see that I was not very sucessful explaining the problem . Is not that I want to have thre fixed positions, but to have free movement within certain max and min values. Quote
GerritvdG Posted April 25, 2022 Posted April 25, 2022 Maybe this is better, it turns the bed clockwise and counterclockwise with the joystick and returns to center when the joystick is released. But I'm not sure if you want the return to center functionality.... Quote
HectorMB Posted April 25, 2022 Author Posted April 25, 2022 Thanks a lot @GerritvdG! The advantage of your program is that the bed doesn't tremble. On the other side, as you pointed out, it returns to the center as the joystick is released... which is quite unconvenient. The idea is to hold a possition in rotation and then go up and down, but keeping the rotation position. I am still squeezing my brains to find a good solution! :) Quote
Jayden Posted April 25, 2022 Posted April 25, 2022 Is this what you are looking for? the slider is set not to return to center Quote
HectorMB Posted April 26, 2022 Author Posted April 26, 2022 That's exactly what I think I need! Indeed, before using joysticks, I was trying them, but as I couldn't find a way to plip them to horizontal, I used the joysticks. I have implemented the program quite significantly (I will post the pics and a new video with the performance, which I think it will gain with the sliders). The question now is: doeas someone know if it's possible -and how- to rotate the sliders to horizonal? Thanks you all for the help!!! :) Quote
GerritvdG Posted April 26, 2022 Posted April 26, 2022 4 minutes ago, HectorMB said: The question now is: doeas someone know if it's possible -and how- to rotate the sliders to horizonal? Yes, the horizontal sliders are available standard, you don’t have to rotate them. looking forward to the end result! Quote
Jayden Posted April 26, 2022 Posted April 26, 2022 7 minutes ago, HectorMB said: That's exactly what I think I need! Indeed, You are most welcome. 7 minutes ago, HectorMB said: The question now is: does someone know if it's possible -and how- to rotate the sliders to horizontal? Just scroll down a bit, if you hit the dials you have gone to far. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.