Author Topic: Remote Servo Control  (Read 13449 times)

bstott

  • Newbie
  • *
  • Posts: 37
Remote Servo Control
« on: August 09, 2013, 05:11:02 PM »
8/9/13 Starting a ---> Simple ( :-\) Remote Servo Control <--- Project
-----------------------------------------------------
Edit: 9/12/2013
Well I've written the Transmitter and Receiver code and made a cell phone video. I'm now a 'C' programmer. I've a new wireless video system. Guess that makes me a wireless system programmer. Yahoo! Read down to the last post or just scroll down.

----------------------------------------

I am beginning an attempt to remotely control a hobby servo.

My project complications are:
  • I do not program.
  • I know next to nothing about RF.
  • I will NOT take the easier route to use two Moteinos to create the radio communications.
  • I will take the easier route using two Moteinos for both ends of the communications.
  • Murphy wrote his laws observing someone like me.
Objectives to learn and understand - How To:
  • Create a radio communications link using two RFM69 enabled Arduino clones - A 2 Moteinos and a Femtoduino.
  • Remotely control a servo motor via a radio communications link.
  • Use Moteino as a controller to integrate wireless control into an existing non-LowPowerLab enabled system.
BOM:I have complicated this effort by creating a Femtoduino system consisting of a Femtoduino (A miniature Arduino clone.), an attached servo motor and an RFM69 for motor actuation and radio communications. The Femtoduino system will be radio connected to an RFM69 enabled Moteino with an attached pot acting as the remote servo motor controller. These two systems will be built from LowPowerLab's products and radio communications firmware, various servo and RF libraries and example sketch fragments to be assembled and loaded.

Steps:
  • Connect the Moteino to the Arduino IDE and test with Blink and/or some other sketch.
  • Load DualOptiboot (?) onto the Femtoduino and test with Blink and/or some other sketch.
  • Figure out how I'm going to power the two sides of the communications link.
  • Build the two battery power systems for the Femtoduino system and  the Moteino systems.
  • Connect the RFM69 to the Femtoduino, program RF and test. How to test?
  • Connect the Moteinos and Femtoduino via RF and test. What test samples to use?
  • Connect Servo and Pot to Femtoduino Moteino, program and test. Get servo to work locally first with Radio firmware installed.
  • Remove pot code from Femtoduino.
  • Connect pot to Moteino and load program. Attempt radio connection with other Moteino Femtoduino and make the remote servo move.
  • Success? ---> Smile and post sharing (bragging about) results. Fail? ---> Frown and post sharing (complaining about) results.
  • Refine and keep figuring how to optimize. Utilize Layman's Six Sigma processes - keep fixing till it works.

Questions(?):
Q.: Will Lipo batteries work to power the two systems?  A one cell Lipo is 3.7 volts.
    If Yes, I have two 1S Li-ion cells which may be used.

In Process:
 :'( when nothing works. Then, Lol....

--- Your thoughts are welcomed.  :)


Edit 9/9/2013: Upon Felix's suggestion, a few weeks ago, I've conceded to simplify this by starting with two (2) Moteinos instead of a hybrid system. I can complicate things later.  ;D


Femtoduino?  Tiny Arduino Clone ---> See Attached photo and follow the link in the BOM above.
« Last Edit: September 12, 2013, 09:31:56 PM by bstott »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5385
  • Country: us
    • LowPowerLab
Re: Remote Servo Control
« Reply #1 on: August 09, 2013, 06:00:09 PM »
Hey Brian,
Here are my thoughts:

Not sure how easy it will be for you to interface to the Femto, neat device but it's pretty small. Even Moteino is pretty small. If you get a RFM69 standalone, for $12 more you can get a full Moteino, or you can even get it separate. Not trying to market for my products, but I try to imagine how much hassle it might become to interface a RFM69 to Femtoduino. It can probably work, but my bootloader has some special fuses that take care of some delays which you might have to code for. Which brings me to the next point - you mentioned reflasing Femto with my bootloader. That would be fine, but if you haven't done that before, it will be quite a ride. You will need to fuse it to 16mhz. Moteino fuses are : Ext:0xfd, Hi:0xdc, Lo:0xde

I just looked at the schematics and from what I can gather, the Femtoduino works at 5V which is a big no-no for RFM69. You will fry it if you connect anything above 3.6V to it, power and data included. That's unless your home made version is 3.3V.

