Go Down

Topic: Help for servo question (Read 3213 times) previous topic - next topic

tommy27

I think that asking a lot. I just want to do something other than simple LEDs and a potentiometer/servo code. Excuse me.

codlink

Change

Code: [Select]
Messenger message;

To this

Code: [Select]
CmdMessenger message;

They are telling you it's called CmdMessenger not just Messenger..
//LiNK

Groove

So, there is a list of candidate constructors.
Pick the one that matches your requirements.
Per Arduino ad Astra

codlink

I had a look at this and I must say, it baffles me (which is easily done).  For one the example code that website gives is full of errors.  I have attempted to fix the errors but was unsuccessful on some of them (trust me, there was a ton). 

This is the code that I came up with:
Code: [Select]
#include <Messenger.h>
#include <Servo.h>

#Define SPEED_SERVO_PIN = 2
#Define SPEED_SERVO_0_US = 2800
#Define SPEED_SERVO_200_US = 870

Servo hand;
Messenger message;

sendVersion void()
{
Serial.Println(F ("AD ArduDash 01.12"));
}

Sendok void()
{
Serial.Println(F ("OK"));
}

sendError void()
{
Serial.Println(F ("ERROR"));
}

setSpeedServo void(int speed)
{
int microseconds = map (speed, 0, 200, SPEED_SERVO_0_US, SPEED_SERVO_200_US);
hand.writeMicroseconds (microseconds);
}

setSpeed void()
{
int speed = message.readInt ();
if (speed <0 | | speed> 230)
{
sendError();
return;
}
setSpeedServo(speed);
Sendok();
}

void OnMessage()
{
switch(message.readChar())
{
case 'V':
sendVersion();
break;
case 'S':
setSpeed();
break;
default:
sendError();
break;
}
}

serialEvent void()
{
message.process(Serial.read());
}

void setup()
{
hand.attach (2);
Serial.Begin (19200);
message.attach(OnMessage);

setSpeedServo(0);
}

void loop ()
{
}


It is "Messenger" according to the library and the example code. 
Code: [Select]
Messenger message;

But can't get it to compile myself.  If someone that has more knowledge on libraries could look at it, they could tell you more.

Here's the compile errors:

Code: [Select]
sketch_oct31a.ino:4:2: error: invalid preprocessing directive #Define
sketch_oct31a.ino:5:2: error: invalid preprocessing directive #Define
sketch_oct31a.ino:6:2: error: invalid preprocessing directive #Define
sketch_oct31a:9: error: expected constructor, destructor, or type conversion before 'void'
sketch_oct31a:10: error: expected constructor, destructor, or type conversion before 'void'
sketch_oct31a:11: error: expected constructor, destructor, or type conversion before 'void'
sketch_oct31a:12: error: expected constructor, destructor, or type conversion before 'void'
sketch_oct31a:13: error: expected constructor, destructor, or type conversion before 'void'
sketch_oct31a:15: error: expected constructor, destructor, or type conversion before 'void'
sketch_oct31a:2: error: 'Messenger' does not name a type
sketch_oct31a:4: error: expected constructor, destructor, or type conversion before 'void'
//LiNK

PaulS

First, it's #define, not #Define. That will get rid of the 1st three error messages.

Second, you have the function name in front of the type. That's completely backwards. There goes the next 6 messages.

Third, Messenger is obsolete. CmdMessenger replaces it. Trying to modify examples for obsolete classes is a waste of time. Doing so when you don't know what you are doing is even more so.

pico



#Define SPEED_SERVO_PIN = 2
#Define SPEED_SERVO_0_US = 2800
#Define SPEED_SERVO_200_US = 870



Also, there is no equals sign in a #define directive. What these should be is:

#define SPEED_SERVO_PIN  2
#define SPEED_SERVO_0_US  2800
#define SPEED_SERVO_200_US  870

Another common mistake is for people to put a semicolon at the end of the #define directive, like this:

#define SPEED_SERVO_PIN  2; // <-- don't do this!

