Rather than the stepwise adjustment, you may want to consider using square root. The attached image shows the plot from -1 to 1 and the code that preserves the sign of the square root of the input number.
Greg McKaskle
Rather than the stepwise adjustment, you may want to consider using square root. The attached image shows the plot from -1 to 1 and the code that preserves the sign of the square root of the input number.
Greg McKaskle
Thats a really smart idea that I hadn’t thought of… I’ll definitely try it out at our next build day!
Just in case though, so I can have more to play around with, would someone mind explaining to me how to fix the pic above? I know the orange wires are double/numeric values and the green wires are boolean values, I just don’t know how to set up an if-then-else-if sequence
EDIT: Also, another question… Whenever I deploy code OR build the code, I get this pop-up every single time. I don’t really understand what it means, but I just click okay and it deploys/builds perfectly fine. Should I just leave it alone or should I do something to stop it from popping up? (attached pic)
The red X with the arrows pointing in away indicates no source on the wire. You have the wire going between two data consumer with no data source. If you hover over the X or use the context help window it will give a similar explanation.
To fix one of the cases, the code for 1.5X joystick is always wired to the motor, but you really want it wired to the <0.4 selector. And the multiply has a 1.5, but it doesn’t have the joystick value wired to the other input. Branch the wire at the <0.4 and hook that up to the multilply as well.
The deploy dialog is an overly alarming dialog. You are doing it correctly, confirming that you intend to stop the program already running and start the new one you are deploying. You may want to consider using the Run button on RobotMain. This will do a debugging deploy and allow you to breakpoint, probe, highlight, look at panels, and get a much better understanding of how your code executes. Build and Run as Startup are only needed when you are finished debugging and writing code.
Greg McKaskle
What this is doing is trying to override the current code loaded on the cRio. Any time you build and run as startup to the robot, this dialog should pop up any time you are trying to redeploy to the robot. It is completely fine to just hit ok
So I’m trying to modify our drive system. I tried just plugging the output into a sqr-root vi and that into the drive system vi, but as soon as I enabled the driver station, the wheels immediately turn. I’m pretty sure it’s vecause it’s trying to take the sqr root of 0, so I’m trying to code it so that it’ll work for everything, however I’m still confused how to do if-then-else statements in LabVIEW
I attached a picture of my attempt to make it work for positive and negative numbers (but still have not set it to “if == 0, go straight to drive system vi”)
Also I’ve heard something about case structures for if-then-elses, not the “select” vi, but I’m not sure which to use how to use either one…
Thanks for the help!
Taking the sqrt of zero shouldn’t really cause an issue. You may find it useful to probe the wire you are sending to the motor. And if you are not comfortable with it, you can copy and paste the code to another VI that runs on the host and plot it as I did a few posts above. For the task you are looking at, the Sign and Absolute value functions are pretty handy.
Greg McKaskle
Instead of setting the motor speed to a certain percentage of full speed, is there a way to set the (CIM) motor to a certain RPM?
Also, I want to make it so that when button 5 is pushed pushed down, the axis 2 and 4 inputs (going into the arcade drive vi to move the robot’s drive train) are multiplied by 0.25
In other words… when Left Bump is held down, the robot moves and turns at 1/4 normal speed
In order to do this, do I need to set a simple boolean to Button 5 and then check the VI over at the axis inputs for the Arcade Drive VI, do I check button 5 directly, or what? I guess this is yet another if-then-else scenario I need to add to the axis inputs… And they still confuse me
So for them, do I need to do Case Structures or Select VI’s? And is there a tutorial for simply making a ton of if-then-else-if statements chained together? All the tutorials I find are introductions to labview, not about anything specifically like what I’m looking for
The motor controllers you are dealing with are not aware of the type of motor and have little ability to measure how fast it is turning. It is possible to use CAN and a Jaguar motor controller, connect a motor and an encoder or other rotation sensor, and then you can get the Jaguar to do the speed control to get to motor to a given RPM set point. You can also do this in the cRIO, but at a somewhat slower speed. You still need an encoder and you need to use a control block such as PID or implement a simple bang-bang controller.
Selects and Case Structures are very similar. The biggest difference is that using a Select, all code is actually executed and the selected answer is propagated downstream. With a Case, only one of the Case statement diagrams is executed.
If you find yourself nesting too many expressions – in any language – there is often a more concise way to code it so that it is more readable. But this is a learning experience, so do it in whatever way lets you express what you want as code. Experiment with alternative ways of writing equivalent code, and before long you will develop your preferred coding style for this sort of thing.
Greg McKaskle
Thanks yet again
I’ll forward the RPM stuff to our coach. The reason we were thinking about it is to keep the same RPM rather than a percentage of the motor speed (which would change as the battery dies)
As for the case and select vi’s, I think I understand what you mean. And for the situation I mentioned about slower movement, I should just be able to use a case structure. Would you happen to have a picture of an example Select Vi?
We had a huge issue today. Spent a good half hour to an hour trying to figure it out and still never got anywhere, AND apparently last year’s programmer never could figure it out either. We have a window motor (for our shooter) that I programmed simply:
Button x: if true, set motor output to 0.4 / if false, set motor output to 0
Button y: if true, set motor output to -0.4 / if false, set motor output to 0
I used case structures for both and copy/pasted the first one made and just added the (-) sign. However the issue is that only one of the two Case Structures will work! Say (ex) initially, Case A is +0.4 and Case B is -0.4. Case A will move the motor but Case B won’t do anything at all. Then I switched the signs and Case A will move the motor the other way, but Case B still wont do anything. Switching buttons didnt make a difference. If I delete Case A, THEN Case B works, since there’s no other Case in its way.
I tried it both with one and with two RefNumRegistry Get vi’s but that didnt make a difference either.
Pics of the cases attached. The FALSE sides are identical to the TRUE sides, except the number is 0 instead of +/-0.4
Triple click the Boolean wire coming from the Button. Delete it and rewire it. I suspect that you have one wire that just looks like it comes from 11 and another that comes from 12.
I again encourage you to have fewer icons to set the motor output. If you know that you will set it, just not sure what value, only make the value selection conditional. Code as you have written it has a tendency to evolve to the point where it is accidentally setting the same motor to 2, 3, or 5 different speeds during a single teleop frame. The winning speed is who went last, and it seems possessed.
I attached an image, definitely feels like I’ve drawn it before, that demonstrates what I mean. Note that in the case both buttons are pressed, you have to declare what to do. I chose to sum the speeds and the motor will not run. That may be a bad idea, but you have to decide what to do in that case.
Greg McKaskle
They’re both working fine. The problem is that one of them does something first, and then the other one immediately does something else, so what the first one did never has a chance to make itself seen.
What you’re trying to do is easy, just not with parallel Case structures like that. Greg’s code is simple, quick to implement, and hopefully easy for you to understand.
yeah, using select vi’s instead of case structures worked perfectly, and is easier to understand ^^ And somewhat ironically, as soon as I checked that the Select vi’s worked here, I went and programmed an addition to our drive system using a case structure, which worked fine. (I set it so that when a button is held down, to multiply the axis output values by 0.25 so we dont have to jerk the controls when aiming for a shot)
Thank yall so much for all the help. It really has been a huge help not just to me but our whole team. We now have a (theoretically) finished drive system and shooter. Now I’m about to start looking into pneumatics and what not for our climber, and camera, sonar, etc stuff for a tracking system
I do have one question, though not about that: I know that when I DEPLOY the LabVIEW code to the robot, I can use the Front Panel to read indicators and what not. However, when I BUILD the LabVIEW code onto the robot, is there any way to read the axis/button outputs (whether by using the front panels or sending something to the driver station program)?
The dashboard shows a few values from the robot by default. It shows two joysticks with 12 buttons and 3 axes. Below are four graphs with the four motor outputs.
If you want to display more, make a dashboard project from the template, add the indicator to the Operation tab, name it the same as the SmartDashboard variable.
Then on the robot, in appropriate location, write the value to the SmartDashboard variable of the same name.
Greg McKaskle
Okay so we finally got our Axis M1011 camera in and today I’m trying to do as much work as I can for it. I set it up with the Axis Camera Setup Tool and read the three whitepapers I found (1, 2, and 3) so now I have a pretty good understanding of how it works. I DON’T know why I need to use RoboRealms (though I’ve heard that I do), and I don’t know how to get started coding our tracking system into the LabVIEW project.
Is there one specific thing I could start with and build up from? For example, when I was just starting to work on coding the teleop and was completely lost, I started with the drive system (since that’s simple) and worked my way up.
EDIT: also, is there a way to control how far a window motor turns? I currently have our window motor set for when x is true, it goes forward, and when y is true, it goes backwards, but i’d love to say “when x is pressed, go forwards __ degrees, then go back the same amount”
To your first question, you have a number of ways to process images. One of those involves running RoboRealms on your dashboard or driver station computer and sending data to the robot. Others involve running LV code in your dashboard or running LV code on your cRIO.
To the second question, the window motors do not have a feedback mechanism. If you add a potentiometer or an encoder, possibly a limit switch in some cases, you can know how much they have turned. But the motors can’t do that automatically, you have to build it.
Greg McKaskle
We don’t really need any image output on the drive station. We JUST want the tracking algorithm. So do we still need RoboRealms if we dont want the output on the driver station?
For the window motor, would my best bet be to say “go forward at x speed for y seconds then go backwards at same speed for same seconds.” and then just play around with it to get it the right speed/time?
My comment was about image processing for targeting. There are different ways of doing this with different tools. Look through the white paper links, though I’d suggest doing 3, then 2, then 1. Experiment a bit if you like, and decide on a tool you’d like to start with. You can always try another if you still have time.
Greg McKaskle
I’m trying to figure out how to wire “-1 for 250 miliseconds, then 1 for 250 miliseconds, then 0/nothing” into a Set Motor Output vi’s output node, but I’m not sure how. Which Vi(s) should I use? I’ve found Timed Sequence as well as all different kinds of Wait and what not
You don’t mention whether this is for autonomous, teleop, or more general. I’ll give some options and try to explain the tradeoffs.
In autonomous, no other code is running, and there is no need to return to the scheduling code. This means that your code can be written the simplest. You can use a sequence and in frame 1, Set Motor to speed S1 and delay with D1 in parallel. Frame 2, Set to speed S2 and Delay with D2, etc. You can generalize this to use a loop and an array of S1, S2, S3, and D1, D2, D3 if you want to.
In teleop, your code needs to return to the scheduler every 20ms or so. The delay block prevents this until the delay is over, meaning that your joysticks will be frozen for a few seconds. The way to code this in teleop code is not obvious, but a trick well worth putting in your tool chest. It is called a state machine. You code it by Setting the motor and noting when you started it. You update the state to Running A and let the function finish and return to the scheduler. Each time teleop is called, you check to see what state you are in. If in state A, you compare the current time to start time to see if 0.25 seconds have passed. If not, leave it alone. Once 0.25 seconds have passed, you change the motor speed and set the state to B and let it return. B does the same time compare and eventually goes to state C where it stops the motor.
The third option is to put the code into Periodic Tasks and let auto and teleop communicate to it. When in Periodic Tasks, you can write it simply, like autonomous, but you put it in a mechanism loop so that it is started/stopped/canceled by a global or other communication mechanism. This is actually the approach I’d generally recommend, and I attached an image of the general code that would be pretty easy to duplicate and set to other mechanisms. The other case handles stop and delays for 20ms. Look through the code and see if you see any issues or have any questions.
Greg McKaskle
That’s very helpful, thanks! I’m trying to copy that into my periodic tasks but I don’t recognize a few of those VI’s. What is the array looking thing on the left? and the Start and Mechanism Op VI’s? Also, I put it inside a While loop, but I don’t see the slot at the top where “Go” is in your picture either
Thank you very much for the help
EDIT: i compiled a video of our progress so far. Everything coded in the video has been done with your help here and I just want to thank you very much! Here’s the video if you’d like to see