Moteino can however be powered with anything from 3.3V to 12V on the "VIN" pins.

So while I appreciate your desire to NOT take the easy route, I can predict you might have some troubles, just judging from the other complications you mentioned :)
Again, not trying to push anything, just trying to help so you don't get the frown right away by generating the magic smoke from the getgo.

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #2 on: August 09, 2013, 07:04:14 PM »
Felix - Thanks. Great advice.

Programming avr(s). I have burned, successfully, a number of Atmel chips, setting fuses to loading bootloaders. I don't know what your bootloader contains since I haven't read enough yet and I'm not a coder. But, as all things go - I guess I'll learn. I do have USBasp(s) and Bubs for the grittier levels.  ;)

The Femtoduino is just a naked Arduino so, is either Duemilanove or UNO. Not unlike yours just smaller. Which ever bootloader I load it will be. The chip is a 328P.

Power: I was not sure here since I haven't read about the RFM69 yet. But, 5v to 3.3 I would likely use a voltage divider to cut down the voltage for the RFM69 or make a small power pcb with an ldo. Not sure yet. It has been a couple of years since I looked at my Femtoduinos  - they may have an onboard ldo for 3.3v to power something. I do not remember.

Your up sell -  8) but, I am foreseeing taking your stuff and enabling other people's stuff. I want to offer others an option to grab a couple parts and knock them together - IF the process is known. I just don't like the waste idea of seeing something with a handful of avrs when one or two would do. And the grief I suffer doing this will give me more of an understanding of what I am doing.


Thank you.
[Edit: 8/9/13 - Post moved into projects folder - Thanks to Felix.]
« Last Edit: August 10, 2013, 08:01:08 PM by bstott »

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #3 on: August 11, 2013, 03:15:10 AM »
Hey Brian,
Here are my thoughts:

... You will need to fuse it to 16mhz. Moteino fuses are : Ext:0xfd, Hi:0xdc, Lo:0xde

... RFM69. You will fry it if you connect anything above 3.6V to it, power and data included. That's unless your home made version is 3.3V.

Moteino can however be powered with anything from 3.3V to 12V on the "VIN" pins.

... I can predict you might have some troubles,...


:-) I think I'm on to something. Thanks for your clues. Timing - Voltages - operating ranges - fuse settings. I'm organizing pictures then questions coming soon.....  :-X

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #4 on: August 12, 2013, 03:41:38 PM »
Felix,

I caved early ---- I just got parts for three other concurrent projects today. So, I decided your suggestion to mate two Moteino's for my servo project is the wiser quicker method. Thanks for your products and suggestions. Good UP Sell! ;-)

Brian.

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #5 on: August 15, 2013, 11:28:51 PM »
Received 2nd Moteino today and programmed both to start getting familiar with radio communications. One is programmed as Gateway the other as Node. They are communicating. I've noticed a notebook lcd between the radios blocks to the radios communicating. On my desk if one radio is set down in the shadaw/behind my laptop lcd blocked from line of sight of the other radio - even a foot away - communication packets are highly blocked.

I have un-commented the line 'radio.setHighPower();' in both of the radio sketches. The Moteinos are powered from the USB and I'm viewing their communications through the Arduino Terminal Windows. I am not sure what is happening.

Wait! - I just remembered starting the Gateway and it posted something about Listening @ 915MHz. I ordered 433MHz...  :-\   Oh, Hum... I will look into it tomorrow.
« Last Edit: August 15, 2013, 11:34:03 PM by bstott »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5385
  • Country: us
    • LowPowerLab
Re: Remote Servo Control
« Reply #6 on: August 16, 2013, 07:54:55 AM »
Yeah make sure you got the settings matching your radio hardware. Frequency, and also get the latest github code for the RFM69 lib. Let me know how it goes...

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #7 on: September 09, 2013, 07:49:03 PM »
Well, Felix supports his customers!

My two radios are working well. I'd had an initial problem by changing the encryption key but, did not assure the new key used was 16 characters long. If you do not use a full 16 character key the Moteinos will, no-worky.  :-[

On with learning. I've been getting familiar with the Moteino and started two simple programs. I've just seen that Felix, about a week ago, posted two examples which send and receive three sources of data. Very good for this effort because, it allows my lack of programming skills to learn to edit/adapt Felix's examples: Struct_send and Struct_receive for this project.   :)

Maybe I'll name my two programs: Pot_send and Servo_receive.  ::)

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5385
  • Country: us
    • LowPowerLab
