Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for duration #5

Open
naaitsab opened this issue Jun 19, 2022 · 7 comments
Open

Option for duration #5

naaitsab opened this issue Jun 19, 2022 · 7 comments

Comments

@naaitsab
Copy link

I experimented a bit with the "type 1" collar. It seems to support longer/continuous vibration and shocks. Tested to 7 seconds.

I've hacked together a very crude method to let it trigger longer. If you call the function in a loop. With the loop count double the amount of seconds it seems to work about right with a delay of 250 in between.

  int timestofire = sec * 2;
  for (int i=0; i<timestofire; i++) {
    process_message(commandC);
    delay(250);
   }

But after a few seconds the ESP restarts so I guess it overloads the system doing it like this. Any idea how to implement this cleanly inside of the collarTX libary?

@CrashOverride85
Copy link
Owner

I'm not too familiar with ESPs, but i think if the main loop takes too long to run, the wdt resets them? (been a few years since I've played with one).

So I'd suggest trying something like this that avoids calling delay():
https://gist.github.com/CrashOverride85/531d95e505f302c8b664b95a71ac3926

Basically it's the ColTxSerial.ino example modified to transmit for 7 seconds (set on line 161)

@naaitsab
Copy link
Author

Thanks will give it a try later on. Not sure what the max duration of the collar itself is. Did you experiment with it yourself?

@CrashOverride85
Copy link
Owner

I honestly can't remember - I probably didn't experiment much with max duration. But I knew they could be on for a few seconds, but I can't remember if there's a limit or what it is

@naaitsab
Copy link
Author

naaitsab commented Jun 28, 2022

Got it working, even with WiFi enabled and a webpage (remote control FTW) it stays stable until 10 seconds :) Maybe even more but I think 10 is a nice max.

Made a few modifications to implement the timer in the commands

Added int sec = atoi(&input_message[5]); under power = atoi(&input_message[2]);
Made the command accept the 'sec' as input instead of the static 7 of the example.
atoi keeps 'calculating' so we need to terminate it after the power ends and the sec(onds) start with a char. So I added a : in the *input_message

So the message should look something like this 1V15:05 for collar 1 vibrate at 15% for 5 seconds.

Only thing I can't really figure out is the timing. It seems to be time + 1 second roughly. So 10 is 11 and 1 is 2.

Also want to implement a pavlov mode. So vibrate first then shock. Guess it needs the modification inside the void loop at the check "if (_transmit_end_ms > 0)" so it will set to vibrate for 1-2 seconds (or 1/3 of the time or something? and then change the "_msg" so it will shock instead of vibrate.

@CrashOverride85
Copy link
Owner

I'm not sure why it's triggering for an extra second - it might be just the response time of collar, or something like that? If it's always out by 1 second, i guess the easy approach is just to take 1 sec off seconds on transmit() 😂

Getting to vibrate first the shock is probably a bit more awkward. I guess you'd need to do something like add a _transmit_start_ms time, and a pavlov_mode flag.
So in the loop, when pavlov_mode=true and msg.mode=VIBE, if the current millis() is more than 1/3 of the way between _transmit_start_ms and _transmit_end_ms, change msg.mode to SHOCK.
There might be easier ways, though... not sure..

@naaitsab
Copy link
Author

naaitsab commented Jul 1, 2022

Do you by chance have the remote for it to test something? Perhaps the second is just the minimum trigger amount and every "loop" adds another second to it. So trigger + 1 loop is 2 seconds instead of 1 because the trigger already adds 1 second.

@CrashOverride85
Copy link
Owner

Just found it and tried it... yeah, from pressing the button to the shock collar stopping, it does seem to be around a second

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants