Go Down

Topic: Trouble elegantly sending time, servo, and rangefinder data together to PLX-DAQ (Read 301 times) previous topic - next topic

SpaceGhost

Hello!

My current project involves a lidar lite (v3) rangefinder mounted on two Dynamixel MX-12W smart servos (stepper motors actually) connected to an Arbotix-M microcontroller that sends sensor data via Xbee into a PLX-DAQ table.

My desired result is that the positions of the servos along with the rangefinder measurements would be sent together with the same time stamps CONTINUOUSLY into PLX-DAQ while the code still coordinates the pre-programmed servo movements. The end product of this is ideally going to be the ability to generate 3D points from this data.

Currently I'm doing this:

Code: [Select]
void loop()
{

  //variable declarations
  int tiltpos = 1175;                                       
  int panpos;                                               

  while (tiltpos < 3073) {                               

    milli_time = millis();

    SendSensorData();     // replaces big block of code previously used
   
    // 1. counter clockwise sweep
    for (int panpos = 0; panpos < 4096; panpos += 10)   //increment pan servo 0 to 4096 by 10
    {
      SendSensorData();

      SetPosition(1, panpos);        //set the position of servo #1 to the current value of 'panpos'
      delay(10);                     
    }

    // 2. Move sensor tilt up one after first sweep
    tiltpos = tiltpos + 11;
    delay(10);                           
    SetPosition(2, tiltpos);           //set position of servo #2 tilt to +11 steps (approx. 1 degree)

    SendSensorData();

    // 3. Clockwise sweep at new tilt position
    for (int panpos = 4096; panpos > 0; panpos -= 10)       //decrement pan from 4096 to 0 by 10
    {
      SendSensorData();

      SetPosition(1, panpos);   
      delay(10);                     
    }



    // 4. Move sensor tilt up one after sweep
    tiltpos = tiltpos + 11;
    delay(10);                     
    SetPosition(2, tiltpos);   

    SendSensorData();

}


So basically trying to send all the aforementioned data continuously while the servos sweep 360, move up, sweep the other way, move up, until it reaches a certain upward angle, after which the program signals it is done.

My issue is that filling in the space between each and every servo command seems clunky and it results in tiny little holes in the resulting PLX-DAQ table.

I tried using two different microcontrollers for the servos and lidar lite but PLX-DAQ and Xbee don't like that i.e. will only read one COM port at a time.

Anybody have an idea of how to do this more elegantly and without all the repetition of the SendSensorData function?

Thank you in advance for any wisdom offered!

*edited code to (hopefully) make more readable

PaulS

Quote
connected to an Arbotix-M microcontroller
What does that have to do with Arduino?

Code: [Select]
  int k=1175; //tilt servo
  int i;           //pan servo

That is NOT what that code does.

Why would you use meaningless names like that? Wouldn't panPos and tiltPos make more sense?

Do you suppose that the microcontroller keep better time than the PC where Excel is running?

Don't you suppose that a function that took 4 values, time, pan position, tilt position, and distance would be better than replicating all that code?

Don't you suppose that a function that took 4 values, time, pan position, tilt position, and distance would be better than replicating all that code?

Don't you suppose that a function that took 4 values, time, pan position, tilt position, and distance would be better than replicating all that code?

Don't you suppose that a function that took 4 values, time, pan position, tilt position, and distance would be better than replicating all that code?

Do you
               suppose that properly
        indenting your
                   code might
       make it easier
   to read? Do you know how easy it is to do that?
The art of getting good answers lies in asking good questions.

SpaceGhost

Well PaulS everything you mentioned is exactly why I asked!

I mentioned the Arbotix-M to just give a little background on what the whole set up of the project was.

Also you are correct that proper indentation and creating a function is the way to go so I'm doing that now BUT again the heart of the question is that even with proper format of code and the use of functions, is there a way to send this info without repeating the function all those times?

Thanks for the continued help!


PaulS

Quote
is there a way to send this info without repeating the function all those times?
Without repeating all the code, yes. That's what a function is for.

Without calling that function repeatedly? No.
The art of getting good answers lies in asking good questions.

Go Up