Re: Remote Servo Control
« Reply #8 on: September 10, 2013, 08:29:17 AM »
Yep, again, whatever I put on there is probably bare bones, but it illustrates a concept which hopefully is helpful to someone. I tried to cover the basics. My primary purpose is not programming or teaching all the tricks you can do in software, but to come up with more components that are useful for people that would like to build things using modular pieces of hardware.
Having said that, some of the examples are exactly what I use and may be less useful without modification.

Hardware is hard, not like software which you download and install and it works... but it's exciting, a lot more so I think :)

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #9 on: September 11, 2013, 02:21:33 PM »
Success to Problem...  :o

I've edited Felix's Struct send & receive examples from Github to use for Pot to Servo control. The Moteino with the attached Pot does transfer the Pot data and I can receive it on the other Moteino. I've then converted analog Pot data into degrees on the receiving Moteino and written it to the Servo motor. The receiving Moteino outputs correct Servo & Pot angle to the Serial Monitor. The data does not fluctuate more than a degree or two. This is stable. RSSI is good. See the attached screen capture *.jpg.

Problem - The problem begins when I attach a Servo motor to the assigned digital PWM (9, 10 or 11) pin on the receiving Moteino. The servo is powered by a separate power supply with common ground to the Moteino. When connected the Servo twitches over a range of 45-50 degrees. See video link below. The twitch coincides with radio activity indicated on the radio blinking light. delay() is used in the receive sketch to allow time for the Servo to move to the commanded position.

Video link:http://youtu.be/RiraZsGLSIE

Send and Receive Radio sketches are attached.

Any Suggestions for Solutions?


Additional Questions:  ???

? What programming commands can I use to isolate the PWM pins from the radio transmissions and change the Servo positon only as directed by the transmitted data?

See attached *.jpg
? Why is the indicated RSSI a negative value?

? Why does it sometimes go over a value of -113?


Thanks,

Brian.

--- Ad naseum -- Reminder: I am not a programmer....

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5385
  • Country: us
    • LowPowerLab
Re: Remote Servo Control
« Reply #10 on: September 11, 2013, 02:31:08 PM »
First - the pins 9-11 are off limits. Actually pin 9 could be used because it's only connected to the SMD LED onboard.
Pins 10 and 11 are SPI pins used by the radio and the flash.

So I would suggest using other PWM pins, 3,5,6,9.
The dBm is a negative value but it's a logarithmic scale, so it's really a value in reference to a milliwatt of power (so it's not really negative in the true sense). Lower value means weaker received signal.

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #11 on: September 11, 2013, 04:54:24 PM »
----- Mission Accomplished! -----


Fellix, Common PWM are off limits? OK, I do now recall reading about something related. Oh well.

----- Radio Controlled Servo Works --------
The previous extreme servo behavior was caused by interference with pins 9, 10 & 11. The code has been changed to use the digital 5 pin. I've attached '_1Servo_Struct_send.ino' and '_1Servo_Struct_receive.ino' sketches. They work - sort of. There is still a twitch while moving the servo but, it is much less than before. Now, the motion to final position is twitchy but, the servo does stay stable in the final position. I do not know how to make the movement smooth. The servo will move to a designated rotation without wild swings.

The attached sketches are easily adapted for more than one servo by copy-n-pasting the lines related to the servo and its variables. It should not be to hard to see the locations. I've inserted comments too.

I do not know how to stop the little twitchy relocating movements of the servo motor when changing position. Even with moving to PWM pins not used by the radio and led there continues to be a pulse that is related to the radio. I notice that they pulse twitch in sync with the radio LED.
« Last Edit: September 11, 2013, 04:58:45 PM by bstott »

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #12 on: September 11, 2013, 09:06:43 PM »
Programming Question

How do I program a time sample from the Pot sending board and transmit it every X period?

The idea: The Pot is an analog signal and can be garbled in transmission. Also, since the Pot is variable while turning it will not transmit well. I think. If instead the applications takes small time based snap shots of the Pot position and sends that every ? 2ms, for example, then the overall performance at the Servo end may be smoother and more responsive? Treat it as a time based stepper motor.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5385
  • Country: us
    • LowPowerLab
Re: Remote Servo Control
« Reply #13 on: September 11, 2013, 10:27:44 PM »
Transmissions will take about 5-6ms at the very least (no payload). ACKs are like regular transmissions with no payload.
So transmitting every 2ms is not feasible, except perhaps if the lib is tuned for a much higher baud value (right now 55.5kbps out of 300kbps). But that would affect range and it's not as easy as swapping register values. So I would not try that. These transmitters are not meant for high throughput.
There is a continuous mode these can run in, and that's more for streaming bytes. That mode could be better for your purpose. But my library is built around the other fundamental mode of this transceiver - packet mode where the idea is to take advantage of the nice features that come with it - AES encryption, packet engine, etc.

Have you considered using a digital pot?

You have a hard problem on your lap. You have to move a remote servo based on the turn of a pot somewhere else. I think the key is to be smart about sampling. You want to have as smooth motion as possible. You have to sample often, BUT transmit seldom (say at most a few dozen ms apart). And only transmit when it's critical, for instance you sample and decide it's time to move the servo to a new location, transmit and wait then sample again and see where the pot is now, and decide again. If the pot turns the other way while the servo is still moving to a given point, then quickly transmit a packet that will reverse it towards the latest position it should be in. I guess you might already be doing all this, but given the constraints (10bit resolution for the pot, X positions for the servo and a limited time slotted transmission medium) you have to really come up with ingenious ways of not creating too much RF traffic.

Another essential thing in such "streaming" scenarios is to avoid using ACKS which will effectively double the RF traffic. In a continuous streaming situation, where there's a lot of packets with new positions transmitted all the time, the loss of a packet is no big deal because a soon to come packet will have the latest position anyway.

Also the frequency channel can be susceptible to interference, so shifting the center frequency up or down may help if you are experiencing a lot of RF interference (using setFrequency(32 bit value) with values from the datasheet).

I believe you found the other examples where I send data every X ms. I hope I answered your questions.

bstott

  • Newbie
  • *
  • Posts: 37
Re: Remote Servo Control
« Reply #14 on: September 12, 2013, 11:47:00 AM »
Thanks Again Felix!

Attached is new - Faster - code.

Transmissions will take about 5-6ms at the very least (no payload). ACKs are like regular transmissions with no payload. So transmitting every 2ms is not feasible, ...

Right! I did some more reading and servos accept commands about 40 per second which is every 25ms. I was speaking from ignorance when I put out the idea to transmit every 2ms.

Quote
Have you considered using a digital pot?

Yes, and a digital servo. But not anymore. A very accurate fast response is not required. It just does need to be responsive.  :)  Oh, and I chewed quite a wad here with getting the Moteinos and programming without also having to learn about digital pots. Remember you convinced me not to use another Arduino clone to interface but, to make it simpler?   ;)

Quote
You have a hard problem on your lap. You have to move a remote servo based on the turn of a pot somewhere else. I think the key is to be smart about sampling. You want to have as smooth motion as possible. You have to sample often, BUT transmit seldom (say at most a few dozen ms apart).

Servos only require commands about every 25ms. This makes your guesstimate of every few dozen of ms - 'Spot On.' for sending data.

'Sampling' is the term I needed to use in my earlier questions. Since a servo only needs commands every 20-25ms I should sample and transmit every 20-25ms. This would dramatically lower RF transmissions.

Quote
If the pot turns the other way while the servo is still moving to a given point, then quickly transmit a packet that will reverse it towards the latest position it should be in.

I LIKE IT!
Sampling the direction, every 10-12ms should work. IF direction changes THEN capture and transmit the new direction command and re-set the 20-25ms transmit cycle ELSE continue 25ms transmission cycle.

Quote
Another essential thing in such "streaming" scenarios is to avoid using ACKS which will effectively double the RF traffic. In a continuous streaming situation, where there's a lot of packets with new positions transmitted all the time, the loss of a packet is no big deal because a soon to come packet will have the latest position anyway.

Yep, got ya. I've removed ACKS from the example code I was using as a base for this project.

Quote
Also the frequency channel can be susceptible to interference, so shifting the center frequency up or down may help if you are experiencing a lot of RF interference (using setFrequency(32 bit value) with values from the datasheet).

Ah, I wondered about that. OK, if happens I will read datasheet and use.

Need to note too that there may be benefits from different antenna and filters. But, then that would become a sophisticated system.

Quote
I believe you found the other examples where I send data every X ms. I hope I answered your questions.

 8) Yes, thank you. A lot of mysterious coding.  ??? But, I am making sense of some.