Shop OBEX P1 Docs P2 Docs Learn Events
Servo Controller USB to Matlab — Parallax Forums

Servo Controller USB to Matlab

ewodulewodul Posts: 22
edited 2013-01-30 18:34 in General Discussion
Hello,

I'm trying to control the Crustcrawler 400HFS thruster, using a ESC (Castecreations hydra120) and a PC. Is it possible to send control signals from my PC using Matlab/Simulink software to the parallax servo controller?

Thanks,

E.
«1

Comments

  • ewodulewodul Posts: 22
    edited 2011-08-01 07:47
    Anyone? Do I need to send a PWM signal to the parallax servo controller or other signals?
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-08-01 14:57
    The Parallax Servo Controller accepts a series of serial commands that can be found in the documentation located here
  • ewodulewodul Posts: 22
    edited 2011-08-01 15:10
    Thanks for your reply!

    What output does the PSC produce? I presume a PWM signal? I'm asking this because the device connected to the PSC (the Hydra 120 ESC) has a PWM input, and I would like to know if I can send my control signal directly to the Hydra or not.
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-08-01 15:22
    With the default firmware, the output is designed to directly interface to a Standard Hobby servo, see here on page 3 for details on the output pulse.

    Since I'm not familiar with the "Hydra 120 ESC", I can't say for sure, but if it accepts standard RC servo signals (most ESC's do) then it should work as if the signal is coming from the receiver.
  • ewodulewodul Posts: 22
    edited 2011-08-03 06:10
    The manual is only showing examples about servos, how does the coding change when using a brushless thruster? (I'm using crustcrawler 400HFS - Hydra 120 ESC - Paralax servo controller usb - PC). Obvious, I don't want the thruster to rotate to a certain angle, but I want the thruster to operate at variable thrust (like 0%-90% thrust, depending on my calculated control signal).

    Which software can I use to send the commands? Does Pbasic work with the PSC? Can I also use e.g. Visual Basic or something?

    I'm sorry if I'm asking stupid questions - but my knowledge about this matter is quite "low", what makes it difficult to understand all the information I found in the manuals/fora/internet/etc.
  • PublisonPublison Posts: 12,366
    edited 2011-08-03 08:13
    ewodul wrote: »
    The manual is only showing examples about servos, how does the coding change when using a brushless thruster? (I'm using crustcrawler 400HFS - Hydra 120 ESC - Paralax servo controller usb - PC). Obvious, I don't want the thruster to rotate to a certain angle, but I want the thruster to operate at variable thrust (like 0%-90% thrust, depending on my calculated control signal).

    Which software can I use to send the commands? Does Pbasic work with the PSC? Can I also use e.g. Visual Basic or something?

    I'm sorry if I'm asking stupid questions - but my knowledge about this matter is quite "low", what makes it difficult to understand all the information I found in the manuals/fora/internet/etc.

    The signal to ESC looks just like a servo signal. A quote from Wikipedia:
    The ESC generally accepts a nominal 50 Hz PWM servo input signal whose pulse width varies from 1 ms to 2 ms. When supplied with a 1 ms width pulse at 50 Hz, the ESC responds by turning off the DC motor attached to its output. A 1.5 ms pulse-width input signal results in a 50% duty cycle output signal that drives the motor at approximately half-speed. When presented with 2.0 ms input signal, the motor runs at full speed due to the 100% duty cycle (on constantly) output.

    VB would certainly work, but you said you were using MatLab. Can MatLab send info out of a serial port, (or USB Virtual Comm Port)?

    PBasic is used to program BS2 chips. You can't program the Servo Controller with PBasic.
  • ewodulewodul Posts: 22
    edited 2011-08-03 08:51
    Yes, Matlab is able to send info out of a serial port. I already managed to receive the firmware version of the PSC using the Matlab code

    ser = serial('COM3');
    set(ser,'BaudRate',2400);
    fopen(ser);
    fwrite(ser,[33 83 67 86 69 82 63 36 79 68]); % the numbers are the ascii representation of the commands
    fscanf(ser);

    However, the rest of the sample code in the PSC's manual seems useless, as it's for servos and not for brushless motors... So I want the thruster to operate at variable thrust (like 0%-90% thrust, depending on my calculated control signal). I hope someone can give me more information about how to do this, either using the PWM signal on my ESC or some codes using the PSC + ESC.
  • Shawn LoweShawn Lowe Posts: 635
    edited 2011-08-03 09:20
    ewodul wrote: »
    Yes, Matlab is able to send info out of a serial port. I already managed to receive the firmware version of the PSC using the Matlab code

    ser = serial('COM3');
    set(ser,'BaudRate',2400);
    fopen(ser);
    fwrite(ser,[33 83 67 86 69 82 63 36 79 68]); % the numbers are the ascii representation of the commands
    fscanf(ser);

    However, the rest of the sample code in the PSC's manual seems useless, as it's for servos and not for brushless motors... So I want the thruster to operate at variable thrust (like 0%-90% thrust, depending on my calculated control signal). I hope someone can give me more information about how to do this, either using the PWM signal on my ESC or some codes using the PSC + ESC.
    Why is it useless? Your ESC accepts PWM signals designed for servos. A 1.0 ms signal is like 0%, a 1.5ms signal is like 50%, a 2.0ms signal is like 100%. Just use matlab to have the PSC send out a 1.5 ms PWM to your ESC and see if it makes the motors run.
  • PublisonPublison Posts: 12,366
    edited 2011-08-03 09:25
    ewodul wrote: »
    Yes, Matlab is able to send info out of a serial port. I already managed to receive the firmware version of the PSC using the Matlab code

    ser = serial('COM3');
    set(ser,'BaudRate',2400);
    fopen(ser);
    fwrite(ser,[33 83 67 86 69 82 63 36 79 68]); % the numbers are the ascii representation of the commands
    fscanf(ser);

    However, the rest of the sample code in the PSC's manual seems useless, as it's for servos and not for brushless motors... So I want the thruster to operate at variable thrust (like 0%-90% thrust, depending on my calculated control signal). I hope someone can give me more information about how to do this, either using the PWM signal on my ESC or some codes using the PSC + ESC.

    As I eluded to in my last post, and ESC is looking for exactly the same signal that a servo is looking for.

    EDIT: I see Shawn posted as I was typing.

    Normally, something like 1ms pulse width would be around 0% throttle. 2ms would be 100% throttle. You may have to adjust the numbers up or down for your particular ESC. Don't forget the conversion of numbers the PSC wants to see.
    All pulse width values are specified in 2 μs increments, so to send a 1 ms pulse to a
    channel you would use a pulse width value of 500 (500 x 2 μs = 1000 μs = 1 ms).
    Position Command – Set Position of a Servo Channel
    Syntax: &#8220;!SC&#8221; <channel> <ramp speed> <lowbyte> <highbyte> <CR>
    

    Set your Ramp Speed to zero so the command is immediate and there is no timing lag. I would send your first command to 0% throttle, as some ESC's will not start up if the throttle is anything but 0%.

    Sound like you have the communications figured out. That's the hard part. :smile:
  • ewodulewodul Posts: 22
    edited 2011-08-03 10:04
    Thanks a lot. I'm even starting to feel a bit less NOOB :)

    I will send a 1,6 ms pulse, as my ESC will see this as 20% throttle. This means a 750 PWM signal because of the 2 us increments, on channel 0, with 0 ramp speed;

    750 -> lowbyte 32, highbyte 3

    Matlab will send ascii commands (the PSC is accepting them), so can I send the following command line:

    !SC00323

    or do I need to use seperation characters or 00 instead of 0?
  • Shawn LoweShawn Lowe Posts: 635
    edited 2011-08-03 13:05
    ewodul wrote: »
    Thanks a lot. I'm even starting to feel a bit less NOOB :)

    Matlab will send ascii commands (the PSC is accepting them), so can I send the following command line:

    !SC00323

    or do I need to use seperation characters or 00 instead of 0?
    Not sure, but if MATLAB is communcating, a little experimentation should light your way! Good Luck
  • ewodulewodul Posts: 22
    edited 2011-08-04 07:03
    Well part of the communication seems to work, I've managed to retrieve the PSC firmware version to Matlab. Sending position commands however doesn't seem to work. Right now, I have the following code:

    psc=serial('COM3', 'Baudrate', 2400, 'Terminator', 'cr');
    fopen(psc);
    fwrite(psc, [33 83 67 0 0 232 3 13], 'uint8', 'sync')

    Here I'm trying to make 2ms pulses (so 1000 increments of 2 micros., so lowbyte 232 highbyte 3) to channel 0 with 0 ramp. The PSC does flash a led shortly, but nothing is happening with my motor. I also dont receive an error message on my com line.

    I've connected a scope to the pulse pin of channel 0 of my PSC, and it's constantly sending a 20 ms block signal, and it doesn't change when I'm sending other signals... Something wrong with my code? What should be the normal output of the PSC when not receiving any code?
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-08-04 07:28
    ewodul,

    Just for kicks have you tried enabling the servo channel? I don't have a unit in front of me at the moment to test this theory, but I can later today.

    Syntax: “!SCPSE” <channel> <CR>
  • ewodulewodul Posts: 22
    edited 2011-08-04 08:48
    I tried to enable the channel, and when I try to make 2ms pulses for full forward I send a 1000 PWM signal (2 micros. increments), resulting on a PWM signal on my scope with a period of 20ms and duty cycle 10%. The output of my PSC seems to be correct right? (it should be 50Hz I think, so that's the 20 ms period)

    However, no movement from my brushless motor, also no reaction from my Hydra 120 ESC... So I guess I have to check my powersuply (I'm using a fixed voltage (12V) powersupply that can deliver up to 3 amps, which I think should be sufficient for just testing my motor).
  • PublisonPublison Posts: 12,366
    edited 2011-08-04 09:37
    ewodul wrote: »
    Well part of the communication seems to work, I've managed to retrieve the PSC firmware version to Matlab. Sending position commands however doesn't seem to work. Right now, I have the following code:

    psc=serial('COM3', 'Baudrate', 2400, 'Terminator', 'cr');
    fopen(psc);
    fwrite(psc, [33 83 67 0 0 232 3 13], 'uint8', 'sync')

    Here I'm trying to make 2ms pulses (so 1000 increments of 2 micros., so lowbyte 232 highbyte 3) to channel 0 with 0 ramp. The PSC does flash a led shortly, but nothing is happening with my motor. I also dont receive an error message on my com line.

    I've connected a scope to the pulse pin of channel 0 of my PSC, and it's constantly sending a 20 ms block signal, and it doesn't change when I'm sending other signals... Something wrong with my code? What should be the normal output of the PSC when not receiving any code?

    It doesn't look like you are including the quotation marks in the Preamble, (ASCII 34). I'm pretty sure they are necessary, so your transmitted data may have to look like this:
    fwrite(psc, [34 33 83 67 34 0 0 232 3 13], 'uint8', 'sync')
    

    Sample from a BS2 program:
    SEROUT PIN, BAUD,["!SC", ch, ra, pw.LOWBYTE, pw.HIGHBYTE, CR]
    
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-08-04 09:57
    @ewodul,

    "...resulting on a PWM signal on my scope with a period of 20ms and duty cycle 10%...." - That sounds correct. Make sure that you are sharing the ground between the ESC and the Servo Controller. Do NOT share the power. <-- even thought the datasheet for your ESC indicates that the ESC supplies power, the Propeller controller will not work that way and needs it's own supply to operate correctly.

    @Publison,

    "It doesn't look like you are including the quotation marks in the Preamble,..." - That's only part of the PBASIC code... ewodul is sending the data correctly as far as I can tell.
  • ewodulewodul Posts: 22
    edited 2011-08-04 10:05
    Make sure that you are sharing the ground between the ESC and the Servo Controller. Do NOT share the power. <-- even thought the datasheet for your ESC indicates that the ESC supplies power, the Propeller controller will not work that way and needs it's own supply to operate correctly..

    I'm not sure what you mean; right now, the PSC is connected via USB to my PC, which should provide the power the PSC needs? Then the 3wire PWM cable is going to my ESC, and the ESC has 2 seperate power cables, which are connected to the + and - of my power supply
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-08-04 10:33
    ewodul,

    According to the schematic on the PSC, just don't supply the 'servo power' from the PSC connector, and you should be ok. In your case, the ESC would be supplying the servo power instead to the PSC.

    Schematic reference:
    http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PSCUsb_A%20Schematic.pdf
  • ewodulewodul Posts: 22
    edited 2011-09-22 07:20
    I'm still figuring out how to let the PSCU work with my HFS400 Thruster. Right now it does still not work for some reason.

    The thruster and ESC are working fine; I managed to produce a PWM signal using a DSpace board. This resulted in rotating my thruster in a way I controlled it.

    I used the following connections here:

    On my ESC:
    -24V to the 2 power supply cables,
    -the pwm cable, which consists of 3 wires (Brown, Red, Orange), connected as: Brown -> GND, Red -> +5V, Orange -> PWM pulse signal 50HZ

    Then the ESC is connected to the thruster with 3 wires. By varying the PWM pulse width of the orange cable i managed to chenge the thrusters speed as described in the manual.

    This does not work with my PSCU.

    The PC - PSCU connection seems fine; I am able to vary the pulse width of e.g. channel 0. I measured this signal on a scope and it seems ok. It has a height of 4.8V, and the PWM signal is 50HZ.

    But when I connect my ESC to the PSCU it does still not work. I connect Orange(ESC) with Wite(PSCU), Red(ESC) with Red(PSCU) and Brown(ESC) with Black(PSCU) by just plugging the 3wire pwm cable of my ESC into the channel 0 connection of the ESC. The PSCU is connected to my PC by USB.

    Does anyone now where I do something wrong? Really stuck here...
  • Shawn LoweShawn Lowe Posts: 635
    edited 2011-09-22 07:26
    Just really quick, try reversing the 3 wire cable
  • ewodulewodul Posts: 22
    edited 2011-09-22 07:40
    On the PSCU board you mean? Already tried ;)...

    Also I'm quite sure the connectors at the inside row on the PSCU board (all denoted with a "W") are the pulse connectors, as I measured a PWM signal on that specific connector using a scope.

    Measuring B and R on the PSCU board resulting in some strange signals around 100mV.
  • PublisonPublison Posts: 12,366
    edited 2011-09-22 08:02
    ewodul wrote: »
    Measuring B and R on the PSCU board resulting in some strange signals around 100mV.

    The "B" is Ground and the "R" is the Servo Power from the green terminal.

    (Make sure the switch is on)
  • ewodulewodul Posts: 22
    edited 2011-09-22 08:25
    OK I guess the problem is with the B and R connections then..

    Should I also connect a voltage to the servo power input on the PSCU? My thruster has it's "own" seperate power supply, so right now I do not use the servo power input at all.

    How is the PSCU grounded? Throught the usb connection port?
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-09-22 09:03
    24V huh? ... yeah I would probably want to keep that voltage away from the PSCU.

    In the first page of the document.. http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/28830-PropServoControllerUSB-v1.0.pdf ... under Key Specifications
    Power requirements: 5 VDC @ ~60 mA for logic, 4.8 – 7.5 VDC for servos (do not exceed your
    servos’ input voltage rating)

    here is the schematic:
    http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PSCUsb_A%20Schematic.pdf

    The Green connector fortunately only supplies power to the power connector on the servo heads if the switch is 'on' ... my concern is, that the C11 and C12 might have been damaged with the 24V. I don't have the BOM (Bill Of Materials), but those caps are probably not rated for more than 16V.

    If your ESC is already powered, all you need to share with the PSCU is Ground and signal, thus eliminating the capacitors if there is a chance that they are causing a problem.
  • ewodulewodul Posts: 22
    edited 2011-09-22 09:10
    I've never connected any power supply to the PSCU. The 24V I've mentioned, was in the setup WITHOUT the PSCU (and unfortunately that's the only setup that works). The 24V is connected to my Hydra120 ESC, which powers the thruster.

    The only connections I use on my PSCU is the usb to PC and channel 0 to the PWM cable of my hura 120 ESC
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-09-22 09:18
    The PWM cable from your Hydra120 ESC could be supplying the 24V into the PSCU, regardless of the switch position on the PSCU. Still, the red wire to the PSCU is not necessary if your ESC is already powered.
  • ewodulewodul Posts: 22
    edited 2011-09-22 09:58
    Ok I will try to only connect GND and signal with my Hydra ESC. The manual of my thruster did not mention this at all so thanks for explaining it to me.

    So the servo power switch could stay in OFF position?

    Is my PSCU proper grounded (through USB or something?) or do I need to add some "grounding"?
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-09-22 10:02
    The Servo connector on the PSCU, needs to share the same ground as well as the same signal to the Hydra ESC. And yes, in your particular setup, the switch could stay off.
  • PublisonPublison Posts: 12,366
    edited 2011-09-22 11:29
    @ewodul

    Would it be possible for you to draw a schematic or sketch out how you have connected all the item, including the power? That would really help.

    And include the part number of the PSC board. Parallax made three different boards.

    Jim
  • ewodulewodul Posts: 22
    edited 2011-09-22 11:37
    Publison wrote: »
    Would it be possible for you to draw a schematic or sketch out how you have connected all the item, including the power? That would really help.
    And include the part number of the PSC board. Parallax made three different boards.

    I will try Beau's tips first when I'm back in the lab tomorrow. If it's working, I will be a very happy person and I let you know. If it's still not working, I will upload a picture and/or draw a schematic to show my setup, I totally agree that will talk more easy :)
Sign In or Register to comment.