Shop OBEX P1 Docs P2 Docs Learn Events
RC Submarine - Periscope raising/lowering...? - Page 2 — Parallax Forums

RC Submarine - Periscope raising/lowering...?

2»

Comments

  • Clock LoopClock Loop Posts: 2,069
    edited 2020-10-26 05:11
    Mike27283 wrote: »

    - When I press both button at the same time on the transmitter for channel 6 the servo returns to the neutral (middle) position. If I am pushing one button and the servo is fully deflected and then press the other button (so both are then depressed) the servo returns to the neutral (middle) position.
    Good to know!

    Mike27283 wrote: »
    - Here is the code I developed for flashing the Submarine ID beacon in a realistic manner:
    DO
    DIR0=1
    OUT0=1
    PAUSE 500
    OUT0=0
    PAUSE 500
    OUT0=1
    PAUSE 500
    OUT0=0
    PAUSE 500
    OUT0=1
    PAUSE 500
    OUT0=0
    PAUSE 3000
    LOOP
    .
    Ok, I'll post some code soon. Since i can't find my bs2 programmer cable, i will need to get a new one, so im sorry if I give you code that is untested.

    Mike27283 wrote: »
    - I do like that the way it is being programmed takes advantage of the momentary nature of the channel 6 buttons to stop moving the periscope at any intermediate position.

    - Is it possible to adjust the BS2 code so that the Sub ID Beacon LED is on and flashing whenever the periscope is not in the fully lowered position.
    I assume this would be pretty easy as that routine would monitor the state of the lower reed switch.

    - I have 4 other LEDs that will also be on the submarine (Mast Head light, Port and Starboard running lights, and a stern light on the rudder) - they will all run off of 12V directly from the Lipo 3S battery. Actually - I am installing a 12V on/off remote switch that is controlled by a RF key fob...so I do not have to mount a switch - can we wire the Submarine ID Beacon in a way that it also receives 12V? This may be problematic as we are using the BS2 to control the Sub ID Beacon LED in conjunction with rasing and lowering the periscope. If this is too difficult don't worry about it. I hooked up the LED to 5V and 12V to compare and it is a noticeable differenc in brightness but not a show stopper.
    The 12v led could be operated with a SSR. 6$ A regular relay would work but wear out from repetition.
    https://www.digikey.com/en/products/detail/ixys-integrated-circuits-division/LBA710/2744939
    Easiest connection.

    You could also use a n-channel mosfet to control the 12v led. 1$
    https://www.digikey.com/en/products/detail/infineon-technologies/IRLB8721PBF/2127670
    81087.jpg
    https://forums.parallax.com/discussion/132225/n-channel-mosfet-problem


    Mike27283 wrote: »
    - The leak detection function is a great idea. I'd like an emergency blow to be commanded if a leak is detected. The BLM I have installed will command a blow if the pulse train from the transmitter is lost for more than 6 seconds or if the battery level gets too low. It seems the easiest way to do this would be to provide a PWM signal directly to the ballast tank servo to fully throw it 100% (exactly as it would if the battery got too low or the transmitter pulse train was lost) that would cause the linkage it is connected to to depress the shraeder valve releasing the gas from the small pressurized blow tank into the ballast tank causing the submarine to surface. I'm not sure if it would be a PW less than 1.25ms or greater than 1.75ms...but I can test that and it would be easy to change in the code and reload into the BS2. I would take the output from the BS2 for this function and combine it with the output from the receiver channel 4 output (to BLM to LPB controller) - which all goes to the same ballast servo. Since that is the way it would be wired I assume the BS2 output for that function would be totally dead until needed - then wake up and provide the needed pulse to drive the servo to the blow position. If not the servo would be getting competing inputs.

    To override the receivers signals to the ballast tank, a relay could do the job, it would normally be closed for the receiver ballast channel, and if the emergency blow is activated, it would switch the relay, closing the Normally open contact which would be connected to a bs2 output that pwms the proper rate.


    With RC stuff, an investment in 10 relays that can be operated by 3.3v (if you want to upgrade your cpu to a propeller in the future)
    If you don't already have the relays, you will need them with this project.
    So far I see you need 3 of them.
    https://www.parallax.com/product/27115

    However, those regular relays use LOTS of power.
    You may just want to switch to all solid state relays if that is a possible issue.
    But the regular relay is easy to hook up, its up to you.

    Personally I would purchase a tube of these and keep them around. They are well worth the cost, and actually cheaper than a regular relay.
    https://www.digikey.com/en/products/detail/ixys-integrated-circuits-division/LBA710/2744939

    So what kind of relay do you want to use in this circuit? If you choose a solid state one, it can operate your 12v led also.
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-10-26 08:17
    Take a look at this schematic.

    I used all solidstate relays and they are wired for failsafe,
    so led is off a default and is powered by 12v,
    both periscope motor leads are grounded as default,
    and ballast control is normally closed, so receiver output 4 is normally connected to blm.
    6336 x 4896 - 2M
  • kwinnkwinn Posts: 8,697
    Another option is to use latching relays. They come in all sizes and require no power to hold on/off pos1/pos2, only a short pulse to switch states.
  • Wow - very impressed!

    - I'm fine with the solid state relays. kwinn suggested latching relays (thank you) not sure if that is a better option.
    - I see how U3 and U4 act as a double relay module to change polarity to change motor direction...and U5 is utilized to step the voltage down to 3.3V or 5V - I'll install the one that best matches a realistic raising/lowering speed.
    But - how is the motor stopped and started? Shouldn't the reed switches control U5 via another relay to shut the voltage off so the motor stops when the periscope is at the top or bottom of travel...
    - Conductive rods providing input to P9 and P8 looks good. I do think we need to change the output of U2 though...in normal operation U2 should be set (as depicted) to route the receiver signal from channel 4 (the 5V and ground wires for the BLM servo do not need to go through U2 - they will remain directly wired to the BLM servo) to the BLM servo. IF there is a leak detected (input on P9/P8) then the output from P1 and P2 switch U2 to disconnect the channel 4 signal and instead route a signal from P7 to the BLM servo - the output of P7 would be either 1ms or 2ms PWM to drive the servo to full throw to cause the Schrader valve to be depressed evacuating the charge in the emergency blow tank into the ballast tank thus surfacing the submarine. I do not know if the output should be 1ms or 2ms - when I set it up and do the op test if it throws the wrong direction I'll go in and change that portion of the code to ensure the servo throws in the correct direction. No need to light the Sub ID beacon LED when a leak is detected - unless that is easy to do...
    - I'm confused on the wiring for the Sub ID Beacon LED. It looks like P14 is the input used to detect the full down position and P15 is the input to detect the full up position?
    But how is the LED flashed? It seems the up/down detection circuit should be separate from the flashing circuit. Once the BS2 detects the scope NOT fully down it will start the flashing routine - an output from a pin on the BS2 then drives a relay that controls the 12v going to the LED thus causing the flashing.

    This is great - I am already learning a lot and am excited to finalize the circuit. The code and different routines embedded and how they work are of great interest to me as well and I am sure I will learn a lot - very cool!
  • kwinn wrote: »
    Another option is to use latching relays. They come in all sizes and require no power to hold on/off pos1/pos2, only a short pulse to switch states.

    Latching relays are a good choice for the application.

    Many are available at a good price at Electronicgoldmine
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-10-27 01:30
    kwinn wrote: »
    Another option is to use latching relays. They come in all sizes and require no power to hold on/off pos1/pos2, only a short pulse to switch states.

    I would NOT use latching relays, im pretty sure the overall power usage to latch them are more than most of the combined power all the ssr's use.
    The 1k resistors limit the ssr leds to around 3.5ma when on, perhaps the latching relays are very small like that too, ....

    Also the reason I went with SSR, is two.
    1. the 12v led blinks at a very fast rate (500ms)
    2. The motor cannot be pwm'ed (if you want an even slower periscope speed) with latching relays or regular relays.
    If you use solid state relays, then you can possibly just give the motor full 12v, omit the U5 regulator that wastes power, and just pwm the ssr for the motor at 12v.
    ( we can try this once most of this circuit is wired up)


    Mike27283 wrote: »

    But - how is the motor stopped and started? Shouldn't the reed switches control U5 via another relay to shut the voltage off so the motor stops when the periscope is at the top or bottom of travel...

    The BS2 monitors the reed switches for a logic low, and then turns the motor solid state relay off.
    If the bs2 fails at this job, a physical dead stop should be installed at the top of the travel and the bottom of the travel, to force the motor to stall.
    You COULD use even more relays with a normally closed relay to cut motor power, but that is actually slower than the bs2, and relies on even more mechanical devices.
    And im not sure if they have normally closed reed switches...
    Mechanical devices like regular relays, are going to wear out faster than an ssr.
    Mike27283 wrote: »
    - I do think we need to change the output of U2 though...in normal operation U2 should be set (as depicted) to route the receiver signal from channel 4 (the 5V and ground wires for the BLM servo do not need to go through U2 - they will remain directly wired to the BLM servo) to the BLM servo. IF there is a leak detected (input on P9/P8) then the output from P1 and P2 switch U2 to disconnect the channel 4 signal
    You could just keep that, and not send a pwm signal, like you said when the signal is dead for 6 seconds the emergency blow is activated?
    If you don't want it to wait the 6 seconds, then we will need to send a signal. So we can just wire that signal from any of the free bs2 pins through a resistor like a 1k connected to the 'out to blm' pin on U2 SSR pin 7.
    I can change the schematic if you want that, instead of waiting 6 seconds.

    Mike27283 wrote: »
    and instead route a signal from P7 to the BLM servo - the output of P7 would be either 1ms or 2ms PWM to drive the servo to full throw to cause the Schrader valve to be depressed evacuating the charge in the emergency blow tank into the ballast tank thus surfacing the submarine. I do not know if the output should be 1ms or 2ms - when I set it up and do the op test if it throws the wrong direction I'll go in and change that portion of the code to ensure the servo throws in the correct direction. No need to light the Sub ID beacon LED when a leak is detected - unless that is easy to do...
    Since everything is controlled by the bs2, most of it is easy to do.
    Once you start to bypass the bs2 with direct wired relays, you eliminate your ability to control it with the bs2.
    Mike27283 wrote: »
    - I'm confused on the wiring for the Sub ID Beacon LED. It looks like P14 is the input used to detect the full down position and P15 is the input to detect the full up position?
    But how is the LED flashed? It seems the up/down detection circuit should be separate from the flashing circuit. Once the BS2 detects the scope NOT fully down it will start the flashing routine - an output from a pin on the BS2 then drives a relay that controls the 12v going to the LED thus causing the flashing.
    The grounds on everything can be all combined. This makes having to run lots of wires, less. And with water, the less wires in the water, the less possibility of shorts.
    The power for the 12v LED is controlled by SSR - U2, technically with P1 on the bs2.
    The 1k resistor (R14) for the led assumed a 2v drop and 12v supply making 10ma current. We should test your led to determine the best resistor.


    I forgot to include a fuse for it all, since its all in the water. I would think a 1.25 amp fuse would work on the positive side of the battery(just for this circuit, not all your other stuff like the reciever and servos, etc)
    , I need to read the total power specs on the bs2, and add up the led and the motor.
    Ideally you would wire it all up and measure the peak power draw in current mode on a multimeter while moving the periscope up and down.

    A total system fuse size could be determined by connecting it all and doing movements of all servos and motors etc. (i suggest you do this when you are nearing the completion of it all)


    Fuses may not protect everything, but I have found they protect most things. One thing may fry, which blows the fuse. But with no fuses, one thing fries, which puts that one things pins in a unknown state(shorted), which could "cascade" fry other things down the line, which could keep going, working its way into every device eventually, making the entire system and all components dead.
    Whereas a fuse would have blown open at the initial failure possibly stopping a cascade short.
    I did this with a Parallax Activity board and multiple other devices, the only thing that fried was the prop chip its self because the fuse opened. My motor drive, and all other chips on the activity board were fine.
    If I had no fuse, the prop chip would have smoked and put who knows what out its pins to other devices.
    I simply cut the prop chip off the board, and soldered a new one on. 7$ chip and fuse. Saved over 100$ in other parts, not to mention an entire activity board.
    Never omit fuses even if they blow slower than chips fry.


  • kwinnkwinn Posts: 8,697
    Clock Loop wrote: »
    ...........
    ..............................

    I would NOT use latching relays, im pretty sure the overall power usage to latch them are more than most of the combined power all the ssr's use.
    The 1k resistors limit the ssr leds to around 3.5ma when on, perhaps the latching relays are very small like that too, ....

    I'm not a big fan of mechanical relays, but this might be one of those applications they are good for. It really depends on how much current and time it takes to switch from one side to the other. Not sure about the current draw for a suitable relay, but the switching time is typically in the 10-20mS range.
    Also the reason I went with SSR, is two.
    1. the 12v led blinks at a very fast rate (500ms)
    2. The motor cannot be pwm'ed (if you want an even slower periscope speed) with latching relays or regular relays.
    If you use solid state relays, then you can possibly just give the motor full 12v, omit the U5 regulator that wastes power, and just pwm the ssr for the motor at 12v.
    ( we can try this once most of this circuit is wired up)

    I would never suggest using a relay for frequent and continuous on/off switching. Definitely a job for an SSR or transistor. What I would most likely do for this type of setup is to use a small H bridge module for moving the periscope up/down and a microswitch that is activated by two tabs on the periscope. One tab for up, and one for down, and that signal could go to the H bridge enable or a micro I/O pin.
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-10-27 07:02
    kwinn wrote: »
    What I would most likely do for this type of setup is to use a small H bridge module for moving the periscope up/down and a microswitch that is activated by two tabs on the periscope. One tab for up, and one for down, and that signal could go to the H bridge enable or a micro I/O pin.

    This will be in water, got any waterproof micro switch suggestions? A reed switch with magnet is pretty cheap...
    I just figured dipping a reed switch into a liquid sealer would be easier than waterproofing some mechanical method.
    The op initially suggested reed switch, i figured it was because... water.

    H bridge was my initial suggestion, the parallax motor board for simplicity.
    But then I saw the op only needs .75 amp for motor power.
    I figured ssr's are easy enough, fairly cheap. Single chip(two for motor control), no pcb, etc...
    Plus op is already using a BS2 inside.... (which is a powerful microcontroller)
  • kwinnkwinn Posts: 8,697
    Clock Loop wrote: »
    kwinn wrote: »
    What I would most likely do for this type of setup is to use a small H bridge module for moving the periscope up/down and a microswitch that is activated by two tabs on the periscope. One tab for up, and one for down, and that signal could go to the H bridge enable or a micro I/O pin.

    This will be in water, got any waterproof micro switch suggestions? A reed switch with magnet is pretty cheap...
    I just figured dipping a reed switch into a liquid sealer would be easier than waterproofing some mechanical method.
    The op initially suggested reed switch, i figured it was because... water.

    H bridge was my initial suggestion, the parallax motor board for simplicity.
    But then I saw the op only needs .75 amp for motor power.
    I figured ssr's are easy enough, fairly cheap. Single chip(two for motor control), no pcb, etc...
    Plus op is already using a BS2 inside.... (which is a powerful microcontroller)

    Good point about water. A reed switch with 2 magnets is the way to go. As for ssr's vs H-bridge, while two ssr's would work a single H-bridge such as this one would also work and adds the possibility of pwm.
  • Hello Clock Loop! Thank you again for the help.

    - I am fine with the SSR's as you suggest.
    - Ok...so when the periscope motor isn't commanded to raise or lower or is at the top or bottom of travel (based on direction of the movement command and as monitored by the reed switches through P15 and P14) the BS2 sends a signal to turn off U3 and U4 thus cutting electric power to the motor and stopping movement. I was confused as the schematic doesn't show a non-powered position for U3/U4...either they are closed or open always routing the power from U5 per the schematic. I assume when the scope is in the fully raised and lowered position (or not being commanded to move) the BS2 commands U3 and U4 just to route a ground to both sides of the motor?
    - U2 and the emergency blow leak generated signal... I get it now. My confusion was due to the labeling. The signal path goes from Receiver Ch4 to the BLM and then to the LPB. Thus the BLM is monitoring the CH4 and sends the blow signal to the servo after 6 seconds. U2 will work exactly as you say - once the signal is opened between CH4 and the BLM, the BLM will then (after 6 seconds) send the signal to drive the servo to blow the ballast tank. That does leave the other side of U2 to light up the Sub ID Beacon LED full bright continually.
    - Ahhhh...the LED. I get it now - P1 will command U2 which will flash the Sub ID Beacon LED. No need for resistor R14 as the LED already has a resistor installed. It works well as I already tested it with the BS2 with the original code to make it flash.
    - I have a 15Amp fuse that will be attached directly at the output of the 3S LiPo 11.1V battery. There are quite a few components running off the battery so 15Amp was recommended by the RC Sub Guy. if you feel we should install others to protect the BS2 or other components for this specific application that would be fine - I just have to be careful as there is limited space.
    - Yes, just to confirm the obvious, any components outside the electronics tank will be exposed to water. I will ensure they are waterproofed.

    Awesome!
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-10-28 12:16
    Mike27283 wrote: »
    the BS2 commands U3 and U4 just to route a ground to both sides of the motor?
    Correct, this is the default state the motor pins will be in if not moving the periscope. NC means normally closed if not activated, and NO is normally open if not activated.
    In the BS2 program, its important to never switch both to create a short, thats why the 1A fuse is there.

    Mike27283 wrote: »
    - I have a 15Amp fuse that will be attached directly at the output of the 3S LiPo 11.1V battery. There are quite a few components running off the battery so 15Amp was recommended by the RC Sub Guy. if you feel we should install others to protect the BS2 or other components for this specific application that would be fine - I just have to be careful as there is limited space.
    I think you should specially protect the bs2, I have used many microcontrollers over the years, and simple, I/O series resistors(even when they are not needed) and a fuse saved many of them.
    In most cases, you accidentally do something wrong, and you know it, and then thank the fuse/resistor was there.
    I would probably put a 0.5 A fuse on the bs2 supply with the led.
    The bs2 specs say the run use is 3mA plus a max of 20mA per i/o but package is 50mA per 8 i/o.

    So I would think the bs2 with that led would even be fine with a 0.25A fuse.


    The 15 amp fuse is like a jumbo jet and the bs2 is like a rc car.
    Your bs2 would likely smoke and get hot before it(if it even could)blow that 15A fuse, if something went wrong.

    Room can be saved by trimming the sharp pins of the DIP ssr ic's and then soldering to the elbow of the pin. That makes dip ic's a bit more flat so they can be wrapped in electrical tape.
    They can also be stacked because I think all their led grounds are the same. Most of the pins would need to be bent straight and trimmed, but the common ones could be soldered to each other and trimmed.
    Instead of dead bug style, that would be silicon sandwich style.
  • Great - really coming together! I’ll get online and order the components I do not yet have while you are working on the code. I’ll breadboard everything together and then upload the code when received to give the whole contraption a test. Thank you very much for this - I’m learning a lot and already have started thinking about some other projects I can tackle with what I am learning. Mike
  • Just a quick clarification...reed switches will close when next to the magnet? I’m 99% sure that is correct but wanted to double check...
  • ‎CLA378-ND‎
    ‎LBA710‎
    SSR RELAY SPST-NO/NC 1A 0-60V
    Ordered - 4

    ‎LM1117IMP-3.3/NOPBCT-ND‎
    ‎LM1117IMP-3.3/NOPB‎
    IC REG LINEAR 3.3V 800MA SOT223
    Ordered - 3

    ‎LM1117IMP-5.0/NOPBCT-ND‎
    ‎LM1117IMP-5.0/NOPB‎
    IC REG LINEAR 5V 800MA SOT223
    Ordered - 3

    ‎CF14JT220RCT-ND‎
    ‎CF14JT220R‎
    RES 220 OHM 1/4W 5% AXIAL
    Ordered - 12

    ‎CF14JT1K00CT-ND‎
    ‎CF14JT1K00‎
    RES 1K OHM 1/4W 5% AXIAL
    Ordered - 25

    ‎374-1282-1-ND‎
    ‎MK24-A-1‎
    SWITCH REED SPST-NO 100MA 30V
    Ordered - 3
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-10-29 04:53
    Yes those reed switches close, when next to the magnet.

    I see you have other rc devices in your picture.
    What I do when ordering small cheap parts, is try to get the volume discounts.
    So i usually order a minimum of 10, or even 100 if its a cheap part, sometimes I even order a reel of 5000 for very common ones like 1k and 220ohm resistors, fuses, etc.
    The shipping is so expensive these days, if you add up years of shipping costs, you realize that you could have just ordered more initially, I learned that the hard way.

    Always order extra of what you need, if you need 3 of something, get 6, etc. (if you can afford it)

    ok, I think I will order a new bs2 programmer dongle so i can test it out also, its been a while since I have done any bs2 stuff. (i work mostly with the propeller these days)
  • Good advice...! A coworker mentioned there is a company that could create a PCB ... I may check that out. Starting to think about how best to neatly and securely put all the components together. I was also thinking it might be good to have the BS2 removable in the event it ever needs to be removed or the code refreshed. Thank you!
  • Just received the components I ordered today - going to start rigging everything up for testing...
  • Ok...I’ve got everything all set up for testing. Only SNAFU is the guy who packed my 220 ohm resistors packed 1K ohm instead... Just placed an order for a resistor set (as well as a capacitor set and more alligator clip test leads) - should have everything in about 4 days. How is the code progressing? One question about the schematic - why is VDD linked together with P15 and P14? Thanks Clock Loop!
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-11-05 21:51
    Ok.

    P15 and P14 are both connected to the reed switches which when closed with a magnet, the closure of the reed switch will pull the stamp pin to ground.
    The resistors on both pins are so the pins will be held high if the reed switch isn't closed.

    This is so if the reed switch were to break or get shorted from water, the switch would close, in a fail-safe mode.

    Read over this code and let me know what you think, I still need to test it and read it over to see if I missed anything, which I am sure I did.

    Feel free to ask anything about the code.
    Its likely the pwm pulsin code doesn't work properly we will need to test it and tweak it most likely.
    And the periscope movement and reed switches will need to all be properly setup for the proper movement and directions, etc.
    ' =========================================================================
    '
    '   File...... SubControl.bs2
    '   Purpose... Submarine Periscope control / emergency ballast flood control.
    '   Author.... Clock Loop @ Parallax Forums
    '   Updated... 4 Nov 2020
    '
    '   {$STAMP BS2}
    '   {$PBASIC 2.5}
    '
    ' =========================================================================
    
    
    ' -----[ Program Description ]---------------------------------------------
    ' At power on the sub would make sure its periscope is lowered all the way,
    '  by detecting the lower reed switch is closed.
    ' Then it monitors the 6th OUTPUT from the receiver FOR a HIGH.
    ' If the 6th OUTPUT is HIGH, the periscope will raise by the BS2 enabling the raise relay.
    ' It will THEN DO a LOOP TO monitor FOR the periscope top position reed switch.
    ' Once raised, it will go into a LOOP TO blink the led, flashes 3x over 3 seconds AND THEN PAUSE FOR 3 seconds.
    ' While the BS2 is in between changing the led states,
    '  in that LOOP it will look FOR a LOW ON the 6th OUTPUT.
    ' If it sees a LOW, it will break out of the flash led LOOP, turn off the led,
    '  AND enable the relay TO lower the periscope.
    ' Then a LOOP will start that will monitor FOR the periscope TO lower all the way,
    '  till it activates the lower reed switch.
    ' Then it repeats everything from the beginning.
    '
    ' 1. More than 1.75ms -Trigger periscope up/down (which one depends ON how you wire the motor)
    ' 2. More than 1.25ms AND Less than 1.75ms - STOP all periscope movement AND start led blink IF periscope isn't closing bottom reed switch.
    ' 3. Less than 1.25ms -Trigger periscope up/down (which one depends ON how you wire the motor)
    
    ' -----[ I/O Definitions ]-------------------------------------------------
    
    RcChannel6    PIN  0    ' Connects to RcReciever Channel 6 output. Bs2 input. Periscope UP/DOWN control signal.
    BeaconLed     PIN  1    ' Connects to U2 pin3 ssr for periscope led.  Bs2 Output, LOW = Normally Open.
    BallastSSR    PIN  2    ' Connects to U2 pin1 ssr for Ballast RC Channel 4. Bs2 Output LOW = Normally Closed.
    MotorSSR1     PIN  3    ' Connects to U4 pin3 ssr.   Bs2 Output low = Normally Open, Shorts Motor pin1 to +
    MotorSSR2     PIN  4    ' Connects to U4 pin1 ssr.   Bs2 Output low = Normally Closed, Shorts Motor pin1 to -
    MotorSSR3     PIN  5    ' Connects to U3 pin3 ssr.   Bs2 Output low = Normally Open, Shorts Motor pin2 to +
    MotorSSR4     PIN  6    ' Connects to U3 pin1 ssr.   Bs2 Output low = Normally Closed, Shorts Motor pin2 to -
    Water1        PIN  8    ' Connects to Rod 1 through a 1k ohm to detect water at bottom of tank. Bs2 input.  Normally Open logic floating.
    Water2        PIN  9    ' Connects to Rod 2 through a 1k ohm to detect water at bottom of tank. Bs2 input.  Normally Open logic floating.
    PeriscopeUP   PIN  14   ' Connects to RS1 Reed switch to detect reed closure from periscope fully up. Bs2 input. Normally Open logic High.  Closed logic low.
    PeriscopeDOWN PIN  15   ' Connects to RS2 Reed switch to detect reed closure from periscope fully down. Bs2 input. Normally Open logic High.  Closed logic low.
    
    
    ' -----[ Constants ]-------------------------------------------------------
    
    #SELECT $STAMP
      #CASE BS2, BS2E, BS2PE
        T9600       CON     84
        Scale       CON     $200            ' 2.0 us per unit
    
      #CASE BS2SX
        T9600       CON     240
    
      #CASE BS2P
        Scale       CON     $0C0            ' 0.75 us per unit
        T9600       CON     240
    
      #CASE BS2PX
        Scale       CON     $0CF            ' 0.81 us per unit
        T9600       CON     240
    
    #ENDSELECT
    
    Baud        CON     T9600
    
    ' -----[ Variables ]-------------------------------------------------------
    
    Ptime             VAR    Word
    PeriscopeMove     VAR    Byte
    TimeCount         VAR    Word
    Flooded           VAR    Byte
    
    ' -----[ EEPROM Data ]-----------------------------------------------------
    
    
    ' -----[ Initialization ]--------------------------------------------------
    
    Initialize:
      PAUSE 250  ' let DEBUG open
      DEBUG CLS  ' clear the screen
      DEBUG "Parallax Bs2 SubMarine Test Application", CR,
            "------------------------------------------------", CR, CR
    
      OUTPUT BeaconLed    ' Set Pin as output.
      OUTPUT BallastSSR   ' Set Pin as output.
      OUTPUT MotorSSR1    ' Set Pin as output.
      OUTPUT MotorSSR2    ' Set Pin as output.
      OUTPUT MotorSSR3    ' Set Pin as output.
      OUTPUT MotorSSR4    ' Set Pin as output.
    
      OUTPUT Water1       ' Set Pin as output.
      INPUT  Water2       ' Set Pin as input.
    
      INPUT RcChannel6    ' Set Pin as input.
      INPUT PeriscopeUP   ' Set Pin as input.
      INPUT PeriscopeDOWN ' Set Pin as input.
    
    
      PeriscopeMove = 2  'Demand that periscope is lowered.
    
      DO WHILE (PeriscopeDOWN = 1)  'Loop this code till the lower periscope reed switch is closed.  Closing the reed switch grounds the pin.
        GOTO MovePeriscope  'Move periscope as demanded.
        PAUSE 10
      LOOP
    
      PeriscopeMove = 0
      TimeCount = 0
      Flooded = 0
    
    ' -----[ Program Code ]----------------------------------------------------
    
    Main:
      DEBUG "Starting Bs2 Submarine Control"
    
      DO
        Flooded = 0 'Reset flood state every 6 seconds.
    
        GOTO LedFlasher    'LedOn
        GOTO FastLoop   '500ms
    
        GOTO LedFlasher    'LedOff
        GOTO FastLoop   '500ms
    
        '1 Second
    
        GOTO LedFlasher    'LedOn
        GOTO FastLoop   '500ms
    
        GOTO LedFlasher    'LedOff
        GOTO FastLoop   '500ms
    
        '2 Second
    
        GOTO LedFlasher    'LedOn
        GOTO FastLoop   '500ms
    
        GOTO LedFlasher    'LedOff
        GOTO FastLoop   '500ms
    
        '3 Second
    
        GOTO FastLoop   '500ms
    
        GOTO FastLoop   '500ms
    
        '4 Second
    
        GOTO FastLoop   '500ms
    
        GOTO FastLoop   '500ms
    
        '5 Second
    
        GOTO FastLoop   '500ms
    
        GOTO FastLoop   '500ms
    
        '6 Second
    
      LOOP
    
    '------------------------------------------------------------------------------
    FastLoop:   'This routine takes 500ms
    
        TimeCount = 0
        FOR TimeCount = 0 TO 49 STEP 1
    
          GOTO FloodDetect    'Check for flood rod conduction
    
          GOTO BallastAlarm   'If flood is detected trigger ballast.
    
          GOTO PulseLength    'Check what periscope movement is demanded.
    
          GOTO MovePeriscope  'Move periscope as demanded.
    
          PAUSE 10   '10ms x 50 = 500ms
        NEXT
    
    
    '------------------------------------------------------------------------------
    FloodDetect:
      Water1 = 1  'Make pin high so it can be detected if shorted.
      IF Water2 = 1 THEN  'If a high is detected, the two are shorted.
        Flooded = 1       'Signal that a flood has happened.
      ENDIF
      Water1 = 0   'Make pin low until we need to test again.
    
    '------------------------------------------------------------------------------
    BallastAlarm:
      IF Flooded = 1 THEN  'A flood was detected.
        BallastSSR = 1     'Open the ballastSSR so the signal drops, after 6 seconds the emergency blow will activate.
      ELSE
        BallastSSR = 0     'Resume normal ballastSSR operation.
      ENDIF
    
    '------------------------------------------------------------------------------
    PulseLength:
    
      PULSIN RcChannel6, 1, Ptime            ' measure positive pulse
    
      IF (Ptime > 0) THEN                    ' if not 0
        DEBUG HOME,
              DEC Ptime, " units ", CLREOL   ' display raw input
        Ptime = Ptime */ Scale                ' adjust for Stamp
        DEBUG CR,
              DEC Ptime, " us  "             ' display microseconds
    
      ELSE
        DEBUG CLS, "Out of Range"           ' else error message
    
      ENDIF
    
      IF (Ptime > 1750) THEN   'Periscope should start up movement.
        PeriscopeMove = 2  'Move periscope up.
    
      ELSEIF (Ptime < 1750) AND (Ptime > 1250) THEN  'Periscope should stop movement.
        PeriscopeMove = 0  'Don't move periscope.
    
      ELSEIF (Ptime < 1250) THEN  'Periscope should start down movement.
        PeriscopeMove = 1   'Move periscope down.
    
      ENDIF
    
    
    '------------------------------------------------------------------------------
    MovePeriscope:
    
      SELECT PeriscopeMove
    
        CASE 0  'No periscope movement wanted.
    
          PAUSE 1
          MotorSSR1 = 0  'NO to +
          MotorSSR3 = 0  'NO to +
          PAUSE 1
          MotorSSR2 = 0  'NC to gnd
          MotorSSR4 = 0  'NC to gnd
    
        CASE 1    'Move periscope down
          IF PeriscopeDOWN = 1 THEN   'The bottom periscope reed switch is not closed.
            'Stop all motor movement
            MotorSSR1 = 0  'NO to +
            MotorSSR3 = 0  'NO to +
            PAUSE 1
            MotorSSR2 = 0  'NC to gnd
            MotorSSR4 = 0  'NC to gnd
    
            'Move motor
            PAUSE 1
            MotorSSR4 = 1  'Open to +
            PAUSE 1
            MotorSSR3 = 1  'Closed to gnd
          ELSE
    
            'Stop all motor movement
            PAUSE 1
            MotorSSR1 = 0  'NO to +
            MotorSSR3 = 0  'NO to +
            PAUSE 1
            MotorSSR2 = 0  'NC to gnd
            MotorSSR4 = 0  'NC to gnd
          ENDIF
    
        CASE 2      'Move periscope up
          IF PeriscopeUP = 1 THEN      'The top periscope reed switch is not closed.
            'Stop all motor movement
            MotorSSR1 = 0  'NO to +
            MotorSSR3 = 0  'NO to +
            PAUSE 1
            MotorSSR2 = 0  'NC to gnd
            MotorSSR4 = 0  'NC to gnd
    
            'Move motor
            PAUSE 1
            MotorSSR2 = 1  'Open to +
            PAUSE 1
            MotorSSR1 = 1  'Closed to +
          ELSE
    
            'Stop all motor movement
            PAUSE 1
            MotorSSR1 = 0  'NO to +
            MotorSSR3 = 0  'NO to +
            PAUSE 1
            MotorSSR2 = 0  'NC to gnd
            MotorSSR4 = 0  'NC to gnd
          ENDIF
    
        ENDSELECT
    
    
    '------------------------------------------------------------------------------
    LedFlasher:
      DEBUG "Flashing led..."
        IF PeriscopeDOWN = 0 THEN
          BeaconLed = 0
        ELSE
          TOGGLE BeaconLed
        ENDIF
    
        'BeaconLed=1
        'PAUSE 500
        'BeaconLed=0
        'PAUSE 500
    
        'BeaconLed=1
        'PAUSE 500
        'BeaconLed=0
        'PAUSE 500
    
        'BeaconLed=1
        'PAUSE 500
        'BeaconLed=0
        'PAUSE 3000
    
    
    
    ' -----[ End of File ]----------------------------------------------------
    '┌────────────────────────────────────────────────────────────────────────┐
    '│                                                   TERMS OF USE: MIT License                                                                                                                                      │                                                            
    '├────────────────────────────────────────────────────────────────────────┤
    '│Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation                                     │ 
    '│files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,                                                  │
    '│modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software                                │
    '│is furnished to do so, subject to the following conditions:                                                                                                                                           │
    '│                                                                                                                                                                                                                                   │
    '│The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.                                    │
    '│                                                                                                                                                                                                                                   │
    '│THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE                        │
    '│WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR              │
    '│COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,      │
    '│ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                             │
    '└────────────────────────────────────────────────────────────────────────┘
    
  • This is great - thank you! I’ll print it out and look it over tomorrow... I am still a noob with the code but will do the research to try not to ask questions unnecessarily. I should have my new Caps and Resistors in soon so I can finish the test rig. I’ll be sure to triple-check the connections and routing before we get to the point were I load the BS2 with the code and try a test run. Thank you - Mike
  • Mike27283 wrote: »
    I am still a noob with the code but will do the research to try not to ask questions unnecessarily.

    Please DO ask questions that you would like, anything.

    Thats why this forum exists, its why I did all this effort to help you.

    We all do this here because we and others benefit from the content. We can search the forums for help and find this kind of content.

  • WBA ConsultingWBA Consulting Posts: 2,933
    edited 2020-11-10 08:57
    Mike27283:
    I've been following this thread as I would love to make an RC Sub some day. On the topic of a reed switch, I believe I still have few of these in my project boxes if you could make use of it somehow:
    https://www.digikey.com/en/products/detail/magnasphere-corp/MG-B2-6.5-L/1680359
    It works similar to a reed switch, but no magnet required, just the presence of ferrous material near it activates it. They are rather slick.
    I also think I have some very small SMT reed switches if space is an issue. I have had both of these styles, but not sure which I still have.
    https://www.digikey.com/en/products/detail/littelfuse-inc/MDSM-10R-20-25/1665606
    https://www.digikey.com/en/products/detail/littelfuse-inc/59165-1-T-00-D/969933
    If you are interested in any of those, let me know. I can toss them in an envelope for you.
  • Thank you for the encouragement. I spent a good portion of the morning going over the code and double-checking all of the values and such.

    - I'm confused on what is text and what is actual code. To be more specific; if only the bare bones text (commands) needed to upload into the BS2 were all that was on the sheet - how much of what is currently there is comment and explanation vs the actual PBASIC commands? I see the ' denotes anything afterwards if ignored as it is a comment so I assume if anything after a ' was removed the rest would be the code and would be what is uploaded?
    - Program description. Minor note - I noticed it didn't describe the ballast leak detect function. I realize that it is not required but for completeness wanted to make you aware.
    - I/O Definitions. Found one error here...Periscope Pin 14 connects to RS2 (fully down) and Periscope Pin 15 connects to RS1 (fully up). They were reversed in the code as compared to the schematic.
    - Main. Question about how this cycle works...when it executes the 'GoTo' to the LedFlasher it seems to go through the entire 6 second flasher routine before executing the 'GoTo' to the FastLoop. Thus - is FastLoop only checked (or executed) every 6 seconds?
    - Pulse Length. It looks like the first portion of this routine is a section to test the latency of the BS2 or signal in some way in order to add in an adjustment so the BS2 is reading the PW signal correctly from receiver channel 6 so it correctly executes up, down or no movement. It looks like the goal is for the BS2 to accurately interpret and read the 1250-1750 ms signal so it know where the window of 'no movement' is located... I see a line item that states * / Scale - I assume I'll have to somehow put in some value here to make adjustments if needed?
    - Added in a few pics of my notes while I was doing my homework this morning. Very interesting stuff and am enjoying the education.
    Mike
    4032 x 3024 - 2M
    4032 x 3024 - 2M
  • Caught something else - in the Initialization section shouldn’t the initial demand to lower the periscope be Periscope move = 1?
  • Good catch on those, I knew that I may have some bugs...
    I will fix those bugs in the original .bs2 file above in the next few days, and answer your questions...
  • Clock Loop - will you be very proud of me! I have the entire thing working...took 3 full days but it is done.

    - I'll attach the code in a Word Doc. It is pared way down - you still get full credit for starting me off so take no offense their is no owner information.
    - Here is a link to a 5 minute video - not great quality but it does demonstrate how everything works. https://drive.google.com/file/d/15TtjwN-X3xy4OqrKcmSS4w4vbpXWlxLQ/view?usp=drivesdk

    - Made some damn noob mistakes...loose grounds, BS2 not fully seated, hooking things up incorrectly...
    - Then had issues figuring out what signals to read or put on pins to make things work...
    - Then my batteries would die...
    - Added a second light (Mastheadlight) and a 4th SSR to run it - also routed the leak detect signal through it.
    - Had to really nug down on reading and learning PBASIC...
    - Changed the code substantially but retained the majority of your structure - the commands you added really primed the pump for me and got me on the right path. Thank you!
    - The periscopes raise and lower, they stop (or I am unable to move them beyond the upper or lower limit) when at the upper and lower limits as defined by magnetic reed switches. If fully seated I cannnot run the motor down but can run it up for instance. The Sub ID beacon flashes the correct sequence and the masthead light (runs through the SSR I added) is on and bright whenever the periscopes are not in the fully down position.
    - I got the leak detect function working (what a bear!); if a leak is detected it drives the SSR I added to ground out the power to the ballast tank servo causing the BLM to command an emergency blow. And - the Sub ID beacon and masthead both flash every 1/2 second as a visual alert signal. I also added code to ensure the periscope motor stops in the event of a leak.
    - I added code so the periscope motor stops in the event of a loss of signal (it was running continuously when signal was lost) due to the sub going too deep and the masthead light will flash by itself alerting me to the condition. Realize on a loss of signal without a leak the BLM does this automatically - so this code prevents the periscope motor from running if its not receiving a signal.

    I am not sure why it takes as long as it does to command the blow after grounding out the ballast servo - grounding out the power equates to loss of signal which is detected by the BLM and then 6 seconds later it activates. Seems to take longer than that...

    Let me know if there is anything I can do to improve the operation. Again - THANK YOU for your help and guidance. Eventually when I get this thing done I'll post some pictures and a video here.

    Mike
  • Wanted to provide a quick update and post some photos of this project. I substituted in a linear servo for us in raising and lowering the masts which further simplified the code. The BS2 was mounted onto a breadboard with the 2 SSR's and other components - it is located underneath the styrene platform at the front end of the submarine's WTC. I also included pictures of my notes in addition to the updated code and pictures of the submarine in its current state. Next steps are to get the sail and mast assembly complete and add torpedo's! Again - many thanks to Clock Loop for his work and guidance - couldn't have dome this without his tutelage.


    I started a new thread - looking to add some autonomy to the submarine with navigation routines. See ... 'RC Submarine Autonomous Control'





Sign In or Register to comment.