Home→Forums→MonoBrick EV3 Firmware→controlling the engine
- This topic has 13 replies, 3 voices, and was last updated 10 years, 3 months ago by Anders Søborg.
-
AuthorPosts
-
September 8, 2014 at 16:04 #4810
Roy TorenParticipantHi,
As part of a project I need to make the engine work until it gets to a specific position and then again
(A rubiks cube robot)
one arm needs to flip the cube and return to its start position.
the basket where the cube sits needs to turn 90 degrees again and again.
Is there anyway to make this happen without the SetPower or SetSpeed functions as they are unreliable because the power of the battery changes constantly.Thank you,
September 8, 2014 at 16:56 #4813
Tcm0ParticipantYou can either go with the “GetTachoCount” function (http://www.monobrick.dk/MonoBrickFirmwareDocumentation/class_mono_brick_firmware_1_1_movement_1_1_motor.html) or with the PID class (http://www.monobrick.dk/MonoBrickFirmwareDocumentation/class_mono_brick_firmware_1_1_movement_1_1_position_p_i_d.html). You can find more about PID at wikipedia: http://en.wikipedia.org/wiki/PID_controller.
September 8, 2014 at 17:55 #4816
Anders SøborgKeymasterHi
From the documentation that Max already pointed to there is a function called speedProfile which lets you move to a position. An example of this is shown here. Please let us all know how work with your cube solver…
/Anders
September 8, 2014 at 20:10 #4821
Roy TorenParticipantI have tried using “GetTachoCount” but it didn’t do the job.
I have searched through the documentation and found a few things that I think can work.
the first one is the PID although it seems a little tricky.
the second one is the vehicle in:http://www.monobrick.dk/MonoBrickFirmwareDocumentation/class_mono_brick_firmware_1_1_movement_1_1_vehicle.htmlI saw that there was a function that uses degrees and percentages as input, I think it would be best because then there wont be any error range, like when you try to control the engine speed or power(does not rely on battery power)
I want to hear your opinion about the second one since I got an answer for the first option.
Thanks.
Ps.
I added a picture of the robot so you guys could see.
The design was adopted from this site:
http://mindcuber.com/mindcub3r/mindcub3r.html- This reply was modified 10 years, 3 months ago by Roy Toren.
Attachments:
You must be logged in to view attached files.September 8, 2014 at 20:44 #4831
Roy TorenParticipantI forgot to mention and I can’t edit now.
I have also tried the speed profile, it works for a while but after the 10th turn with the hand robot there is starting to be an error range, that gets bigger with time.
I have to be as accurate as possibly can, the speed profile and power profile are not reliable since they rely on the engines power at that specific moment.
I have also tried leaving the battery charging while running the program and the error range keeps on coming.September 8, 2014 at 20:51 #4833
Tcm0ParticipantAs I said, PID is probably your best guess or at least the most acurate.
It seems that you use the NXT color sensor and not the EV3 one. In that case the first link from the other topic to the RGB mode would be right (:P to Anders).September 8, 2014 at 21:00 #4834
Roy TorenParticipantI have read a little bit more about the PID.
I Have some questions about it:
the first one is what values should I enter in this function :
Position PID (Motor motor, Int32 position, bool brake, sbyte max Power, float P, float I, float A, int seattle Times)
(What is the position?, settle time?, P,I,D ?)The second question is how do i use it in my code, assuming my motor is connected to output A.
And as for the color sensor, which one of them is the NXT and which one of them is the EV3? I have posted two pictures of different ones.
can you please answer me in the topic?
Thanks- This reply was modified 10 years, 3 months ago by Roy Toren.
September 8, 2014 at 21:49 #4839
Tcm0ParticipantSorry, but I havn’t used PID so far :/ http://www.inpharmix.com/jps/PID_Controller_For_Lego_Mindstorms_Robots.html gives a good introduction. There are also calculators avaible to calculate the PID. But maybe you’d better google before asking me as I don’t know so much about PID.
September 8, 2014 at 22:27 #4840
Anders SøborgKeymasterHi
Have a look at this example. You might need to tune the P, I and D values to get the desired response…
/Anders
September 9, 2014 at 07:12 #4841
Anders SøborgKeymasterHi
I am actually a little puzzled by this. I think the reason that you are getting an error over time with the speed Profile is that you are suffering from gear backlash and not that a speed profile is not precise (since it moves to the desired position each time). If in fact that you have an error over timer due to the fact that the motor moves to the wrong position (tacho count) then a simple reset of the tacho should be enough. Could you please provide some more details on why the speed profile is not good enough?
/Anders
September 9, 2014 at 09:21 #4842
Roy TorenParticipantThe PID works alot better with the testing I have done.
I have configured it like this:
PositionPID PID = new PositionPID(motor, 360, true, 50, P, I, D, 50);I left the P I and D the same as in the PID example since I don’t really know what they do, i guess 360 is a complete circle of the engine since it keeps coming back.
I also need the engine to go in reverse(with the engine) in PID, is there anyway I can do that?As for the speed profile, I used it and it is probably the backlash, due to the fact that the engine is turning a cube so there is alot of friction and power involved.
The speed profile does work, but the second it starts to make an error it does not fix it unlike what i have seen until now with the PIDSeptember 9, 2014 at 10:33 #4843
Anders SøborgKeymasterHi
I also need the engine to go in reverse(with the engine) in PID, is there anyway I can do that?
Try with minus in front of the target position
/Anders
September 9, 2014 at 11:08 #4844
Roy TorenParticipantI have tried using it like this:
PositionPID PID = new PositionPID(motor, 360, true, 50, P, I, D, 50);
PositionPID revPID = new PositionPID(motor, -180, true, 50, P, I, D, 50);but it didn’t seem to do the trick, the engine only does the 360 command.
I am aiming for the arm that flips the cube to start on the cube and then do the flip(that’s the 360)
but then I want the arm to leave the cube and go up a bit without flipping it again(that’s why I need to reverse the engine)September 9, 2014 at 17:21 #4845
Anders SøborgKeymasterHi
I think that you are doing something wrong. The code below works fine…
using System; using MonoBrickFirmware; using MonoBrickFirmware.Display.Dialogs; using MonoBrickFirmware.Display; using MonoBrickFirmware.Movement; using System.Threading; namespace MonoBrickHelloWorld { class MainClass { private const float P = 0.8f; private const float I = 1800.1f; private const float D = 0.5f; public static void Main (string[] args) { Motor a = new Motor(MotorPort.OutA); PositionPID PID = new PositionPID(a,1000, true, 50, P,I,D, 500); PID.Run().WaitOne(); LcdConsole.WriteLine(a.GetTachoCount().ToString()); PID = new PositionPID(a,-1000, true, 50, P,I,D, 500); PID.Run().WaitOne(); LcdConsole.WriteLine(a.GetTachoCount().ToString()); } } }
/Anders
-
AuthorPosts
You must be logged in to reply to this topic.
Follow