[C.CC USERS] HIGH and LOW and interrupts problem

Matt Jadud jadudm at gmail.com
Wed Aug 11 17:06:06 BST 2010


Hi Laurence,

On Wed, Aug 11, 2010 at 11:05 AM, Laurence Laycock <rencio7 at gmail.com> wrote:
> Hi Laurence here (:

I love how you dove into things right when everyone went on vacation. :)

> (Here is a link to my robot code and rencio7.module)

It isn't accessible, for some reason -- I don't have permission to view it.

>  HIGH and LOW with digital.write (plumbing.module) doesn't work and  other
> commands such as digital.output (digital.module) I get type mismatch
> errors.. try 0 and 1 instead....it works...this should be fixed easily in
> the library...I'll try and do it lol..although not high priority I guess....

I committed a fix. We'll test if before pushing a new build.

> button.press PROC only works with pins 1,2 or 3...it doesn't work with all
> the others (arduino atmega328) error code: - error status E....final machine
> state: file=external.interrupts.module line 37....maybe there is a reason
> for this?

SO.

The hardware interrupts are only available for the first few pins...
currently. Looking at the Atmega328 manual, it looks like we could
have interrupts on the INT0 and INT1 pins (which are 1, 2, and 3 I
think), as well as the PCINT0...23 pins (which would be most of the
other pins).

We haven't written this code yet. Would that be useful for us to
tackle in the nearer future?

> writing.module only works (compiles) if I delete the lines 101 - 108 of
> it... yay

Drew doesn't like wiring.module. We are providing it as a "bridge" for
Arduino programmers, but it mostly encourages sequential (as opposed
to parallel) solutions to problems.

Either way, we'll at least fix it up a bit more so it isn't a problem
for users. Hm. Currently, the most recent version of the module has
this commented out... it looks like we'll just have to update the
Mac/Windows packages.

> my use of byte.tick PROC(in rencio7.module) ...for motor pwm needs to be
> possible without it....probably is...I'd like to know how...D:

Ask this again (and a bit more clearly?) when we can access the code.

> When running a sequence can I loop it? If not how do I do an if statement to
> tell it that if the sensor is not HIGH run it again...?


SEQ
  INITIAL BOOL DONE IS FALSE:
  INT x, y, z: -- Assorted variables

  -- Loop while
  WHILE NOT DONE
    SEQ
      .. do stuff ...
      IF
        x = 42
          DONE := TRUE
        TRUE
          SKIP
  -- Now, we're done with the loop, so we can continue.
  -- Why? Because we put a SEQ outside of the WHILE loop.
  z := 8

I think that's the pattern you're looking for... if I understand your
question correctly, anyway.

> I'm trying to trigger a pin to high or low when triggering a sharp 5cm
> sensor (which just reports 0 or 1) It works when using button.press on a
> motor pin but I tried it on pin 9 (the enablepin1 of the h-bridge) -but the
> motor doesn't move - I'm guessing that toggle only uses 1 or 0 values so due
> to pwm 1 is too little to move the motor..or not. :X

Hm.

I think I understand, not seeing the code.

I'd do the following:

trigger -> debounce -> motor.control

Have a process called "trigger" where you do the sensor work. It
signals out (perhaps running it through the debounce process that is
lurking in the libraries somewhere) so you don't get lots of messages
in a short period of time. (This may not matter.) Your motor.control
process then receives the message (either a LOW or a HIGH), and based
on that reading does the appropriate thing to the PWM. It might look
like:

PROC motor.control (CHAN LEVEL sensor?, CHAN BYTE pwm!)
  LEVEL lvl:
  WHILE TRUE
    SEQ
      sensor ? lvl
      IF
        lvl = HIGH
          pwm ! 128 -- Half-speed
        TRUE
          pwm ! 0 -- Kill the motor
:

> My next step is to do some robot simple avoidance and to run this when
> triggering a sensor : -
> (this will be just a set of PROC I've made)
>    goStop()
>     delay (500)
>     goStart()
>     goBackward()
>     delay(500)
>     goLeft()
>     delay(500)
> How would I send a signal from a pin to trigger a PROC and if that trigger
> is LOW run a different one?

Think in terms of process networks. You could have a process that
encapsulates one set of behaviors (backing up to the left, for
example) and another that encapsulates backing up to the right. These
both sit at the end of  SIGNAL channels, waiting. Then, you have a
control process that looks a bit like the one I pasted above...
depending on sensor readings, you can trigger one channel or another.
the backup.left and backup.right PROCs are both running continuously
(if you will), but most of the time they're blocked, waiting for a
SIGNAL over a channel.

Does that make sense?

Related, you might give Jon's paper a read:

http://www.transterpreter.org/publications/#SimpsonJacobsenJadud06

It's about doing subsumptive control on the LEGO Mindstorms -- the
code and ideas written there will work just fine in the context of the
Arduino -- a student of mine used some of these ideas in his senior
comp last term when exploring interactive jewelry. (I should see about
getting his comp online somewhere...)

Doing robotics in occam-pi should work fine -- that's where we started
with all of this, and where two students this summer were doing
autonomous aircraft work. Please continue to ask questions and push
for ideas -- we're glad to help.

> I'm trying to port code from arduino and I'm getting confused...my head is
> still trapped in C -I've tried drawing some code diagrams like in plumbing
> pdf but I'm unsure of some ways to do some things...even though I have
> OccamDocs....

Just keep at it, and keep asking questions. These are great questions,
and you're just experiencing the joy of learning to think in a
different way (process-oriented vs. procedural/sequential). Anything
that we can do to help, we're glad to do. (Most of the core team have
assisted in teaching occam-pi at the University of Kent, so we're keen
to help new programmers getting started in this space.)

Related, the Kent "Anonymous Question Pages" might be a good resource
for us to link to from the website:

http://www.cs.kent.ac.uk/projects/ofa/co538/anonqa/index.html

Searching those when you have questions about things in occam-pi will
likely find questions asked by students in years past, and faculty
answers to those questions.

> I plan to use concurrency as my main coding base for arduino if it continues
> to develop (it is promising). I have a lot of code I would like to try
> porting to it.

We're not going to be walking away from the Arduino anytime soon, and
members of the group are reasonably committed to the tools in terms of
research and teaching, so... I don't think we're going away. Just keep
asking questions, and we'll keep providing answers.

Should I pick up one of the Polou bots?

Cheers,
Matt




More information about the users mailing list