Not that you've done that here, but just to aware of another common mistake.

Some people prefer to replace #define preprocessor directives with

static const int SPEED_SERVO_PIN = 2;

which is actually a compiler statement, and allows for more rigorous type checking. It accomplishes much the same thing in most common contexts.
WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

codlink

#21
Oct 31, 2012, 05:46 pm Last Edit: Oct 31, 2012, 05:49 pm by codlink Reason: 1

First, it's #define, not #Define. That will get rid of the 1st three error messages.


I am shaking my head that I did not catch that..

Quote

Second, you have the function name in front of the type. That's completely backwards. There goes the next 6 messages.


That's what I get for not being experienced..

Quote

Third, Messenger is obsolete. CmdMessenger replaces it. Trying to modify examples for obsolete classes is a waste of time. Doing so when you don't know what you are doing is even more so.
From the tutorial he was following, they were using Messenger.  It looked like the tutorial was pretty old, so I downloaded that library and installed it.  The example has:
Quote
Messenger message;

I have written it many different ways and still get the error..


@Pico
I knew there wasn't supposed to be an equals sign, but was trying to get the error to go away and I was grasping at straws..  It never even crossed my mind about the capitol "D"
//LiNK

codlink

Thanks to Paul and Pico, I got it to compile.  Tommy, if your still around try this code:

Code: [Select]
#include <Messenger.h>
#include <Servo.h>

#define SPEED_SERVO_PIN 2
#define SPEED_SERVO_0_US 2800
#define SPEED_SERVO_200_US 870

Servo hand;
Messenger message;

void sendVersion()
{
Serial.println(F ("AD ArduDash 01.12"));
}

void Sendok()
{
Serial.println(F ("OK"));
}

void sendError()
{
Serial.println(F ("ERROR"));
}

void setSpeedServo(int speed)
{
int microseconds = map (speed, 0, 200, SPEED_SERVO_0_US, SPEED_SERVO_200_US);
hand.writeMicroseconds (microseconds);
}

void setSpeed()
{
int speed = message.readInt ();
if (speed <0 || speed> 230)
{
sendError();
return;
}
setSpeedServo(speed);
Sendok();
}

void OnMessage()
{
switch(message.readChar())
{
case 'V':
sendVersion();
break;
case 'S':
setSpeed();
break;
default:
sendError();
break;
}
}

void  serialEvent()
{
message.process(Serial.read());
}

void setup()
{
hand.attach (2);
Serial.begin(19200);
message.attach(OnMessage);

setSpeedServo(0);
}

void loop ()
{
}
//LiNK

tommy27

#23
Nov 01, 2012, 11:05 am Last Edit: Nov 01, 2012, 11:37 am by tommy27 Reason: 1
http://www.youtube.com/watch?v=Dwen0izz4q4&feature=youtu.be  :)

codlink

Nice vid Tommy! 

You could always give it a shot!
//LiNK

tommy27

Can I export rpm data for an other servo with python?

PaulS

Quote
Can I export rpm data for an other servo with python?

This question does not make sense. RPM is a measure of speed. How can python, on the PC, know how fast something connected to the Arduino is turning?

AWOL

Quote
This question does not make sense.

It does, if you watch the video  ;)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

Quote
It does, if you watch the video

I watched the video. It still doesn't.  The context in which it might make sense is missing. The python script and the Arduino code, to be specific.

tommy27

Can i change this code for rpm data???

Code: [Select]
import time
import pyinsim
import serial

ARDUINO_PORT = 'com3:'

arduino = serial.Serial(ARDUINO_PORT, 19200, timeout=1)
time.sleep(3)

def outgauge_packet(outgauge, packet):
  speed_kmh = int(packet.Speed*3.6)
  speed_command = 'S {0}\r'.format(speed_kmh)
  arduino.write(speed_command)
  arduino.flushInput()


outgauge = pyinsim.outgauge('127.0.0.1', 30000, outgauge_packet, 30.0)

pyinsim.run()

Go Up