arduino coding with...
 
Notifications
Clear all

arduino coding with servo controller

7 Posts
1 Users
0 Reactions
11.1 K Views
Posts: 55
Topic starter
(@andsolo21)
Trusted Member
Joined: 9 years ago
[#48361]

below is a bunch of conversations ive had recently with Chris (ctmal), thought we'd post them incase there are any others out there who are also in need and also how much thought process you have to go through. Personally im still no closer, but i can see light at the end of the tunnel and i'm enjoying the challenge, although Chris may think im a pain, but again being a newbie having guys like him, and also Martin who has helped me understand the relays/ssr's and zero cross systems, are an absolute godsend, waffle over conversation below


6 Replies
Posts: 55
Topic starter
(@andsolo21)
Trusted Member
Joined: 9 years ago

Quote Originally Posted by Andsolo21
Hi Chris

Sorry to pes u with a private message but is it possible to pick your brains over thee servos and vixen, I’ve done everything that was in the video but I still get very little if any movement at all any idea where I’m going wrong

I’ve done away with the pca servo unit and wired direct to the pins on alternate power and adjusted my arduino code to suit

Any help would be greatly appreciated

Thanks
Andy

It's no bother....at what point are you seeing no movement? Is it just when you are using the Object Suite or is it anything that is coming out of Vixen? If you haven't already, I would start with a sequence that's just something simple like a ramp from 0 to 100% and make sure that is working ok with your servo controllers. The results should point us in the right direction.


Reply
Posts: 55
Topic starter
(@andsolo21)
Trusted Member
Joined: 9 years ago

Quote Originally Posted by Andsolo21
Hi Chris did a quick test with the code that i sent in the previous message but i tested the movement before powering up and noticed the servo was on full lock (clockwise) so i span it the opposite way and on plugging in the uno the servo locked itself to the clockwise position, i did a ramp on and off as a test sequence and didnt get anything

using the servo test from the sketches the servo spins back and forth without any issues
Ok. That makes sense. The issue it looks like you are running into is that the servos require a pulse every 20ms whether the data changes or not. Vixen only sends data the when there is a change in data. So, essentially, your Arduino and Vixen aren't really talking the same language.

I don't really know Arduino but assuming I'm reading it right, there are a couple of issues.
1. The timing issue I just talked about.
2. Do don't see any place where you are handling the information sent from Vixen(You could be, I just don't see it).
3. As soon as you enter that loop, you are not ever leaving it to do other things...so, for example, the servo variable can never change.

Based on the way I did it in the renservo, here's some ideas....
1. You need a variable to contain the Vixen data. From this (when you get the data) you can calculate your pulse value. i.e, 0 would be 0, 255 would be 1500(using your value here) and 127 would be 750.
2. I'm assuming the Arduino has/uses timers? Depending on how many you can have/use determines how you would generally set it up. The general idea is that you set a 20ms timer. When that timer ticks, you set a timer for your pulse and set the pin to active. When that 2nd timer ticks, you turn it off. In the meantime, the 'main' program will be listening for data from Vixen.

So, as a starter, I would set it up like this(again, I don't know Arduino so I'm just sectioning off functions assuming you can do it).

int VixenData = 0;
void PulseStart()
{
//this would get called when the 20 ms timer goes off
-set the 2nd timer for your calculated pulse width using the VixenData variable.
-set the output to high
}

void PulseStop()
{
//this would get called when the 2nd timer ticks.
-set the output pulse low
}

void ReceivedVixenData(int data)
{
//would just need to be called when VixenData is received
-set the incoming data to the VixenData variable.
-you might want to calculate your pulse width variable here.
}

