go_away

Author Topic: An example of my problem  (Read 656 times)

0 Members and 1 Guest are viewing this topic.

Offline thornsb1Topic starter

  • Jr. Member
  • **
  • Posts: 12
  • Helpful? 0
An example of my problem
« on: October 24, 2010, 06:36:42 PM »
Here is the source code that Webbot generates for a project with one servo. In order to learn how to control servos I am only using one servo at this time. The problem is that this code moves the servo backwards and forwards continuously. I want to be able to command any number of servos to move to a certain position and stay in that position while other servos do something. I know how to change the center and range but I can't get the servo out of the loop. Can someone tell me what I would have to change to make a servo stop at a certain position without moving again until later? Also, if there is a good strategy for this kind of programming I would appreciate any suggestions. Thanks Guys!


#include "hardware.h"

// Initialise the hardware
void appInitHardware(void) {
   initHardware();


}
// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
   return 0;
}
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {

   // -------- Start Switch/Button-------
   // Switch/Button - see switch.h
   
   // To test if it is pressed then
   if(SWITCH_pressed(&button)){
      // pressed
   }
   
   // To test if it is released then
   if(SWITCH_released(&button)){
      // released
   }
   // -------- End   Switch/Button-------

   // -------- Start Marquee-------
   // Marquee - see 'segled.h'
   // Before using the Marquee you need to redirect rprintf to write to it
   // This can be done using
   Writer old = rprintfInit(marqueeGetWriter(&marquee));
   
   // All rprintf output will then be sent to the marquee but will not
   // display until an end-of-line eg "\n" has been sent. Example:-
   // rprintf("Hello World\n");
   
   // If the endDelay is non-zero then the marquee will scroll
   // forever or until you call: marqueeStop(&marquee);
   
   // If the endDelay is zero then the marquee will stop once
   // the entire line has been shown ('one-shot' mode)
   
   // In 'one-shot' mode then you may want to make sure that
   // a previous line has finished before you display a second line.
   // This can be done as follows:-
   marqueeSetEndDelay(&marquee,0); // Make sure we are in one-shot mode
   if(marqueeIsActive(&marquee)==FALSE){
        if(loopCount==1){
           rprintf("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
        }else{
         rprintf("Loop=%u\n",(unsigned)loopCount); // Put the loop count
        }
   }
   
   // Restore rprintf back to its previous location
   rprintfInit(old);
   // -------- End   Marquee-------

   // -------- Start Actuators -------
   // To control your.motors/servos then see actuators.h in the manual   // To retrieve the required speed of servo1 use:
   // DRIVE_SPEED speed=act_getSpeed(servo1);
   // To set the required speed of servo1 use:
   // act_setSpeed(servo1,speed);
   // This example will move the motors back and forth using the loopStart time:
   TICK_COUNT ms = loopStart / 1000;      // Get current time in ms
   int16_t now = ms % (TICK_COUNT)10000;    // 10 sec for a full swing
   if(now >= (int16_t)5000){            // Goes from 0ms...5000ms
      now = (int16_t)10000 - now;         // then 5000ms...0ms
   }
   // Map it into DRIVE_SPEED range
   DRIVE_SPEED speed = interpolate(now, 0, 5000, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
   // Set speed for all motors/servos
   act_setSpeed(&servo1,speed);
   // -------- End   Actuators -------

   return 0;
}

 


Get Your Ad Here

data_list