Go Down

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

PaulS

Quote
Can i change this code for rpm data???

In place of speed, or in addition to?

What is packet? It looks like some kind of struct. What is in packet? Does it have something analogous to Speed that contains rpm, instead?

tommy27

Rpm in addition to speed with 2 servo: one for speed and one for rpm

PaulS

The correct ratio is one answer per question.

tommy27

Quote

What is packet? It looks like some kind of struct. What is in packet? Does it have something analogous to Speed that contains rpm, instead?

Excuse me... Packet of the game?

PaulS

Since this no longer has anything to do with Arduino, I think you're on your own.

PeterH


Rpm in addition to speed with 2 servo: one for speed and one for rpm


If you are able to modify the software that is sending the speed commands to also send RPM commands then I don't see anything stopping you. The Arduino side of things would certainly be possible.
I only provide help via the forum - please do not contact me for private consultancy.

tommy27

with this code my servo is very crazy, why???  :~
Code: [Select]
#include <Messenger.h>
#include <Servo.h>

#define SPEED_SERVO_PIN 7
#define SPEED_SERVO_0_US 460
#define SPEED_SERVO_300_US 3000

#define RPM_SERVO_PIN 7
#define RPM_SERVO_0_US 460
#define RPM_SERVO_300_US 3000

Servo hand;
Messenger message;

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

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

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

void setSpeedServo(int speed)
{
  int microseconds = map(speed, 0, 300, SPEED_SERVO_0_US, SPEED_SERVO_300_US);
  hand.writeMicroseconds(microseconds);
}
void setRPMServo(int rpm)
{
  int microseconds = map(rpm, 0, 10000, RPM_SERVO_0_US, RPM_SERVO_300_US);
  hand.writeMicroseconds(microseconds);
}

void setSpeed()
{
  int speed = message.readInt();
  if (speed < 0 || speed > 230)
  {
    sendERROR();
    return;
  }
  setSpeedServo(speed);
  sendOK();
}
void setRPM()
{
  int rpm = message.readInt();
  if (rpm > 100000 || rpm < 0)
  {
    sendERROR();
    return;
  }
  setRPMServo(rpm);
  sendOK();
}
void onMessage()
{
  switch (message.readChar())
  {
    case 'V':
      sendVersion();
      break;
    case 'S':
      setSpeed();
      break;
    case 'R':
      setRPM();
      break;
    default:
      sendERROR();
      break;
  }
}

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

void setup()
{
  hand.attach(7);
  Serial.begin(9600);
  message.attach(onMessage);
 
  setSpeedServo(0);
}
void setup()
{
  hand.attach(7);
  Serial.begin(9600);
  message.attach(onMessage);
 
  setRPMServo(0);
}

void loop()
{
}

codlink

That sketch won't even compile...
//LiNK

tommy27

is this the error??
Code: [Select]
void setup()
{
  hand.attach(7);
  Serial.begin(9600);
  message.attach(onMessage);
 
  setSpeedServo(0);
}
void setup()
{
  hand.attach(8);
  Serial.begin(9600);
  message.attach(onMessage);
 
  setRPMServo(0);
}

codlink

//LiNK

AWOL

If it didn't compile, why complain that the servo went crazy?
"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.

tommy27


If it didn't compile, why complain that the servo went crazy?


with this
Code: [Select]
void setup()
{
  hand.attach(7);
  Serial.begin(9600);
  message.attach(onMessage);
  setSpeedServo(0);
  hand.attach(8);
  Serial.begin(9600);
  message.attach(onMessage);
  setRPMServo(0);
}

PaulS

Code: [Select]
  hand.attach(7);
  hand.attach(8);

Which pin do you want the servo attached to?

Code: [Select]
  Serial.begin(9600);
  Serial.begin(9600);

In case the 1st one didn't work, do it again. Why do you then assume the 2nd one worked? Why not a thirst and a fourth?

Code: [Select]
  message.attach(onMessage);
  message.attach(onMessage);

Ditto.

It's really time that you stop blindly cutting and pasting code in the hopes that something will work, and read and understand what the code is doing.

tommy27

Code: [Select]
 
hand.attach(7); //rpm servo
hand.attach(8); //speed servo

PaulS

The comments now say one thing (wrong). The code still says something else.

There is NO relationship between rpm and hand or between speed and hand. Meaningful names make all the difference.

Go Up