3

I recently got the RedBearLabs BLE shield to use it to control two high spped continuous rotation servos. I have the BLE example sketch loaded and the ios controller app works. The problem is that the servos are too fast to control and I want to slow them down. I cannot use the app to slow them down. I was wondering how I could modify the example sketch or servo library to change the ax speed or something. Thanks in advance.

BLE Shield Homepage: http://redbearlab.com/bleshield/

BLE Libraries and Example Sketch: https://github.com/RedBearLab/nRF8001

  • 1
    Can you be more explicit in what you want to achieve. What do you mean by "the servos are too fast to control" - do you mean the servos are repositioning too quickly? Something else? Also can you please post (or link to) the exact code you need help with - not a whole library of stuff. – Kingsley Feb 18 '16 at 3:47
  • The servos spin too fast to be able to control it very well. I want to slow those down. codebender.cc/sketch:245943 This is the code – zcmckenna Feb 18 '16 at 4:09
  • SnapDraggen, please edit the question to answer the items in Kingsley's comment. Note, there are seven different examples at the github link, four of them having BLE in their names, so you should say which one you mean. Also add a direct link to whatever iOS app you used. – James Waldby - jwpat7 Feb 18 '16 at 4:14
  • This is the app: itunes.apple.com/us/app/ble-controller/id855062200?mt=8 The sketch is the one called BLEControllerSketch I am using it to build a robot – zcmckenna Feb 18 '16 at 4:15
  • 1
    @SnapDraggen - please edit your question and copy the information in your comments into it. The question will then be more complete. Please read How do I ask a good question? – Nick Gammon Feb 18 '16 at 5:28
2

The bi-directional Parallax High Speed Continuous Rotation Servo responds to “simple pulse-width modulation”, according to its web page. That is, pulse widths in the range from about 500 μs to 2500 μs will set the speed and direction, with some value near 1500 μs corresponding to zero RPM.

The code in the BLEControllerSketch uses the following bits of code, among others, to initialize servo-control data structures and to control them:

#include <Servo.h>
...
byte pin_servo[TOTAL_PINS];
Servo servos[MAX_SERVOS];
...
      case 'O': // set Servo
        {
          byte pin = ble_read();
          byte value = ble_read();

          if (IS_PIN_SERVO(pin))
            servos[PIN_TO_SERVO(pin)].write(value);
          pin_servo[pin] = value;
          reportPinServoData(pin);
        }
        break;

Thus, you will need to send an O message from your iOS app, together with servo pin number and control value, to set a servo's speed.

As noted on the ServoWrite page at arduino.cc, the parameter to Servo's .write() method is a number:

On a standard servo, this will set the angle of the shaft (in degrees), moving the shaft to that orientation. On a continuous rotation servo, this will set the speed of the servo (with 0 being full-speed in one direction, 180 being full speed in the other, and a value near 90 being no movement).

You can find out a little more by looking at Servo's .write() method in Servo.cpp:

void Servo::write(int value)
{
  if(value < MIN_PULSE_WIDTH)
  {  // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
    if(value < 0) value = 0;
    if(value > 180) value = 180;
    value = map(value, 0, 180, SERVO_MIN(),  SERVO_MAX());
  }
  this->writeMicroseconds(value);
}

SERVO_MIN() and SERVO_MAX() are macros that access min and max fields in a Servo object and convert them to microsecond values. Because the code in BLEControllerSketch.ino lets those fields default, the range evidently will be from 544 to 2400 μs (see the values given in Servo.h).

Note that you can get better resolution – hence, better speed control – by sending values in that range of microseconds to your servos, instead of trying to control it using values in degrees. The .write() method will interpret such numbers as microseconds instead of as degrees. Servo.cpp appears to use half-microsecond timer ticks; and each degree corresponds to about 10 μs of pulse width; so resolution using microsecond values should be about 10 times better than using degrees.

In short, it appears that you should do some experimenting with O messages that send values around 1500, to find the values that correspond to slowest forward and backward speeds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.