Servo Controller USB to Matlab
ewodul
Posts: 22
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.
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.
Comments
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.
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.
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:
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.
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.
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.
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?
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?
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>
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).
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:
Sample from a BS2 program:
"...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.
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
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
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...
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.
The "B" is Ground and the "R" is the Servo Power from the green terminal.
(Make sure the switch is on)
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?
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.
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
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"?
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
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