MainLoop()
{
-Here you would just basically keep checking for incoming data.
-When data is received you'll call the RecievedVixenData to set the data. The timer's are actually doing the work for the servo.
-For testing, you could do something like this to testing(and bypass Vixen until you know it's working):
-increase VixenData by 1;
-Call RecievedVixenData{VixenData)
-Delay 500ms
-loop
}

I hope that makes sense. Let me know.
Chris


Reply
Posts: 55
Topic starter
(@andsolo21)
Trusted Member
Joined: 9 years ago

Quote Originally Posted by Andsolo21
Fantastic i'll have a look at this now will be in touch in a bit
It just dawned on me that, while I was in a rush to get you a reply, I think I gave you some bad information.
Servo's expect to receive a pulse every 20ms. For the most capable servo's, that pulse generally needs to be between .5ms for the extreme to one direction to 2.5ms for the other direction(these are extremes, so your servo's probably won't handle that range). So, if you receive data from Vixen(or from any other source), you have to calculate your pulse with that in mind. In other words, if you get 0 from Vixen your pulse would be .5ms long and if you get 255 your pulse would be 2.5ms long. The middle is pretty standard at 1.5ms.

To get the actual pulse width's required you'll have to look at your servo's manuals. The recommended values are usually a pulse between 1ms and 2ms.

Sorry about the bad information.
Chris


Reply
Posts: 55
Topic starter
(@andsolo21)
Trusted Member
Joined: 9 years ago

I didn't realize you were using a separate servo controller. What you've been creating here is actually a servo controller. I went back to your forum posts. It looks like that servo controller talks I2C. So, all you need the Arduino to do is to receive the signal from Vixen over the serial connection then configure/send the data out to the servo controller over I2C. You'll have to get the protocol that the servo controller needs from the manual.

So, in other words, you'll get the data from Vixen, create your packet/data that you need to send to the servo controller, then send it out I2C. It also appears that there are libraries and examples for you. Check out https://learn.adafruit.com/16-channel-pwm-servo-driver .

Quote Originally Posted by Andsolo21
thats the bit im suffering with ive worked through several tutorials and can get them to work but can figure out how to get them to work for what i need

Did you go through this page? https://learn.adafruit.com/16-channe...afruit-library

If looks like after you install the adafruit library you should be able to start the example right away. If you aren't getting any action you're probably not wired up correctly.


Reply
Posts: 55
Topic starter
(@andsolo21)
Trusted Member
Joined: 9 years ago

It might help if you step back a take a look at what this program does....keep in mind that I've never used an Arduino but the code looks fairly readable to me.

The program starts out by running setup(). This appears to setup the serial port at 9600 baud and sets up the pwm for the servo's. You'll want t change the baud rate to what you have in Vixen and you'll want to get rid of all the println's since Vixen doesn't support the 2 way communication.

Next, the program goes to Loop(). Here, it looks like it doing this....
1. Run a loop counting from the servomin(150) to servomax(600) and sending it out to the servo's at each step. This moves the servo completely to one direction.
2. It then pauses with the delay(500)
3. It does the same as step 1 only running from Max to min. This moves the servo in the other direction.
4. Next, servonum++ advances the program to the next servo and it all runs again.

So, from this, there are a couple things to learn.
1. I don't see setServoPulse being used at all. I'm not sure that it's needed.
2. You now know that the lowest pulse is 150(this will relate to 0 in Vixen) and the max is 600(this will relate to 255 in Vixen).
3. You now know how to assign a value to the servos...pwm.setPWM(servonum,0,pulselen)

So, how do you modify the code to work with Vixen?
Basically in the loop() section all you will need to do is listen for the Vixen data, when it comes in translate it from a 0-255 value to a 150-600 value, and write it to the servo pwm.setPWM(servonum,0,puslelen).

So, for example, lets say you have 8 servo's set up in Vixen. When you receive the data in the Arduino you would receive the values for the 8 servos. Once you have those values you'll have to process each of them. For each one you'll do the math to translate the 0-255 data value to a 150-600 data value that the servo assigns and send it out to the correct servo using pwm.setPWM....

The Arduino servo code that you downloaded is already doing the hard work of handling the actual sending of the data out to the servos for you.


Reply
Posts: 55
Topic starter
(@andsolo21)
Trusted Member
Joined: 9 years ago
Quote Originally Posted by Andsolo21
wow thanks chris, thats explained it perfectly, i do have one possibly stupid question.... how does vixen or the arduino know what channel is which, sorry am like a dog with a bone on this now and would this be the headers that people are on about, would i have to put in an int servo etc?
sorry

That's not a stupid question at all. I'm not really sure what headers you are talking about...maybe for the Vixen serial plugin?

You really just need to understand how Vixen is sending the data, then you can figure that out. So, depending on what Vixen plugin you use it'll receive a packet of all channels sent. So, I'm guessing you are going to be using the generic serial plugin from Vixen. All that does is send the data out the serial port for all channels any time any channel changes.

So, for example, if you have 3 channels set up in Vixen, any time there is data to send(this happens when the value for any channel changes) Vixen will send the data for all channels. So, your Arduino will receive 'Channel 1, Channel 2, Channel 3'. So, you know that the first byte of the data received will be for servo 0, then servo 1, then servo 2.

As far as headers are concerned...
You may run into some issues if you process data as freely and without checks as you are doing here. For example, what happens if there's a glitch somewhere and you only receive 2 bytes of data? The arduino wouldn't know how to handle it and may cause it to do something wrong. Generally serial devices work out some sort of handshake or checking mechanism when receiving the data. This can be done easily by starting each packet of data sent by Vixen with a specific series of characters/control data, etc. When you receive the data in the Arduino you would check the data to ensure the specified string of data. This would/could mark the start of a specific data stream, could send information such as how many channels of data to expect, etc. It really could get pretty involved. I think this is what you are hearing about with the header comments. I you are interested in this check out the wiki for the Renard Protocol. It's a pretty good example of how it can be done.

For now though, until you are up and running I think you should be fine assuming all is data.


Reply
Share: