Hello, this year our team will use window motors to control an arm. We were wondering if it is possible to use these reflective sensors to prevent our arm from exceeding a certain climbing limit. Basically, it is prevented from going up after a certain point, and being able to go down if the limit has been reached.
We have already made the control system for the arm motors with the clockwise and anticlockwise control with two different buttons as per another post that helped us here on the forum(ignore that one is the opposite of the other, this is due to one of the motors being fixed upside down, it is only temporary).
If you’re using a Talon anyways (and depending on your sensor) it might actually be easier to just wire the sensor directly to the appropriate forward/reverse limit switch pins on the Talons data port (though I strongly recommend using a breakout board for this). This way your limits should work regardless of if you make a mistake in your code.
That said, though my Labview is a bit rusty, I would think you could also create a fairly simply True/False logic that would take the state of the sensor and allow all motion when it’s not tripped, but only allow motion in one direction when it is tripped. I think the logic looks something like this:
There may be a better/simpler way to do this, but like I said, my Labview is a bit rusty.
The last thing I’ll mention is that if you’ve never used these sensors before, one issue you might run into with these types of sensors is sometimes the sensor itself requires more voltage/amps than the RoboRIO DIO ports can provide. In these situations, I’ve been able to separate the power wires and power them via the appropriate power sources (either PDP, VRM, or other converter as necessary, depending on the voltage required in the sensor spacs) and USUALLY the remaining sensor wire will still provide the <5v range input that the roboRIO can handle. I strongly recommend testing this with a multimeter BEFORE connecting it to the RoboRIO though.
My LabVIEW is horribly rusty, but this was a fun trick back when I did this.
Taking multiple boolean inputs, converting them into a binary number i.e. (00,10,01,11) (boolean array then convert array to binary) than taking those binary representations and using them on a select case structure that only allows direction in the normal working range would be how I approach this. This also allows for the motor to be locked out or other warning if both switches are triggered at the same time. Also provides a handy way in the same logic to include a sensor for “default” should you want to initialize a relative encoder in starting config and be confident in auto.
Example here, all you need to do is feed the sensor inputs into the array and pass your control command through the case structure, case-by-case determining what range of float input values (or boolean button values) are valid:
Hi, thanks for the sensor wiring tips. Our sensor uses 10v to 30v, so we were thinking of using the VRM to serve as an external power supply, while an LM7805 would be connected from the signal wire to the roborio to regulate to 5V and avoid burning the digital inputs (the colors of the sensor wire are not those, I just put it in a generic way). Do you think we are on the right track?
If the brown (signal?) wire is actually outputting 12v like the sensor is receiving, then this approach makes sense. Again though, I would still recommend testing the sensor with a multimeter first as many similar sensors I’ve tried output the standard 3.3v on the signal pin, even if the sensor itself requires more than that, which would make the LM7805 unnecessary.
Otherwise the wiring looks good, power and ground to 12v VRM, signal to DIO.
I think the digital inputs on the roboRIO are already pulled up (it’s an NPN system) and to change the state you need to pull them down to ground with a NPN sensor. It appears the SICK is a PNP sensor so changing the voltage from too high to okay just keeps pulling the DI in the same direction with no change of state.
You may want to consider a 5V sensor like E18-D80NK instead to simplify this wiring to “just plug into a roborio”. Also a lot cheaper. As stated above you may need a 1-10k pulldown to make the logic level work.
Your recommendation looks like it directly connects to the roboRIO (except for wiring an appropriate connector) and that’s what I’d buy or an equivalent one that we found on Pololu.
OP probably got that old SICK for free or the bottom of the junk box. Since they don’t seem averse to minor custom circuits they could get a cheap NPN transistor. There are plenty of YouTube videos about converting PNP to NPN.
Hi, thanks for the sensor warning! we are a rookie team and have never used sensors before so we didn’t even realize the inputs were NPN. I’m still in the first year of the technician, but I’ve already seen some of that logic, so I understood what you meant. I believe the largest is NPN, although I still need to check. if both are PNP, I still need to use them, since here in Brazil sensors are extremely expensive and we only have these (for some reason this circuit I theorized would be cheaper than buying a new sensor ). I just don’t understand yet how to convert this signal to the DIO. maybe I should open a new topic specifically about this in case it’s complicated to explain here
Maybe an electrical engineer can recommend a transistor to use. I’m not much of an electrical type but I’d guess that a cheap (5 cents) low-power one would suffice since you are just shorting almost no roboRIO current to ground and I assume it’s running at 12vdc or less (I hope your sensor runs at 12vdc or less). You aren’t switching a load such as a light or motor.
thanks again for the help. we are studying this material and other external ones. But to verify if it will be really necessary, we believe that this largest one we have is both PNP and NPN. what do you think?
My team has not used this particular device but it appears to be similar to others we do use. I’m concerned that it isn’t measuring what you want to measure. You need to check this. I’m not sure what the learning mode does. Does it adjust the range precisely or is it merely adjusting to the ambient light conditions which vary a lot on a robot driving around an arena?
I think what this sensor does is tell you if something is within its 20mm to 350mm (approximately) range or not. It’s a switch that either sees something “shiny” in the range or it doesn’t see something “shiny” in that range. From my experience the range is approximate and can require some “tuning” for an individual sensor with its variations from the standard published values.
This model may indicate the switch status with a little light or you can use a voltmeter and test that it does work as you expect or need it to work. I’d make sure it’s what you want before expending effort to convert it to NPN.
If you wanted to go the transistor route, you could use a small-signal transistor (BJT or FET) as an inverter; something like a 2N2222 or 2N4401 (both NPN BJTs), or 2N7000 N-channel FET. Either possibility would require a resistor, so you’re at 2 components regardless. The BJT needs a current-limiting resistor for the base (but it can handle its own pull-down), whereas the FET needs a pull-down resistor (or it will never turn off). See the lazy drawing for more details. I got tired of drawing boxes, but if it’s not clear, the G and S mean “Ground” and “Signal” pins of the DIO port on the roboRIO being used as the sensor’s input. Both must be hooked up for this to work properly.
we check it with a multimeter, and the sensor emits a signal when something is within the detection range. the buttons serve to adjust the distance it is able to detect, so it serves as a switch for what we want. for now I’m using limit switch to do the tests we want, although I prefer to use a sensor for that
Thanks for the code tip. I’m not using the sensor yet, but using a limit switch has allowed me to test the logic. Taking your example logic, we produce a similar one. Button 1 allows you to go up, and button 2 to go down. When the arm reaches the limit, it will no longer be possible to go up even pressing the button. The only way to move the arm is to press button 2 to go down, which will depress the limit switch and allow button 1 to go up again.