Pages: [1]   Go Down
Author Topic: Servo/ESC control via Processing and Firmata  (Read 1454 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, I'm trying to control an RC electronic speed controller (ESC) from Processing on my Mac.
ESCs use the same control signal as a regular RC servo, so I'd appreciate advice from anyone who has experience with either.
If you're curious, a 0˚ servo signal to the ESC runs the motor in full reverse, 90˚ is stopped, and 180˚ is full forward.

I know my wiring is right, because I can control the motor from the servo mode slider in the Firmata Test application, and I can also use the "sweep" example code on the Arduino Servo library refpage to make the motor run back and forth without intervention from the computer.

In a nutshell, I need to control this ESC (or servo, however you like to think about it) in real-time from my Processing sketch.  I know only one Processing command that helps towards this end, and that's "arduino.pinMode(escPin, Arduino.SERVO);", called in setup().

Anyone know what Processing syntax will actually set the servo to a certain angle?

I tried "arduino.analogWrite(escPin, speed);" inside of draw(), after executing the above command in setup().
"speed" was assigned various int values from 0-180, but the motor did not respond properly and did not reverse, suggesting that the PWM on the pin was still running @~390Hz rather than giving a proper RC pulse.

A rundown of the 'ware:
Macbook Pro running Mac OS 10.6.7 and Processing 1.5.1
Arduino Mega 2560 running StandardFirmata 2.2
Turborix EL 110A ESC fed for now by a 250W ATX PSU and controlling a small 12V Johnson motor for bench tests

Thanks!

Jacob
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What sketch do you have on the Arduino when this Processing application is running? Is it the ServoFirmata sketch? If not, why not?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the advice Paul.  I just tried ServoFirmata and the ESC worked fine. 

Perhaps I should have clarified, but I've got several more actuators and sensors connected to the Mega that need to communicate with the computer, so ServoFirmata alone won't work.  I know StandardFirmata supports servos since I can run the ESC from Firmata Test with StandardFirmata on the Arduino and all the sensors, etc. running, but for some reason I can't control servos from Processing.

So what I'd just love to know is if the Processing library is buggy or if I'm just using it wrong.

Here's my Processing test code (which incidentally controls the motor with a joystick rather than a mouse or arrow keys.)  It works fine when ServoFirmata is running on the Mega.

Code:
import procontroll.*;
import processing.serial.*;
import cc.arduino.*;

int escPin = 3;
ControllIO controll;
ControllDevice device;
ControllSlider xSlider;
float xVal;
Arduino arduino;

void setup(){
  controll = ControllIO.getInstance(this);
  device = controll.getDevice("Generic   USB  Joystick  ");
  device.setTolerance(0.01f);
  xSlider = device.getSlider(0);
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  arduino.pinMode(escPin, Arduino.SERVO);
}

void draw(){
  background(255);
  xVal = xSlider.getValue();
  arduino.analogWrite(escPin,int(xVal*90+90));
}

Thanks
Logged

Pages: [1]   Go Up
Jump to: