Presentation is loading. Please wait.

Presentation is loading. Please wait.

Internet of Things with Intel Edison Servo motors with Pololu Controller Pierre Collet

Similar presentations


Presentation on theme: "Internet of Things with Intel Edison Servo motors with Pololu Controller Pierre Collet"— Presentation transcript:

1 Internet of Things with Intel Edison Servo motors with Pololu Controller Pierre Collet Intel Software

2 Objectives Objective Servo motors are controlled with a signal called PWM. To interact correctly with a PWM device, you need to generate a strict signal. Obvious for a basic microcontroller, not so much for a general purpose processor with a regular linux. Two solutions : o Use a Real Time OS. On Edison the second processor is running a Real Time OS so we can do it on Edison itself. o Use an external PWM card, connected with USB. A good example : Pololu Maestro card. Today, we’ll use the Pololu Maestro with 6 PWMs.

3 Setup

4 LibUSB We are connected to the Pololu card with USB, using USB messages. We need libusb-1.0-dev and we’ll use a package for Yocto, the Linux by default on Edison. To install : echo "src/gz all > /etc/opkg/base-feeds.confhttp://repo.opkg.net/edison/repo/all echo "src/gz edison >> /etc/opkg/base-feeds.confhttp://repo.opkg.net/edison/repo/edison echo "src/gz core2-32 >> /etc/opkg/base-feeds.confhttp://repo.opkg.net/edison/repo/core2-32 echo "src mraa-upm > /etc/opkg/mraa-upm.confhttp://iotdk.intel.com/repos/1.1/intelgalactic opkg update opkg install libusb-1.0-dev

5 Using the Master USB port Master/Client When you plug Edison to your PC with a USB cable, you see Edison as a serial-over-USB device and a mass storage device. That’s the client mode of USB. Switch But Edison is also a PC, acting as master. To use the full size USB port on the board as a master, operate the switch. Remember to switch it back after this lab.

6 Hardware Connecting hardware Plug and boot your board. Connect the Pololu card to Edison on USB host connector using a standard mini USB Cable. Connect a servo motor on Pololu channel #1. In the next slide we’ll see how to power the Pololu from a USB port.

7 Hardware – Power from USB Power ? The Pololu has 2 power requirements : o Very minimal for the microcontroller. This power comes from the USB cable. o High for the servos. We need to get this power from an external source and connect it to the 2 power pins of the Pololu. Two methods Usually, we would get a 6V battery with the right connector. If you have one, use it. If you don’t, it’s possible to : o cut a USB cable (it’s not reversible, obviously), separate wires o get the 2 power wires (red and black) o connect manually the 2 wires to the Pololu power pins

8 Hardware #5 Vin #0 Regular USB cable DATA Modified USB cable POWER ONLY

9 Script

10 Shell script to control a servo Binaries We provide you 3 binaries to control 3 parameters : o The targeted position of the servo motor o The speed of the servo motor (0 is max speed) o The acceleration of the servo motor (0 is max acceleration ) For each binary, the first argument is the channel number and the second parameter is the value. How to run this files #./set_accel00 #./set_speed00 #./set_target02000 The order is automatically sent to the Pololu card via USB. These binaries are C++ program using libusb-1.0.

11 Shell script to control a servo A simple bash script to control a servo motor #! /bin/bash while :# infinite loop do./set_target # channel 0 targeted position is set to 1000 sleep 1s # we wait a second./set_target sleep 1s Done It’s just moving the servo from 1000 to 2000 and back, with 1s pauses.

12 C Code

13 Set_target source code A C++ main function using libusb #include using namespace std; int main(int argc, char *argv[]){ if(argc < 3) cout << "Usage: binary servo_number target_value" << endl; int servo = atoi(argv[1]); int value = atoi(argv[2]);

14 Set_target source code Creating libusb structures libusb_device **devs; libusb_context *ctx = NULL; libusb_device_descriptor descr; libusb_device *pololu; string idPololu ("137"); int r; int found = 0; ssize_t cnt, i; Initializing libusb r = libusb_init(&ctx); libusb_set_debug(ctx, 3); Seeking devices cnt = libusb_get_device_list(ctx, &devs);

15 Set_target source code For each device found for(i = 0; i < cnt; i++) { r = libusb_get_device_descriptor(devs[i],&descr); //pololu id is 137, so let’s find it if(descr.idProduct == 137) { pololu = (devs[i]); found = 1; break; Stop looking for devices and don’t unreference the pololu } libusb_unref_device(devs[i]); }

16 Set_target source code Sending target command if(found){ libusb_device_handle **handle; r = libusb_open(pololu,handle); r = libusb_detach_kernel_driver(*handle,0); if(r < 0 && r != LIBUSB_ERROR_NOT_FOUND) { cout<<"Error: detach kernel driver failed"<

17 Set_target source code Closing USB connection r = libusb_release_interface(*handle,0); libusb_close(*handle); } libusb_free_device_list(devs, 1); libusb_exit(ctx); return 0; }

18 Conclusion Edison being a PC, you can expect to find a lot of great USB solutions to all your problems. Same thing for webcams. For PWM, you could do without the Pololu Maestro, both are good solutions. Idea : Integrate Edison and Android ? An IoT project which need a remote ? Use your Android smartphone to control Edison ! We’ve seen how to create a web form with NodeJS, you can also create an Android app with a native look and feel. Conclusion

19

20 License Creative Commons – By 3.0 You are free: to Share — to copy, distribute and transmit the work to Remix — to adapt the work to make commercial use of the work Under the following conditions: Attribution — You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). With the understanding that: Waiver — Any of the above conditions can be waived if you get permission from the copyright holder. Public Domain — Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license. Other Rights — In no way are any of the following rights affected by the license: – Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; – The author's moral rights; – Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights. Notice — For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.


Download ppt "Internet of Things with Intel Edison Servo motors with Pololu Controller Pierre Collet"

Similar presentations


Ads by Google