Skip to content

Lawebb - timing updates#3

Open
dfrencham wants to merge 3 commits into
masterfrom
lawebb-timing
Open

Lawebb - timing updates#3
dfrencham wants to merge 3 commits into
masterfrom
lawebb-timing

Conversation

@dfrencham

Copy link
Copy Markdown
Owner

Code provided by lawebb as example of timing implementation

Comment thread LightTree.cpp
digitalWrite(PIN_LIGHT_TREE_RELAY_2, HIGH);
digitalWrite(PIN_LIGHT_TREE_RELAY_3, HIGH);
digitalWrite(PIN_LIGHT_TREE_RELAY_4, HIGH);
digitalWrite(PIN_LIGHT_TREE_RELAY_1, LOW);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a new configuration option to reverse relay states.

Comment thread Makefile
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile

MONITOR_PORT = /dev/cu.wchusbserial1420
MONITOR_PORT = /dev/ttyACM0

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must be using a better quality Arduino than me :)

Comment thread Sequence.cpp
4 240 Set LED3 Play Tone 632
5 300 Stop Tone
6 360 Set LED4 Play Tone 632 Gate Activate
7 660 Gate Deactivate

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we need an explicit "Deactivate" state. After the gate drops it is deactivated (magnet off, no sequence running). I can understand an "armed" state, as that implies the magnet is powered.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The solenoid just requires a pulse. 300 ms seems long enough. Leaving it on sucks a lot of power and will surely burn out the coil. I tried making a pulse by dumping charge from 50000uF worth of charge from some capacitors - not enough. So software is better, and the need to deactivate. The The Gate::arm() function was empty so used it... should have renamed it

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, cheers makes sense. Should we have a variable name gateControlType that we can set to "solenoid" (with default being "magnet")?

That way we can change the behaviour based on that setting.

Comment thread Sequence.cpp
gate->set_abortable(false);

// Use interrupt to catch END request from SENSOR
attachInterrupt(digitalPinToInterrupt(PIN_SENSOR), Interrupt2, LOW);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't seem to be detaching the interrupt anywhere - so this interrupt could be attached multiple times. The results might be unexpected after the first run.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK - haven't noticed any problem as yet

Comment thread Sequence.h
void begin_sequence();
void abort_seq();
void set_ready();
void setLed(int led_val);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why setLed is here - you can do it via the LightTree reference.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote a test sequence.cpp , and did cut and past when was working. Then slavishly copied the setLed, gateAct, and playTone functions too. Agreed can get rid of them

Comment thread Sequence.h
void abort_seq();
void set_ready();
void setLed(int led_val);
void gateAct(int gate_val);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Gate class reference

Comment thread Sequence.h
void set_ready();
void setLed(int led_val);
void gateAct(int gate_val);
void playTone(int play_val);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use AudioFX class reference

Comment thread constants.h
#define DELAY_RAND_MAX 2700

// some inferior gate controllers don't BEEP at the correct pitch
// frequence. Correct tones (in Hz) are below

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I had this in the wrong place.

Comment thread constants.h
#define PIN_SFX_ACT 1 // sound board active

#define PIN_LIGHT_TREE_RELAY_ENABLE 3
#define PIN_LIGHT_TREE_RELAY_ENABLE 4

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we have at least one bloke running a gate that expects to enable the light tree with pin 3. We might need to find another solution (we could use Pin 19).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pins 2 and 3 are the only ones that can be used for an interrupt input by my reading. 2 is used for ABORT so had to use 3 for the interrupt for the light beam

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argh! you're right. I might have to make light tree mode a software configuration item rather than a jumper.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to listen for the beam while the sequence is running. As the sequence loop is still active, we can check at the start of each loop if the beam pin has gone low. As the ATMEGA is already busy running that loop, we won't run into any issues by doing the check there.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to not use an interrupt? here are two examples of serial monitor using test button - first button is before sequence is finished - second is after finished.

[17430] No longer abortable
[17430] Set LED 1
[17550] Set LED 2
[17670] Set LED 3
[17790] Set LED 4
[17790] Gate Activate
[18091] Gate Deactivate
[20013] Reaction Time = 2223
[20013] Press GO to restart...
[20040] Setting sequence to STOP

[89785] No longer abortable
[89785] Set LED 1
[89905] Set LED 2
[90025] Set LED 3
[90145] Set LED 4
[90145] Gate Activate
[90445] Gate Deactivate
[92395] Setting sequence to STOP
[92395] Sequence complete - Waiting for reaction time...
[94418] Reaction Time = 4273
[94418] Press GO to restart...

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - should be do-able without an interrupt. We can keep the sequence loop running until we have a time. Pseudo code:

while (sequenceRunning || (timingEnabled && waitingForTime)) {
 if (timingEnabled && gateHasDropped) {
  if (digitalRead(PIN_TIMING_TRIGGER) == LOW) {
    // time found, save in var 
    waitingForTime = 0;
  }
 }
 // rest of sequence code
}

Comment thread rad-gate.ino

serial_print("Gate controller initialised");
serial_print(VERSION);
serial_print("Waiting for GO Button Press");

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the version string print, but also add your line. Otherwise it isn't clear we are ready for a button press. Good idea.

Comment thread Sequence.cpp
attachInterrupt(digitalPinToInterrupt(PIN_SENSOR), Interrupt2, LOW);

offset = millis();

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused with how this was structured until I realised you are running a series of tasks as an inner loop for each step.

@dfrencham dfrencham mentioned this pull request Mar 5, 2018
Comment thread Sequence.cpp

offset = millis();

while((step < count) && (!gate->is_aborted())) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lawabb what was the reason for the refactor with the loop? was the original code difficult / unwieldily to update? (if the original code was rubbish, please say so!)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code was fine. It took me sometime to figure out how it worked, but I successfully modified it to work with my addition of 'gate deactivate' with the exception that I couldn't set wait time to zero so had to use 1ms. The trouble was that it was becoming unweildy and ugly... I don't know how to merge with the original code. As an amateur python programmer what I did was write the sequence in python the transferred it virtually line by line with help from google. It may be of some use...
test_new_seq.zip

@denisborgesalves denisborgesalves left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alguém tem o código-fonte mais recente da UCI para me fornecer?

Meu e-mail é:

denisborgesalves@gmail.com

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

Successfully merging this pull request may close these issues.

3 participants