go away spammer

Author Topic: [SOLVED]::Persistent variables in the Axon  (Read 1746 times)

0 Members and 1 Guest are viewing this topic.

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
[SOLVED]::Persistent variables in the Axon
« on: July 12, 2011, 08:18:18 AM »
Hi all,

I was certain I'd posted this before, but I searched all my previous posts and couldn't find it, so *super* sorry if this is one of those common questions that comes up all the time!

Here's my issue:

I'm using webbotlib.  The Axon is responsible for determining whether my robot should be working in "position" mode or "force" mode.  The switch between these two modes is a threshold on the force sensor: the robot keeps moving to a certain position unless the force on the sensor exceeds a threshold, at which point it starts to regulate the force at some pre-set value.

That threshold is going to have to be variable, and what changes it is a message from the PC.  So far, so good -- I can easily send data back and forth from the PC to the Axon.  

However, since the threshold is just a variable that gets created each time the Axon goes into the "appControl" function, it also gets destroyed each time I exit that loop.  If the threshold were never changing, I'd just #define it as something.  I need to be able to set the threshold whenever I want, without having to re-set it each time I go through the appControl function.

So: PC sends a new threshold, Axon receives it, and should set that threshold and keep it, regardless of whether it exited appControl, until a new threshold is received.  

How do I do that? :-P

MIKE
« Last Edit: July 12, 2011, 09:36:26 AM by mstacho »
Current project: tactile sensing systems for multifingered robot hands

Offline rbtying

  • Supreme Robot
  • *****
  • Posts: 452
  • Helpful? 31
Re: Persistent variables in the Axon
« Reply #1 on: July 12, 2011, 08:53:08 AM »
Put it on top of the program, outside of the various functions and such:

Code: [Select]
uint8_t threshold;

void foo() { threshold = 0; }
void bar() { ++threshold; }

Offline mstachoTopic starter

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 10
Re: Persistent variables in the Axon
« Reply #2 on: July 12, 2011, 09:35:17 AM »
Awesome!  That was way simpler than I expected, thanks.

MIKE
Current project: tactile sensing systems for multifingered robot hands

 


Get Your Ad Here

data_list