Pages: 1 2 [3] 4   Go Down
Author Topic: Help for servo question  (Read 2860 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 633
Posts: 50188
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

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

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 633
Posts: 50188
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The correct ratio is one answer per question.
Logged

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

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?
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 633
Posts: 50188
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

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

with this code my servo is very crazy, why???  smiley-confuse
Code:
#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()
{
}
Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That sketch won't even compile...
Logged

//LiNK

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

is this the error??
Code:
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);
}
Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 689
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yep...
Logged

//LiNK

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26487
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

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

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

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 633
Posts: 50188
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  hand.attach(7);
  hand.attach(8);
Which pin do you want the servo attached to?

Code:
  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:
  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.
Logged

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

Code:
 
hand.attach(7); //rpm servo
hand.attach(8); //speed servo
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 633
Posts: 50188
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 2 [3] 4   Go Up
Jump to: