Category Archives: 机器人小组

Connector Basics

Introduction

Connectors are used to join subsections of circuits together. Usually, a connector is used where it may be desirable to disconnect the subsections at some future time: power inputs, peripheral connections, or boards which may need to be replaced.

Covered in This Tutorial

In this tutorial we will go over:

  • Basic connector terminology
  • Categorize connectors into distinguishable categories
  • Talk about the differences between connectors within those categories.
  • Show how to identify polarized connectors
  • Talk about which connectors are best suited for certain applications

Suggested Reading

You may find these concepts useful before starting on this tutorial:

Connector Terminology

Before we get started discussing some commonly used connectors, let’s explore the terminology used to describe connectors.

Gender - The gender of a connector refers to whether it plugs in or is plugged into and is typically male or female, respectively (kids, ask your parents for a more thorough explanation). Unfortunately, there are cases where a connector may be referred to as “male” when it would appear to be female; in the examples section, we’ll point a few of those out as we discuss individual component types and explain why that’s the case.

Male and female 2.0mm PH series JST connectors

Male (left) and female 2.0mm PH series JST connectors. In this case, gender is determined by the individual conductor.

Polarity - Most connectors can only be connected in one orientation. This trait is called polarity, and connectors which have some means to prevent them being connected wrong are said to be polarized, or sometimes keyed.

North America wall plug

A polarized North American wall plug. By having two different widths for the plug blades, the plug will only go into the outlet one way.

Contact - Contacts are the business portion of the connector. They are the metal parts which touch each other, forming an electrical connection. This is also where problems occur: the contacts can become soiled or oxidized, or the springiness required to hold the contacts together may fade with time.

ADH8066 mating connector

The contacts on this connector are clearly visible.

Pitch - Many connectors consist of an array of contacts in a repeated pattern. The pitch of the connector is the distance from the center of one contact to the center of the next. This is important, because there are many families of contacts which look very similar but may differ in pitch, making it difficult to know that you are purchasing the right mating connector.

.1" pin header connector examples

The pitch of the pins on the headers on a standard Arduino is .1".

Mating cycles - Connectors have a finite life, and connecting and disconnecting them is what wears them out. Datasheets usually present that information in terms of mating cycles, and it varies widely from one technology to another. A USB connector may have a lifetime in the thousands or tens of thousands of cycles, while a board-to-board connector designed for use inside of consumer electronics may be limited to tens of cycles. It’s important that you select a connector with a suitable life for the application.

Connector for GS406 GPS module

Mating connector for the GS406 GPS module. The connector’s datasheet indicates a maximum of 50 insertion cycles for this part.

Mount - This one has the potential for being confusing. The term “mount” can refer to several things: how the connector is mounted in use (panel mount, free-hanging, board mount), what the angle of the connector is relative to its attachment (straight or right-angle), or how it is mechanically attached (solder tab, surface mount, through hole). We’ll discuss this more in the examples section for each individual connector.

Comparison of different mounting methods for barrel-type connectors

A comparison of three different methods of mounting the same barrel connector: (left to right) board mount, inline cable mount, and panel mount.

Strain relief - When a connector mounts to a board or cable, the electrical connections tend to be somewhat fragile. It is typical to provide some kind of strain relief to transfer any forces acting on that connector to a more mechanically sound object than the fragile electrical connections. Again, there will be some good examples of this later on.

1/8" Headphone jack showing strain relief

This 1/8" headphone jack comes with a strain relief “boot” slid over the cable to prevent forces on the cable from being transmitted directly to the electrical joints.

USB Connectors

USB connectors come in two flavors: host and peripheral. In the USB standard, there is a difference between the two, and the connectors on cables and devices reflect this. However, all USB connectors will have some things in common:

  • Polarization - A USB connector can only nominally be inserted one way. It may be possible to force a connector in wrong, but that will result in damage to the device.
  • Four contacts - All USB connectors have at least four contacts (although some may have five, and USB 3.0connectors have even more). These are for power, ground, and two data lines (D+ and D-). USB connectors are designed to transmit 5V, up to 500mA.
  • Shielding - USB connectors are shielded, such that a metal shell which is not part of the electrical circuit is provided. This is important to keep the signal intact in environments with a lot of electrical “noise”.
  • Robust power connection - It’s important for the power pins to make connection before the data lines, to avoid trying to power the device over the data lines. All USB connectors are designed with this in mind.
  • Molded strain relief - All USB cables have plastic overmolding at the connector to prevent strain on the cable that could potentially damage the electrical connections.

Labeled image of USB extension cable

USB extension cable, with some of the common features of USB connectors labeled.

USB-A Connectors

USB-A female is the standard “host” connector type. This is found on computers, hubs, or any device intended to have peripherals plugged into it. It is also possible to find extension cables with a female A connector and a male A connector on the other end.

USB-A ports on a laptop computer.

Female USB-A ports on the side of a laptop. The blue connector is USB 3.0 compliant.

USB-A male is the standard “peripheral” connector type. Most USB cables will have one end terminating in a USB-A male connector, and many devices (such as keyboards and mice) will have a built-in cable terminated with a USB-A male connector. It’s also possible to find USB-A male connectors that are board mountable, for devices like USB memory sticks.

USB-A male connector examples

Two types of Male USB-A connectors, on a SparkFun Cerberus cable and an AVR Stick development board.

USB-B Connectors

USB-B female is a standard for peripheral devices. It’s bulky, but robust, so in applications where size is not an issue, it’s the preferred means for providing a removable connector for USB connectivity. It is usually a through-hole board mount connector, for maximum reliability, but there are panel-mount options for it as well.

USB-B connector on an Arduino Uno

Arduino boards, including this Uno, have long used the female USB-B connector, due to its low cost and durability.

USB-B male is almost exclusively found at the end of a cable. USB-B cables are ubiquitous and inexpensive, which also contributes to the popularity of the USB-B connection.

Male USB-B connector

USB-B male connector on the end of a SparkFun Cerberus cable.

USB-Mini Connectors

The USB-Mini connection was the first standard attempt to reduce the size of the USB connector for smaller devices. USB-Mini female is typically found on smaller peripherals (MP3 players, older cellphones, small external hard drives), and is usually a surface mount connector, trading robustness for size. USB-Mini is slowly being phased out in favor of the USB-Micro connector.

USB-Mini female connector

USB-Mini female connector on a Protosnap Pro Mini.

USB-Mini male is another cable-only connector. As with USB-B, it’s extremely common, and cables can be found cheaply almost anywhere.

USB-Mini male connector

USB-Mini male connector on the end of a SparkFun Cerberus cable.

USB-Micro Connectors

USB-Micro is a fairly recent addition to the USB connector family. As with USB-Mini, the primary concern is size reduction, but USB-Micro adds a fifth pin for low-speed signalling, allowing it to be used in USB-OTG (On-the-go) applications where a device may want to operate as either a host or a peripheral depending on circumstances.

USB-Micro female is found on many newer peripherals, such as digital cameras and MP3 players. The adoption of USB-micro as a standard charge port for all new cellular phones and tablet computers means that chargers and data cables are becoming increasingly common, and USB-Micro is likely to supplant USB-Mini in the coming years as the small-factor USB connector of choice.

USB-Micro female connector

USB-Micro female connector on a LilyPad Arduino USB board.

USB-Micro male is also a cable-only connector. There are generally two types of cables with USB-Micro male ends: one for connecting a device with a USB-Micro port as a peripheral to a USB host device and one for adapting the USB-Micro female port to a USB-A female port, to be used in USB-OTG capable devices.

USB-Micro male connector

USB-Micro male connector on the SparkFun Cerberus cable.

USB-A female to USB-Micro adapter

Adapter pigtail for using USB-OTG capable devices having only a USB-Micro port with standard USB peripherals. Note that not all devices supporting USB-OTG will work with this pigtail.

Audio Connectors

Another familiar connector group are those used for audio-visual applications–RCA and phono. While these can’t truly be considered to be of the same family, as the various USB connectors are, we’ll consider both of them to be in the same vein.

“Phone” Type Connectors

You’ll probably immediately recognize the 1/8" version of this connector as a the plug on the end of a pair of headphones. These connectors actually come in three common sizes: ¼" (6.35mm), 1/8" (3.5mm), and 2.5mm. ¼" size connectors find a lot of use in the professional audio and music community- most electric guitars and amplifiers have ¼" tip-sleeve (TS) jacks on them. 1/8" tip-ring-sleeve (TRS) is very common as the connector for headphones or audio output signals on MP3 players or computers. Some cell phones will provide a 2.5mm tip-ring-ring-sleeve (TRRS) jack for connecting to headphones that also include a microphone for hands-free communications.

The common availability of these connectors and cables makes them a good candidate for general purpose connectivity applications–for instance, long before USB, Texas Instruments graphing calculators used a 2.5mm TRS connector for a serial programming connector. It should be remembered that tip-sleeve connector types are not designed for carrying power; during insertion, the tip and the sleeve can be momentarily shorted together, which may damage the power supply. The lack of shielding makes them poor candidates for high-speed data, but low speed serial data can be passed through these connectors.

1/8" TRS phone plug

Headphone-type TRS phone plug, 1/8". Typically, tip and ring will carry the stereo audio signals while sleeve will be connected to ground.

1/8" TS phone plug

1/8" phone plug. Note the lack of a ring contact on this connector.

1/8" board mount headphone jack

1/8" board mount headphone jack with pins corresponding pin connections labeled. When no jack is inserted, an internal switch connects the tip and ring pins to the adjacent unmarked pins, allowing insertion detection.

RCA Connectors

Familiar as the home-stereo connector of choice for many decades, the RCA connector was introduced in the 1940s by RCA for home phonographs. It is slowly being supplanted by connections like HDMI in the audio-visual realm, but the ubiquity of the connectors and cables makes it a good candidate for home-built systems. It will be a long time before it is obsolete.

Female RCA connectors are usually found on devices, although it is possible to find extension or conversion cables with female jacks on them. Most RCA connectors are connected to one of four types of signals: component video (PAL or NTSC, depending on where the equipment was sold), composite video, stereo audio, or S/PDIF audio.

Female RCA plug, for video signals.

Female RCA connector, for video signals. Typically, NTSC or PAL video signal connectors will be yellow.

Male RCA connectors are usually found on cables.

Male RCA plugs

Male RCA plugs. Red and white are usually for audio applications, with red denoting the “right” audio channel.

Power Connectors

While many connectors carry power in addition to data, some connectors are used specifically to provide power connections to devices. These vary widely by application and size, but we will only focus on some of the most common ones here.

Barrel Connectors

Barrel connectors are typically found on low-cost consumer electronics which can be plugged into wall power via bulky AC wall adaptors. Wall adaptors are widely available, in a variety of power ratings and voltages, making barrel connectors a common means for connecting power to small projects.

The female barrel connector, or “jack”, can be purchased in several varieties: PCB mounted (surface mount or through hole), cable mount, or panel mount. Some of these connectors will have an additional contact that allows the application to detect whether a power supply is plugged into the barrel jack or not, thus allowing the device to bypass batteries and save battery life when running on external power.

Female barrel connector

Female barrel connector. When no plug is inserted, the “insertion detection” pin will be shorted to the “sleeve” pin.

The male barrel connector, or “plug”, is usually only found in a wire termination variety, although there are multiple methods of attaching the plug to the end of the wire. It’s also possible to get plugs that come pre-attached to a cable.

Male barrel plug

Unattached male barrel plug, for attachment to any power supply. Note that the sleeve connection is designed to be crimped onto the wire for extra strain relief.

Barrel connectors provide only two connections, frequently referred to as “pin” or “tip” and “sleeve”. When ordering, there are three differentiating characteristics of a barrel connection- inner diameter (the diameter of the pin inside the jack), outer diameter (the diameter of the sleeve on the outside of the plug), and polarity (whether the sleeve voltage is higher or lower than the tip voltage).

Sleeve diameter is most commonly either 5.5mm or 3.5mm.

Pin diameter is contingent upon sleeve diameter; a 5.5mm sleeve will have either a 2.5mm or 2.1mm pin. Unfortunately, this means that a plug designed for a 2.5mm pin will fit in a 2.1mm jack, but that the connection will be, at best, intermittent. 3.5mm sleeve plugs usually mate to a jack with a 1.3mm pin.

Polarity is the final aspect to consider; most often, the sleeve will be considered 0V and the tip will be a positive voltage relative to the sleeve. Many devices will have a small diagram indicating the polarity expected by the device; care should be taken to adhere to this, as an improper power supply may damage the device.

Plugs of both sleeve sizes are usually 9.5mm long, but longer and shorter ones do exist. All SparkFun products use a positive polarity 5.5mm sleeve and a 2.1mm pin; we recommend sticking to that standard where possible, as it seems to be the most common flavor found in the wild.

Barrel connector polarity label

Common polarity diagrams for AC adaptors with barrel plugs. Positive polarity (tip positive, sleeve 0V) is most common. Diagram courtesy Wikipedia user Three-quarter-ten.

“Molex” Connectors

Most computer hard drives, optical drives, and other internal peripherals get power through what is typically called a “Molex” connector. To be more accurate, it’s a Molex series 8981 connector–Molex is actually the name of the company which initially designed this connector back in the 1950s–but common usage has denuded that fact somewhat.

Molex connectors are designed to carry a lot of current: up to 11A per pin. For projects where a lot of power may be needed–a CNC machine, for instance, or a 3D printer- a very common method for powering the project is to use a desktop PC power supply and connecting the various system circuits through Molex connectors.

The Molex connector is one where the male/female terminology is a bit odd. The female connector is usually found on the end of a cable, and it slips inside of a plastic shell which surrounds the male pins on the male connector. Usually, the connectors are press-fit only, and very, very tight–they are intended to be connected and disconnected only a few times and, as such, are a bad choice for systems where connections will frequently be changed.

Male Molex connector

Male Molex connector. The gender of the pins inside the connector is what signifies the gender of the connector as a whole.

Female Molex connector

Female Molex connector on a project power supply.

IEC Connector

As with the Molex connector, this is a case where a generalized component name has come to be synonymous with a single, particular item. IEC connector usually refers to the power supply inlet which is commonly seen on desktop PC power supplies. Strictly speaking, that’s an IEC 60320-1 C13 (female) and C14 (male) connector.

IEC 60320-1 C14 male connector

C14 male IEC power inlet, on a DC project power supply. Note that, as with the Molex connector, the gender of the connector is defined by the pins within the hood.

C13 female IEC power connector

C13 female IEC power connector, on a fairly standard AC power supply cable. Cables with this end can be found all around the world, usually with the dominant local AC connector at the other end.

IEC connectors are used almost exclusively for AC power input. The nice thing about using one on a project is that IEC-to-wall cables are extremely common and available with localized wall plugs for most international locations!

JST Connector

At SparkFun, we frequently refer to “2.0mm JST Connectors”. This is yet another generalization of a specific product- JST is a Japanese company which makes high-quality connectors, and our 2.0mm JST connector of choice is the PH series two-position polarized connector.

All of SparkFun’s single-cell lithium-polymer ion batteries come standard with this type of JST connector, and many of our boards include this connector (or a footprint for it) as a power supply input. It has the advantage of being compact, durable, and difficult to connect backwards. Another feature, which can be an advantage or a disadvantage, depending on how you look at it, is that the JST connector is wicked hard to disconnect (although a carefully applied diagonal cuttercan be helpful!) once it’s mated. While this makes it unlikely to fail during use, it also means that disconnecting the battery for charging can damage the battery connector.

2-Pin JST male connector on a LilyPad Arduino USB board

2-Pin JST male connector on a LilyPad Arduino USB board. Again, as with the Molex, the pins inside the hood determine the gender of the connector.

Male and female 2-pin JST connectors

Male and female 2-pin JST connectors.

There are PH series connectors with more than two positions; SparkFun even sells them. However, our most frequent application is for the 2-position battery connection.

Pin Header Connectors

Pin header connectors comprise several different means of connection. Generally, one side is a series of pins which are soldered to a PCB, and they can either be at a right-angle to the PCB surface (usually called “straight”) or parallel to the board’s surface (confusingly referred to as “right-angle” pins). Such connectors come in a variety of pitches, and may have any number of individual rows of pins.

Right angle female header pin connector

Right-angle female header pin connection on an FTDI basic board.

The most commonly seen pin headers are .1" single or double row connectors. These come in male and femaleversions, and are the connectors used to connect Arduino boards and shields together. Other pitches are not uncommon; for instance, the XBee wireless module uses a 2.0mm pitch version of the same connector.

.1" pin header connector examples

.1" pin header connectors, male and female, on an Arduino Uno board.

A common variation on this part is a “machine pin” version. While the normal version is formed out of stamped and folded sheet metal, machine pin connectors are formed by tooling the metal into the desired shape. The result is a more robust connector, with a better joint and longer life, making it somewhat more expensive.

Female machine pin headers

Female machine pin headers. Note that these are designed to be snapped apart into smaller sections, while standard .1" female header pin connectors are not. It’s also important to note that not all non-machine pin header connectors will mate with the machine pin variety.

Cables made to connect to these pin headers are usually one of two types: individual wires with crimp connectors on them or ribbon cables with insulation displacement connectors. These can simply be clamped onto the end of a ribbon cable, which creates a connection to each one of the conductors in the ribbon cable. Generally, cables are only available as female gender and expect a male pin to mate with.

Crimp connected header cable

Six-position crimp-type cable. Each wire is individually stripped, a connector crimped to it, and then the connectors are inserted into the plastic frame.

2x5 insulation displacement connectors on a ribbon cable

2x5 insulation displacement connectors (IDC) on a ribbon cable. This type of cable can be quickly assembled because it does not require stripping of individual connectors. It also has polarizing tabs on each end, to prevent incorrect insertion in the mating board-side connector.

Temporary connectors

Screw Terminals

In some cases, it may be desirable to be able to connect bare, unterminated wire to a circuit. Screw terminals provide a good solution for this. They are also good for situations in which a connection should be capable of supporting multiple different connecting devices.

The downside of screw terminals is that they can come undone fairly easily, leaving a bare wire waving around in your circuit. A small dab of hot glue can address this without being too difficult to remove later.

Screw terminals are typically designed for a narrow range of wire gauges, and wires that are too small can be as big a problem as wires that are too big. SparkFun carries two types of screw terminal–a .1" pitch version and a 3.5mm version. Most screw terminals are highly modular, and they can easily be extended at the same pitch by simply connecting two or more smaller sections together.

3.5mm screw terminals


-> 3.5mm pitch screw terminals, showing the insertion point of the wire to be connected, the retention screw which holds the wire in place, and the modular connectors on the sides of the individual units allowing multiple pieces to be ganged together. <-

Banana Connector

Most pieces of power test equipment (multimeters, power supplies) have a very simple connector called a “banana jack” on it. These mate to “banana plugs”, crimped, sprung metal plugs, meant to make a single power connection. They are frequently available in a stackable configuration and can be easily connected to any type of wire. They are capable of carrying several amps of current and are inexpensive.

Banana plug

Stackable banana plug. Note that there are two different ways to plug in an additional banana plug.

Variable power supply with banana plugs

Extech variable bench supply with banana jacks on the front.

Alligator Clip

Named for obvious reasons, alligator clips are good for test connections to posts or bare wires. They tend to be bulky, easily cause shorts to nearby bare metal, and have a reasonably poor grip that can be easily compromised. They are primarily used for low-cost connections during debugging.

Alligator clips

“third hand” tool, which uses alligator clips to hold work pieces, holding a wire terminated with an alligator clip for electrical test. Note the plastic boot surrounding the alligator clip, to make it less likely to short to other connections.

IC Clip (or IC Hook)

For more delicate probing operations, there are a variety of IC clips on the market. These are sized to allow a user to clip them onto the pins of an IC without contacting adjacent pins; some of them are delicate enough to be clipped onto even fine-pitched SMD component legs. These smaller clips can be found on logic analyzers as well as test leads, which are great for prototyping or troubleshooting circuits.

Large IC clip

large IC clip on the end of a wire. This clip is still small enough to be connected to a single leg on a through-hole chip without causing a problem for adjacent pins.

Other Connectors

RJ-type Modular Connectors

Registered jack connectors are standard for telecommunications equipment into a local exchange. The names one normally hears associated with them (RJ45, RJ12, etc) are not necessarily correct, as the RJ designator is a based on a combination of the number of positions, the number of conductors actually present, and the wiring pattern. For example, while the ends of a standard ethernet cable are usually referred to as “RJ45”, RJ45 actually implies not only an 8 position, 8 conductor modular jack, it also implies that it is wired for ethernet.

These modular connectors can be very useful, since they combine ready availability, multiple conductors, moderate flexibility, low cost, and moderate current carrying capacity. While not originally intended to deliver a great deal of power, these cables can be used to deliver data and a couple of hundred milliamps from one device to another. Care should be taken to ensure that jacks provided for applications like this are not connected to conventional ethernet ports, as damage will result.

8p8c "RJ45" style modular jack

A standard 8p8c (8-position, 8-conductor) “RJ45” modular jack. Be aware that if you intend to use this type of jack to pass DC signals and power, you must avoid using connectors with built-in signal transformers.

D-sub Type Connectors

Named for the shape of their shell, D-subminiature connectors are a classic standard in the computing world. There are four very common varieties of this connector: DA-15, DB-25, DE-15, and DE-9. The pin number indicates the number of connections provided, and the letter combination indicates the size of the shell. Thus, DE-15 and DE-9 have the same shell size, but a different number of connections.

Female board-mount DE9 connector

Female DE-9 board-mount connector. Gender is defined by the pins or sockets associated with each signal, not the connector as a whole, making this connector female despite the fact that it effectively inserts into the shell of the mating connector.

DB-25 and DE-9 are the most useful to the hardware hacker; many desktop computers still include at least one DE-9 serial port, and often one DB-25 parallel port. Cables terminated with DE-9 and DB-25 connectors are widely available, too. As with the modular connector above, these can be used to provide power and point-to-point communications between two devices. Again, since the common usage of these cables does not include power transmission, it is very important that any repurposing of the cables be done cautiously, as a non-standard device plugged into a standard port can easily cause damage.

Resources and Going Further

You should now have a good idea which connectors are suited best for certain applications and which connectors will be useful to you in your next project. Please check out these other links to lean more about connectors.

  • Giant database of connectors and pinouts - Everything you never wanted to know about pretty much any connector, ever. A good site for basic info about connectors, but often quite shy on interface details.
  • Wikipedia article on registered jack connectors - More on the confusing world of the registered jack (RJ) connector, which is often misunderstood and misused.
  • Wikipedia article on D-subminiature connectors - As with the registered jack connector, misinformation abounds on the D-subminiature standard. Wikipedia has a great article about it.
  • Mouser electronics catalog - Browsing an electronics supplier catalog is often a great place to start looking for the name of an unidentified connector; Mouser’s enhanced online catalog is just as good as the print version, with fewer papercuts!

If you’d like top explore more SparkFun tutorials, check out these other offerings:

 


cc

 Creative Commonstutorials are CC BY-SA 4.0

Original From:

https://learn.sparkfun.com/tutorials/connector-basics

步进电机基础知识与Arduino控制

步进电机是将脉冲信号转换成机械运动的一种特殊电机。步进电机在使用时不需要额外的反馈,这是因为除非失步,否则步进电机每次转动时的角度已知的,由于它的角度位置已知就能精确控制电机运动的位置。一般我们会用Arduino驱动的小型步进电机有以下两种。

steper01steper02

步进电机内部实际上产生了一个可以旋转的磁场,如图所示,当旋转磁场依次切换时,转子(rotor)就会随之转动相应的角度。当磁场旋转过快或者转子上所带负载的转动惯量太大时,转子无法跟上步伐,就会造成失步。

 steper03steper04

从步进电机的矩频特性图上可知,步进电机以越快的速度运行,所能输出的转矩越小,否则将会造成失步。每种不同规格的步进电机都有类似的矩频特性曲线,详细图表需要查阅其规格书。

steper05

图 矩频特性

步进电机的磁极数量规格和接线规格很多,为简化问题,我们这里就先只以四相步进电机为例进行讨论。所谓四相,就是说电机内部有4对磁极,此外还有一个公共端(COM)接电源, ABCD是四线的接头。而四相电机的可以向外引出六条接线(两条COM共同接入Vcc),即GNDABCD,也可以引出五条线,如图所示,所以有成为六线四相制和五线四相制。

steper06

                                    六线四相制                                              五线四相制

下表中1表示高电平、0表示低电平,我们以下述最简单的一相励磁方式来驱动步进电机

steper07

这种方式,电机在每个瞬间只有一个线圈导通,消耗电力小但在切换瞬间没有任何的电磁作用转子上,容易造成振动,也容易因为惯性而失步。

二相励磁方式

这种方式输出的转矩较大且振动较少,切换过程中至少有一个线圈通电作用于转子,使得输出的转矩较大,振动较小,也比一相励磁较为平稳,不易失步。

steper08

步进角是步进电机每前进一个步序所转过的角度。在不超载也不失步的情况下,给电机加上一个脉冲信号,它就转过一个步距角。这一简单的线性关系,使得步进电机速度和位置的控制变得十分简单。

综合上述两种驱动信号,下面提出一相励磁和二相励磁交替进行的方式,没传送一个励磁信号,步进电机前进半个步距角。其特点是分辨率高,运转更加平滑。

-二相励磁方式

steper09

下面是这三种驱动方式的时序波形图

steper10

驱动问题

不要天真的以为可以直接将Arduino的端口和ABCD分别相连,因为Arduino的数字I/O口最大只能通过约40mA的电流。因此,我们想到了使用晶体管进行放大。常用的方法有三种:

steper11

  1. 直接利用晶体管来驱动,这需要你对电机和晶体管的详细参数有一定了解,才能选择恰当的参数去匹配他们。此外,还必须使用二极管来处理当电机内部线圈产生感应电动势逆向流入晶体管而对晶体管造成损害。

  1. 使用诸如ULN2003ULN2803这样的激励器,它实际是内部集成好了放大功能的集成电路芯片,此外也无需额外添加二极管,因为它已经内置了。

  2. 使用光耦,在驱动芯片或者晶体管的前端再加入光耦合器,以加强隔离步进电机的反电动势,以免损害Arduino

steper12

 

  1. 使用L293D这样的H桥的方式来驱动步进电机,详细请参考上两节介绍的L293 Motor Sheild官网的说明。

steper13steper14

我们以ULN2003为例,现有的驱动板可以用来驱动步进电机,我们只需要选择Arduino的四个输出端口用杜邦线分别连接驱动板的IN1IN2IN3IN4,再用外置电源连接驱动板的5-12V+接口,并把电源和Arduino的地(GND)与驱动板的(-)共线即可。

steper15

steper16

ULN2003采用的是达林顿管(Darlington transistor)方式来增强对大电流负载(如步进电机)的驱动,所谓达林顿管其实就是二级放大的三极管而已(如右图所示),经过恰当的三极管型号选择匹配后,两次放大的三极管驱动能力比一个三极管更强。详情请参考ULN2003DataSheet。但无论哪种方式,记住,使用额外的外接电源来驱动晶体管和集成芯片,它才是电机的真正的能量提供者。

关于实际的步距角

前面所讲述的其实是一个简化模型,真正的步进电机步距角比较小。因为采用了图所示的多齿结构,这种结构类似于游标卡尺的工作原理,所以实际4相步进电机的步距角并非360°/8 = 45°。根据其规格书,本节范例所用的步进电机的步距角是5.625°,如果采用一-二相励磁方式,则可以达到其一半的分辨率。

steper17

如果图所示仍然令你感到困惑,可以查看下面这个网址所示的动画。

www.pengky.cn/cizudj/bujin-DDJ2/bujinDDJ-DH.flv

/* 
 步进电机速度控制示例
 
本示例程序用于驱动非极性步进电机。
电机的接口连接至Arduino的8至11号端口
变阻器连接至模拟端口A0

电机将沿着顺时针方向旋转,电位器的模拟量越高,步进电机的转速就越快。
因为setSpeed()函数将设定每一步序的时间间隔。你可能会发现当电位器模拟量太低时,电机将会停止旋转。
*/

#include <Stepper.h>

const int stepsPerRevolution = 200;

Stepper myStepper(stepsPerRevolution, 8,9,10,11);            

int stepCount = 0;

void setup()
{
}

void loop()
{
  int sensorReading = analogRead(A0);
  int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  if (motorSpeed > 0)
{
    myStepper.setSpeed(motorSpeed);
    myStepper.step(stepsPerRevolution/100);
  } 
}

关于精确驱动大功率步进电机的原理,请参考

http://www.szleadtech.com.cn/jishu/article_det.aspx?Id=6

steper18steper19

上图所示类型是一般功率较大的步进电机,在爱好者自制的3D打印机如RapRepCNC系统中常常见到,驱动他们最好使用专用的驱动模块,如图所示。

选用电机及其控制系统需要适当的权衡。例如,不要将步进电机用于高速应用,也不要将直流电机用于低速高转矩场合。步进电机已经具备了半闭环反馈,所以直接应用即可,而直流电机则适用于高速带传动等,如需要更大的转矩,则需要如齿轮等机构来转换,当然如果你想精确的控制直流电机,也可以在其中添加编码器,然后用微控制器去检测电动机的精确位置和速度。而将减速增转矩以及精确位置反馈的功能集合到一起的装置,就是下一节介绍的伺服电机(舵机)。

【教程】Arduino控制的机械臂

有同学说我这个机械臂很像挖掘机,好吧,考不上蓝翔的同学们看过来!

【点击此处下载机械臂结构的CAD图】可以直接发图给淘宝的店家加工,这里默认亚克力板的厚度为2.4mm。

工具:1、热熔胶枪;2、电烙铁;3、螺丝刀套件

材料:

Arduino UNO                                       x 1

旋转式电位器                                       x 4

自锁开关                                                x 1

MG995舵机                                           x 4

SG90舵机                                              x 1

5-9V电源                                                 --

一些线材                                                 --

需要用到的标准件有:M4*10螺栓18个,M4螺母18个,M2*6圆头带垫自攻螺丝。M4螺母和螺栓可用【膨胀塑料卡扣】代替。

        从视频中可以看到,机械臂实际上是在模仿一个4连杆机构的动作,而连杆的转动副就是旋转电位器。所以整个系统可以分为【机械臂主体】和【控制器】2个部分来制作。

一、机械臂主体

         主要结构为标称3mm的(实际为2.4mm)亚克力板材。

         舵机采用4个MG995(要求有十字、六角、圆盘配件包)和1个SG90(任意配件)。

         SG90与机械爪子之间靠粘合剂固定。螺栓+螺母作为轴承时可用粘合剂固定螺母在螺栓上的位置。

        由于加工精度和材料的物理特性,各板相接的榫位可能不能很好地卡住甚至出现断裂的情况,可以选择放弃榫接而采用热熔胶或者粘合剂进行固定。

        本人在制作实物的过程中发现一些设计问题,由于疏忽,也许并未能把所有的问题都在设计图中重新修改,敬请原谅。

        使用者可以一次加工更多的零件作为后备,防止在有零件损坏的情况下没有备用零件。

        下载本文的附件,在淘宝搜索“亚克力加工 激光”搜索到相关店家,联系客服,选好合适的亚克力板材(3mm),发送dwg文件给客服,确认无误后下单即可。

ATTENTION:
        【水深!对于价格一定要货比三家!同时要确认板材实际厚度为2.4mm!】

sg90舵机
sg90舵机
mg995舵机
                mg995舵机

预调电位器预调电位器

舵机的安装
            舵机的安装
舵机的安装
             舵机的安装
爪子细节
              爪子细节
安装好的样子
                                                 安装好的样子

由于有些部分已用热熔胶固定,Ttable不再将其分解拍照了。附件里每个dwg文件都只是机械臂的一部分,使用者们可以对照着先拼装出各个部分,再总装起来。

使用的过程中,Ttable发现它容易倒,使用者可以通过修改底盘的设计或者为底盘增加一点配重来解决这个问题。

 

 

二、连杆控制器

这部分没什么好说的,随便找点杆状材料,转动副是电位器,用热熔胶粘成连杆就行,可谓简单粗暴。

IMG_20141006_203839 IMG_20141006_203854

不过要注意两点:一是要注意电位器的初始位置要能使每个节点的运动范围和机械臂对应关节的运动范围保持一致;二是,如果你使用碳膜电位器(如图),你会发现接触不良的频率非常高,所以要用足够的热熔胶来固定电位器引脚的接线。

要用足够的热熔胶来固定
要用足够的热熔胶来固定
末端是一个自锁开关,用来控制爪子。
末端是一个自锁开关,用来控制爪子。

 

制作完两个部分之后,就可以把所有东西连接起来了。

从上面可以看到控制器的接线非常混乱……线多没办法,而且线要足够长,避免影响控制器的活动范围。同理,机械臂的舵机线也要足够长。

接线图
接线图(有一个button忘了画,其实就是一个button,连接arduino的数字0口)

 

为了防止干扰,机械臂和Arduino要使用两个独立的电源。我用的是2组串联的18650电池。另外,供给机械臂的电压不可以高于9V,否则会烧坏SG90。

 

后来我使用万能板来代替面包板
后来我使用万能板来代替面包板

 

 

用简陋的排针来和Arduino链接
用简陋的排针来和Arduino链接

最后,代码来了。

Continue reading 【教程】Arduino控制的机械臂

电池的分类和特性

一次性电池(Primary Battery)俗称“用完即弃”电池,因为它们的电量耗尽后,无法再充电使用,只能丢弃。常见的一次性电池包括:
锌锰电池—电压约1.5V,电池容量较低,能输出的电池也较低,几乎被碱锰电池所取代,唯独是不会在长期存放后漏出有害腐蚀液体,所以仍被使用于低用电量同时需长期使用的装置,例如钟、红外线摇控等。
碱锰电池—电压约1.5V,电池容量及输出的电池较锌锰电池高,但不及镍氢电池,长期存放后漏出有害腐蚀液体。

battary

市面上常见不可充电5号(AA)、7号(AAA)电池都属于上述介绍的两种电池,还有一种常见的9V电池也常常也用来和Arduino供电

battary02

当这种电池其实是内部由多组各自是1.5V的电池串联来达到对外9V供电的,这种电池往往也是不可循环充电使用。处于日益受重视的环境问题,以及消费者使用产品的经济性,我们越来越倾向于使用可充电的电池,而干电池只在功耗较低的设备上仍旧使用。
可充电电池又称二次电池(Secondary battery)、蓄电池。可充电电池按制作材料和工艺上的不同,其优点是在充电后可多次循环使用,它们可全充放电两百多次甚至达2500次,充电电池的输出电流(负荷力)要比大部分一次性电池高。常见的类型有:

battary03battary04

铅酸电池—电压约12V,能量密度较低,所以体积庞大。但可以做出大容量的、且能放出巨大电流的电池,所以仍然无法淘汰。汽车启动电机通常需要200A 左右的电流,目前只有铅酸电池能胜任。它还有一个好处:充电简单,不用放电完就可以充,而且是简单的恒压充电。过放电将导致电池性能下降,需要激活处理。体积较大的机器人可以考虑使用。

battary05battary06

battary14

镍氢电池NiMH —电压约1.2V,有极轻微的记忆效应,容量较镍镉电池及碱性电池大,可充放电循环使用数百至二千几次。虽然镍氢电池的电压时1.2V,但在大多数场合可以替代1.5V的干电池。旧镍氢电池有较大的自放电,新的低自放电镍氢电池 自放电低至与碱性电池相约,已取代了镍镉电池和绝大部份碱性电池的用途,能量密度要求不高的场景下推荐使用。

battary07

市面上常见的18650锂离子电池

battary12
锂离子电池Li-ion—电压约3.6、3.7V,锂离子电池具有重量轻(容量是同重量的镍氢电池的1.5~2倍)、容量大、无记忆效应等优点,具有很低的自放电率,因而即使价格相对较高,仍然得到了普遍应用,包括许多电子产品,而且不含有毒物质,但这类用于消费性电子产品的Li-ion电池在存放一段时期后电量会永久减少。另也有用于纯电动车(如特斯拉)及混合动力车的Li-ion电池,用于这用途的锂离子电池容量相对略低,但有较大的输出、充电电流,也有的有较长的寿命,但成本较高。

battary08

battary13

锂聚合物电池 ( lithium polymer ) 或聚合物锂电池又可简称为锂聚电池 ( Li-Po )、或聚锂电池都是一种锂离子电池升级替代品。锂聚电池通常是由数个相同的平行子电池芯 ( secondary cells ) 来增加放电电流,或由数个电池包(pack)串联来增加可用电压。锂离子电池为锂聚电池的前身,主要差异为电解质使用液态有机溶液而非胶状或固态的聚合物,这使得锂聚合物电池在过压充电和短路时只会鼓起、不会发生爆炸的危险。现在电子产品(如智能手机、平板电脑、蓝牙耳机、非廉价移动充)中已有替代锂离子电池的趋势。
电池使用的基本准则:
1、任何时刻都不允许将电池短路,购买正规厂家的电池和符合规格的充电器进行充电,不要图便宜,本书附录将介绍一些较为正规的厂家及购买途径。
2、在能量密度没有特殊要求的场合,优先考虑镍氢电池NiMH,能量密度要求较高的场合(如四轴飞行器),优先考虑锂聚合物电池( Li-Po )。因为锂离子电池Li-ion虽然能量密度大,但意外短路或者充电方式不正确(这通常是由劣质充电器造成)都可能引发爆炸,威胁人身安全。
3、认真阅读电池及充电器的说明书或规格书,依照规范使用电池,必要时做好防护措施。

battary09 battary11

18650锂电短路爆炸后                                锂电过压充电爆炸试验

Arduino的编码盘与反馈

市面上的电机质量参差不齐,便宜的电机普遍都有10%的误差,这意味着,Arduino控制器给出同样驱动信号,两个电机转过的角度和转速都会有较大差别。在机器人运行的过程中,如果左右轮电机不对称,机器人在直线驱动信号下将走弯路。这一点后续还会讲到,但是本节介绍的编码器,其主要功能就是反馈电机运动的速度与位置,能做到让电机基本指哪转哪。编码器的实现方式通常有磁式和光学两种,不过原理非常类似,只是磁式采用霍尔传感器检测磁场的脉动,而光学编码器采用光敏元件检测。下面就以光学编码器为例简要介绍其工作原理。为了检测细微运动并输出为数字脉冲信号,码盘(旋转运动)或码尺(直线运动)被细分成若干校区,每个小区透光或者反光。以透光式为例,当光源由码盘一侧向另一侧发射一束光时,另一侧的光敏元件进行检测。如果码盘角度正好位于光线能穿过的地方,光敏元件导通,输出高电平,反之则光敏元件管断,输出低电平。随着码盘的转动,传感器就能连续不断地输出脉冲信号,对该信号在特定时间内计数,则可测量其转过的角度,已经获得平均速度。

encoder01

encoder02

前面一节提到了电机的正反转驱动问题,在检测的时候也会有此困惑,上述介绍的编码盘工作方式是无法获得旋转方向的。所以有提出采用绝对编码器的方案,详情请参考附录或相关资料。在大多数情况下,许多增量编码器通过增加多一个码区,即可完成判断转向的功能。

encoder03

增量编码器给出两相方波,它们的相位差90°,通常称为A通道和B通道。其中一个通道给出与转速相关的信息,与此同时,通过两个通道信号进行顺序对比,得到旋转方向的信息。还有一个特殊信号称为Z或零通道,该通道给出编码器的绝对零位,此信号是一个方波与A通道方波的中心线重合。

encoder04

旋转编码器可通过旋转可以计数正方向和反方向转动过程中输出脉冲的次数,旋转计数不像电位计,这种转动计数是没有限制的。配合旋转编码器上的按键,可以复位到初始状态,即从0开始计数。

encoder05

encoder06

增量型编码器精度取决于机械和电气两种因素,这些因素有:光栅分度误差、光盘偏心、轴承偏心、电子读数装置引入的误差以及光学部分的不精确性。确定编码器精度的测量单位是电气上的度数,编码器精度决定了编码器产生的脉冲分度。以下用360°电气度数来表示机械轴的转动,而轴的转动必须是一个完整的周期。要知道多少机械角度相当于电气上的360度,可以用下列公式来计算:电气360 =机械360°/n°脉冲/转

encoder07

现在市面上已经有了专门的编码器模块,配合联轴器可以直接与电机相连,测量我们需要测量轴的转动情况,如右图所示,看起来很像电位器的样子,但它可以连续360°旋转,一圈脉冲数:20。

编码器(Encoder)也可以直接用现有的Arduino类库直接操作,使用起来简单方便,其代码如下,详细资料及类库下载,请访问源码作者博客或Arduino官网相关了解更多。

http://playground.arduino.cc/Main/RotaryEncoders

http://www.pjrc.com/teensy/td_libs_Encoder.html

/* 编码器示例程序
 * 源码作者相关信息
 * http://www.pjrc.com/teensy/td_libs_Encoder.html
 * 该代码位于公共域
 */

#include 

Encoder myEnc(5, 6);

void setup() {
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");
}

long oldPosition  = -999;

void loop() {
  long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition);
  }
}

用Arduino检测颜色

很多机器人竞技及爱好者制作过程中都需要能辨别颜色的传感器,比如赛道中的区域和信标的识别,又或者一些爱好者希望制作一款能够自动还原实物魔方(Rubik's Cube)的机器人。
关于颜色的基本问题,笔者经验很多初学者还混淆“光的三原色及颜料的三原色”,这可能会影响颜色传感器使用的理解,下面先做一简单介绍。
我们看到叶子是绿色的,并不是因为叶子发出绿色的光,而是因为白色阳光中混合了各种颜色的光,除了绿色被反射以外,其它颜色的光都被吸收了。

color01

光的三原色(RGB) 颜料的三原色(CMYK)
将橙红和绿的色光混合,可得到黄色光;绿和蓝紫光混合可得到青绿色光;橙红和蓝紫混合可得到红紫色光。若将三原色光混合,则会变成白光。这些色光混合后,会得到比原来色光更明亮的色光,因此色光的混合,又称为“加色混合”。
色彩有减法,是由于物体表面上的颜料,吸收了日光中一部份的光波,反射日光其他的色光,当两种或多种颜料混合的时候,有更多的色光被吸收,越少的色光被反射,因而形成暗色或黑色。色彩的减片法是运用在颜料的混合,亦广泛地运用在印刷技术之中。同时色彩的减法又称为CMYK,CMYK分别代表三原色中彩蓝C (Cyan),洋红(Magenta),黄(Yellow),以及黑(Black)。黑色虽然不属于三原色的一种,但在印刷上,要加上黑颜料才能调出真正的黑色。
由上面的三原色感应原理可知,如果知道构成各种颜色的三原色的值,就能够知道所测试物体的颜色。对于 TCS3200来说,当选定一个颜色滤波器时,它只允许某种特定的原色通过,阻止其它原色的通过。例如:当选择红色滤波器时,入射光中只有红色可以通过,蓝色和绿色都被阻止,这样就可以得到红色光的光强;同理,选择其它的滤波器,就可以得到蓝色光和绿色光的光强。通过这三个值,就可以分析投射到 TCS3200 传感器上的光的颜色。仔细观察芯片的放大照片就可以看到。在透明塑料封装的芯片中央有一个硅片,其中的电极用纯金跳线和外部引脚相连。因为此芯片需要透光工作,不同于其它黑色塑料封装的芯片,恰好能够一窥集成电路IC芯片的内部结构。这是笔者故意设此一节讲解该芯片的原因之一。
我们还可以看到硅片中央有8×8=64个颜色不同的方块,这其实是64个小光敏二极管,不过上面都有滤镜,只能分别透过红(R)、绿(G)、蓝(B)三种颜色光中的一种,以检测这三种光线分量的强度。三种颜色光的光敏二极管等量均布在64块方砖中。

color02color03

Texas Advanced Optoelectronic Solutions(TAOS)公司是全球公认的光传感技术创新厂商,其所生产的TCS3200颜色识别芯片在机器人爱好者中得到广泛的应用。许多开源硬件模块提供商利用这块芯片制成颜色模块出售。这些模块大同小异,在使用前比较重要的还是了解此款芯片的基本工作原理。在AllDataSheet网站中中查找此款芯片的资料,可以了解到以下几点:

color04color05color06

该芯片有8个引脚,其中OE用于选择此芯片是否正常工作,因为其它引脚可以和其它传感器共用Arduino引脚,在OE为有效状态时,整个芯片才工作。无效状态时,其它引脚都处于高阻状态,相当于断开连接。OE上划一横线表面,OE是在低电平时有效,而非高电平。
VDD和GND是电源正负极,如欲知道此专业名词来历请查阅晶体管工艺相关书籍,由于DataSheet中指明工作电压范围2.7V~5.5V,所以和Arduino连接时直接接5V端口即可。
OUT是唯一一个输出端口,输出固定频率的方波来传达检测所得颜色信息。
S0、S1、S2、S3此四个都是输入的设置端口,具体功能下面两表介绍

color07
根据DataSheet可知,100%的频率输出的时候,典型的方波频率是600kHz,占空比50%,但是由于一些控制器无法检测频率过高的频率,所以可以通过设置S0、S1两个输入引脚的电平,按相应比例降低输出方波的频率,以便于低速的信号捕捉电路能够侦测统计相关信号,但传感器信号的刷新速度也会随之降低。由于Arduino的速度已经足够快较准的捕捉100%频率的TCS3200信号,故S0、S1均设置为高电平(H/HIGH)。

color08
S2和S3输入引脚依照一定的组合,可以分别获得红(R)、绿(G)、蓝(B)三种颜色光的强度,所以在使用颜色传感器的过程中,只要在较短的时间内逐次扫描分别获得三种色光的分量即可初步判断物体的大致颜色了
下面给出TCS3200各控制引脚与Arduino控制器的硬件连线与程序源代码。

color09

//测试颜色识别模块TCS3200
const int s0 = 8;
const int s1 = 9;
const int s2 = 12;
const int s3 = 11;
const int out = 10;
   
//定义LED端口
int pinRed = 2;
int pinGreen = 3;
int pinBlue = 4;
    
//RGB颜色色值
int red = 0;
int green = 0;
int blue = 0;
    
void setup()   
{  
  pinMode(s0, OUTPUT);  
  pinMode(s1, OUTPUT);  
  pinMode(s2, OUTPUT);  
  pinMode(s3, OUTPUT);  
  pinMode(out, INPUT);  
  pinMode(pinRed, OUTPUT);  
  pinMode(pinGreen, OUTPUT);  
  pinMode(pinBlue, OUTPUT);  
  Serial.begin(9600);  
  digitalWrite(s0, HIGH);  
  digitalWrite(s1, HIGH);  
}  
    
void loop() 
{  
  color();
  //输出RGB各色值
  Serial.print("Red:");  
  Serial.print(red, DEC);  
  Serial.print("Green:");  
  Serial.print(green, DEC);  
  Serial.print("Blue:");  
  Serial.print(blue, DEC);  
  Serial.println();  

  //检验结果是否红色 
  if (red < blue && red < green && red > 50)  
  {  
   Serial.println("Red");  
   digitalWrite(pinRed, HIGH); //点亮红色LED 
   digitalWrite(pinGreen, LOW);  
   digitalWrite(pinBlue, LOW);  
  }  

  //检验结果是否绿色
  else if (blue < red && blue < green)   
  {  
   Serial.println("Blue");  
   digitalWrite(pinRed, LOW);  
   digitalWrite(pinGreen, LOW);  
   digitalWrite(pinBlue, HIGH); //点亮绿色LED 
  }  

  //检验结果是否蓝色
  else if (green < red && green < blue)  
  {  
   Serial.println("Green");  
   digitalWrite(pinRed, LOW);  
   digitalWrite(pinGreen, HIGH); //点亮蓝色LED 
   digitalWrite(pinBlue, LOW);  
  }  
  Serial.println();  

  //延时两秒后关闭所有LED
  delay(2000);   
  digitalWrite(pinRed, LOW);  
  digitalWrite(pinGreen, LOW);  
  digitalWrite(pinBlue, LOW);  
 }  
    
void color()  
{  
  //设置好S2、S3端口,准备读取颜色值
  digitalWrite(s2, LOW);  
  digitalWrite(s3, LOW);  
  //红色光RED
  red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);  
  digitalWrite(s3, HIGH);  
  //蓝色光BLUE  
  blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);  
  digitalWrite(s2, HIGH);  
  //绿色光GREEN  
  green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);  
}

Arduino控制小型直流电机

电机俗称马达(Motor),有直流驱动的有交流驱动的,还有用汽油(航模车模)、液压驱动的马达(大型工业设备)。一般所指的电机是通过电生磁原理将电路中的电能转换成机械能的装置。本节仅讨论常见的小功率直流电机,对于工业上常用的异步交流电机的控制因涉及诸多电力电子技术细节超出本书细节,请有兴趣的读者可以参考电机学相关著作或教材。

DCmotor01

图所示为一直流电机(DC Motor)工作原理示意图。一对静止的磁极N和S之间,安装了一个可以绕中心轴旋转的漆包线线圈及其包裹的层叠硅钢片。硅钢片的目的是为了增强线圈产生的磁导,减少漏磁,而硅钢片叠加在一起相互又绝缘,是为了防止硅钢片内产生较大的涡流而损耗电能在发热上。中间转动的部分通常称为电枢,而线圈两端分别接在换向器的两个半圆铜片上,铜片之间相互绝缘,但分别接直流电源正负极。其中的磁场和产生的电枢转矩如何计算,为何需要设置换向器等问题在初中物理教科书中已有论述,在此不再赘述。

DCmotor02

需要说明的是,电机是较大功率的器件,他不能直接用Arduino的端口去驱动。一般来说,Arduino的每个引脚只能扇出(source)或者灌入(sink)最大40mA的电流,而所有端口的总电流不超过200mA(0.2A),而一般小电机也往往超过100mA。因此,只能采用放大驱动的方式,以晶体管(BJT)驱动电路为例,将端口连接至基极,就可以不到几mA的电流驱动流经电机的数百mA电流。下图晶体管集电极上连接的5V视直流电机的额定电压而定。一般按照直流电机上的铭牌来选择此路供电电源的电压和带负载能力,且最好将此路供电电源与Arduino的供电电源分开,以防止电机启停时对电源的干扰影响Arduino的正常工作。
针对不同电机(或者大负载),需要使用不同型号的晶体管放大,所以读取电机铭牌上的参数就显得尤为重要。下面是一款常见电机的说明书部分截取,资料来自Sparkfun官网,电机型号为Micro Metal Gearmotor 30:1 ROB-08911,从中我们可以获得相关信息,从而达到合理选用匹配的驱动器(三极管)。

DCmotor03
然后我们从常见的晶体管目录中选择,下面的较为常用的一些小功率晶体管型号,更多常用晶体管列表目录及其关键参数,请参考附录。

S9011 S9012 S9013 S9014 S9015 S9018 A1015 C1815
A42 A92 2N5401 2N5551 A733
C945 S8050 S8550 2N3906 2N3904
譬如在型号为S9013的晶体管的DataSheet说明中,我们看到如下表格数据
DCmotor04

可见S9013放大后连续正向电压和电流分别达到20V和500mA,完全能够满足额定电压和电流分别是6V和100mA的直流电机负载且有几倍的裕量,故可以满足要求。如果你手上的电机无法找到相应的规格书,你可以通过在电机工作时测量其电压和电流来进行简单的估计。
下面我们就来接线驱动小电机,不过我们不能忽略电机内的线圈,这意味着电机在断电一瞬间将产生巨大的自感电动势,其峰值很可能会超过晶体管所能承受的最大电压,所以必须减缓自感可能带来的不利因素。根据楞次定律,带有电感负载的通路端口的一瞬间,产生的自感有保持原有电流方向的趋势,所以我们可以在电机两旁并联一个二极管来释放因自感产生的尖峰电压。二极管选用较为常用的型号1N4001即可,关于二极管的参数选择过程与之前三极管的过程类同,请读者自行查阅Datasheet练习。

DCmotor05DCmotor07

 

DCmotor06

/* -----------------------------------------------------------
 * | Arduino小电机驱动电路示例程序 |
 * | 代码出处http://ardx.org/4001 |
 * | 连线时请注意参考右图引脚位置 |
 * -----------------------------------------------------------
 */

int motorPin = 9; //定义电机连接引脚

void setup()
{
  pinMode(motorPin, OUTPUT);
}

void loop()
{
  motorOnThenOff();
  //motorOnThenOffWithSpeed();
  //motorAcceleration();
}

//关闭电机
void motorOnThenOff(){
  int onTime = 2500; //调节开关占空比,也可使用PWM模拟输出方式
  int offTime = 1000;

  digitalWrite(motorPin, HIGH);
  delay(onTime);
  digitalWrite(motorPin, LOW);
  delay(offTime);
}

//电机以特定速度启停
void motorOnThenOffWithSpeed(){

  int onSpeed = 200;
  int onTime = 2500;

  int offSpeed = 50;
  int offTime = 1000;

  analogWrite(motorPin, onSpeed);
  delay(onTime);
  analogWrite(motorPin, offSpeed);
  delay(offTime);
}

//电机变速
void motorAcceleration(){
  int delayTime = 50; //调整速度的时间间隔

  //电机加速
  for(int i = 0; i < 256; i++){
    analogWrite(motorPin, i);
    delay(delayTime);
  }

  //电机减速
  for(int i = 255; i >= 0; i--){
    analogWrite(motorPin, i);
    delay(delayTime);
  }
}

由于一个晶体管驱动的电机只能单向驱动调速,有时候往往还需要电机能够正反转。如图所示,当Q1管和Q4管导通,Q2和Q3截止时,电流从电源正极经Q1从左至右流过直流电机,然后再经Q4回到电源负极,从而驱动直流电机沿一个方向旋转。反之,当Q2和Q3导通,Q1管和Q4管截止时,电流从直流电机右边流入,从而驱动直流电机沿另外一个方向旋转。这种驱动方式的电路和字母“H”非常相似,所以就往往被称为H桥驱动电路。这样类似的H桥组合驱动电路可以自行搭建,但要注意不能让Q1和Q2或者Q3和Q4同时导通,哪怕是较短的时间也不允许,因为这会使得电源正负极直接相连,可能损坏电源或晶体管。所以在执行使用H桥驱动直流电机电路前请务必仔细检查电路和程序,以防短路。

DCmotor08意法半导体公司(STMicroelectronics)生产的L293D和L298P两款芯片是市面上常见的H桥电机驱动集成芯片,它们的外形虽然看起来很不一样,但是只要掌握其中一种的原理和使用方法,再学习使用另外一个就不会太难。这两款芯片的细节参数请读者自行查阅AllDataSheet网站,但很多机器人或电子模块提供商已经将H桥做成了Arduino的专用模块甚至是盾牌(Sheild),配合专门的Arduino类库,使用起来会大为方便。本节以美国开源硬件商Adafruit制作的一款293 Motor Sheild为例来说明如何实现电机的调速与正反转。
DCmotor10

此款Motor Sheild采用了两个L293及一个74HC595芯片,可以同时控制4路直流电机或者两路步进电机和舵机。本节仅介绍此款Motor Sheild普通直流电机的使用,关于步进电机和舵机,请参考本书后续部分或Adafruit官网:
https://learn.adafruit.com/adafruit-motor-shield/using-dc-motors
DCmotor09

此款Motor Sheild使用前有专配类库,可以到GitHub网站下载
https://github.com/adafruit/Adafruit-Motor-Shield-library
需要注意的是,电机有四个连接口,如图所示,连接其中一个即可(下面的示例程序使用的是Motor #4)。此种连接端子用于连接电流较大的场合,故使用的是螺丝刀拧紧的方式,在把电线剥开一小段距离后,松开螺丝放入电线裸露端再拧紧螺丝即可。如果在使用过程中发现电机转向与你所需的方向相反,断开电源后将两根连接线交换位置后重新连接即可。

// Adafruit Motor shield library
// 此代码位于公共域

#include <AFMotor.h>
AF_DCMotor motor(4);

void setup() {
  Serial.begin(9600);
  Serial.println("Motor test!");
  //打开电机
  motor.setSpeed(200);
  motor.run(RELEASE);
}

void loop() {
  uint8_t i;
  Serial.print("tick");
  motor.run(FORWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i);
    delay(10);
  }
  for (i=255; i!=0; i--) {
    motor.setSpeed(i);
    delay(10);
  }
  Serial.print("tock");
  motor.run(BACKWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i);
    delay(10);
  }
  for (i=255; i!=0; i--) {
    motor.setSpeed(i);
    delay(10);
  }
  Serial.print("tech");
  motor.run(RELEASE);
  delay(1000);
}

上述示例程序实现的是电机简单的正反转加速减速,故不再添加注释。

Arduino操作伺服电机/舵机(一)

舵机简单的说就是集成了直流电机、电机控制器和减速器等,并封装在一个便于安装的外壳里的伺服单元。能够利用简单的输入信号比较精确的转动给定角度的电机系统。
舵机安装了一个电位器(或其它角度传感器)检测输出轴转动角度,控制板根据电位器的信息能比较精确的控制和保持输出轴的角度。这样的直流电机控制方式叫闭环控制,所以舵机更准确的说是伺服马达,英文servo。
舵机的主体结构如下图所示,主要有几个部分:外壳、减速齿轮组、电机、电位器、控制电路。工作原理是控制电路接收信号源的控制信号,并驱动电机转动;齿轮组将电机的速度成大倍数缩小,并将电机的输出扭矩放大响应倍数,然后输出;电位器和齿轮组的末级一起转动,测量舵机轴转动角度;电路板检测并根据电位器判断舵机转动角度,然后控制舵机转动到目标角度或保持在目标角度。

图 舵机外观及内部主要结构示意图

舵机是一个微型的伺服控制系统,具体的控制原理可以用下图表示:

图 舵机控制原理示意图

控制电路接收信号源的控制脉冲,并驱动电机转动;齿轮组将电机的速度成大倍数缩小,并将电机的输出扭矩放大响应倍数,然后输出;电位器和齿轮组的末级一起转动,测量舵机轴转动角度;电路板检测并根据电位器判断舵机转动角度,然后控制舵机转动到目标角度或保持在目标角度。
模拟舵机需要一个外部控制器(遥控器的接收机)产生脉宽调制信号来告诉舵机转动角度,脉冲宽度是舵机控制器所需的编码信息。舵机的控制脉冲周期20ms,脉宽从0.5ms-2.5ms,分别对应-90度到+90度的位置。

模拟舵机由于使用模拟器件搭建的控制电路,电路的反馈和位置伺服是基于电位器的比例调节方式。电位器由于线性度的影响,精度的影响,个体差异性的问题,会导致控制匹配不了比例电压,比如我期望得到2.5V的电压位置,但第一次得到的是2.3V,经过1个调节周期后,电位器转过的位置已经是2.6V了,这样控制电路就会给电机一个方向脉冲调节,电机往回转,又转过头,然后有向前调节,以至于出现不停的震荡,这就是我们所看到的抖舵现象。在购买一批舵机中会发现有的很好用,有的在空载的时候也会在抖动,有的是在加一定的负载后就开始抖动。

servoAnimation


舵机除电源外,只要一根信号线即可;使用PPM(脉冲比例调制)信号控制;所谓“PPM”,是一个周期约20ms,其间有个宽度在2ms 左右的脉冲控制信号。一般是以1.5ms 为基准,此时舵机居中,小于1.5ms 舵机左转,大于1.5ms,舵机右转;至于角度和脉冲宽度关系各个产品不同,例如:0.5ms 对应左转90 度,2.5ms 对应右转90 度。
舵机内部实际上是由小电机、减速齿轮、驱动电路、位置反馈、比较电路等组成的闭环控制单元,由于其内置减速齿轮,所以输出力矩较大。最早将其改造为轮式机器人动力源的爱好者估计就看上了这些,他们将舵机的限位去除,位置反馈去除,舵机控制电路因得不到反馈,以为还未转到指定的角度,只好一直驱动电机转动,由于去除了限位,输出轴实现了连续转动,就成了一个减速直流电机。而且,利用其原来的左、右转控制逻辑,实现了正、反转控制。从本质上说,舵机和直流减速电机相同,只是利用了舵机内部的驱动和控制电路,从而简化了控制接口和电路。实际上:改造为连续转动的舵机 = 电调 + 直流减速电机电子调速器的控制信号和舵机一样,只是在小型电机中一般用不着电调,因为其功率不太大,一般在10A 以上,100A 也不足为奇,大材小用了。舵机还有一个优点是安装方便,除自身安装外,安装车轮也很方便,因为舵机一般提供丰富的轴输用舵机作为小车动力,可用MCU 直接驱动,不需要再设计、制作额外的驱动电路,这点对于DIY 者而言还是颇具吸引力的。而且控制所需的MCU 资源也有限,只要一个数字I/O口、一个定时器即可,虽说准确生成2ms 左右的脉冲有些技巧,但总的来说编程相对容易。如果用Arduino 系列控制器,其Servo 函数可让你一条语句“搞定”。
结论:使用舵机作为小车驱动一是为了便于装,二是为了便于控,三是可简化电路。其代价就是“力气”略小,可供选择的规格有限。还有就是略有些不“经济”,因为舵机的“贵贱”主要体现在其控制精度上,改为连续运转的驱动电机后,这部分功能给“废”了,是不是有些可惜?不过也不完全“浪费”,舵机的这部分控制通常采用PID 调节,其比例功能可用于调速,当输入的脉冲偏离中点(1.5ms)越远,其驱动电机的速度越快,而且其调节电路使用了电机反电势作为反馈,原设计大概是为了保证舵机在轻、重负荷下都可以按照相近的速度转到指定的角度,以实现较好的控制特性(比如说60 度/0.22 秒)。改为连续转动后正好作为调速功能,这也是使用舵机的一大优点。

图 连续舵机外观及中位点调节示意图

上图所示是较为常用的一款常用的连续旋转舵机,可以使用螺丝刀调节其中位点,以使其脉冲中点能在1.5ms附近变化。

// Controlling a servo position using a potentiometer (variable resistor) 
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> 

#include  
 
Servo myservo;  // create servo object to control a servo 
 
int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
void loop() 
{ 
  val = analogRead(potpin);        // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);   // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);             // sets the servo position according to the scaled value 
  delay(15);                    // waits for the servo to get there 
}

// Sweep
// by BARRAGAN <http://barraganstudio.com> 
// This example code is in the public domain.


#include  
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
 
 
void loop() 
{ 
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees    {                                  // in steps of 1 degree      myservo.write(pos);              // tell servo to go to position in variable 'pos'      delay(15);                       // waits 15ms for the servo to reach the position    }    for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

Arduino实践-超声波(ultrasonic)测距

科学家们将每秒钟振动的次数称为声音的频率,它的单位是赫兹(Hz)。我们人类耳朵能听到的声波频率为20Hz~20000Hz。当声波的振动频率小于20Hz或大于20KHz时,我们便听不见了。因此,我们把频率高于20000赫兹的声波称为“超声波”(ultrasonic)。通常的超声波频率为1兆赫兹~5兆赫兹。因其方向性好,穿透能力强,易于获得较集中的声能,在传播距离较远,故而常被被用于测距。

ultrasonic
超声波发射器向某一方向发射超声波,在发射的同时开始计时,超声波在空气中传播,途中碰到障碍物就立即返回,超声波接收器收到反射波就立即停止计时。超声波在空气中的传播速度为340 m/ s,根据计时器记录的时间t,就可以计算出发射点距障碍物的距离S ,即:S = 340t / 2。超声波指向性强,在介质中传播的距离较远,利用超声波检测往往比较迅速、方便、计算简单、易于做到实时控制,并且在测量精度方面能达到工业实用的要求,因此在移动机器人的研制上也得到了广泛的应用。
超声波发生器可分为两大类:一类是用电气方式产生超声波;一类是用机械方式产生超声波。电气类包括压电型、磁致伸缩型和电动型等;机械类包括加尔统笛、液哨和气流旋笛等。它们所产生的超声波的频率、功率和声波特性各不相同,因而用途也有所不同。目前常用的是压电式超声波发生器。
压电式超声波发生器实际上是利用压电晶体的谐振来工作的,其外观结构与内部结构分别如图所示.该传感器有两个压电晶片和一个共振板, 当其两极外加脉冲信号,且频率等于压电晶片的固有振荡频率时,压电晶片将会发生共振,并带动共振板振动产生超声波。反之,如果两电极间未外加电压,当共振板接收到超声波时,将迫使压电晶片振动,将机械能转换为电信号,这时它就成为超声波接收器了。

图 超声波测距模块内部结构简图

       超声波测距传感器规格很多,测试距离也从远到近都有,价格相差也较大,一般机器人爱好者使用的都是测量范围在最小几厘米到最大几米之间,典型值是2厘米到2米,精度约5毫米。超声波测距的优点在于测量范围较大,且不是使用光学信号,所以被测物体的颜色对于测量结果没有影响。但还是常常会受到外界环境的其它因素影响,依靠声速测距,所以对于一些影响声速的因素较敏感,比如温度、风等。最大允许角度较小。在不同的室温下,声速是不同的,因而会给测距带来误差,所以一般的模块测距精度都难以小于5毫米。但很自然的会想到采用温度补偿的方式,也即额外再添加一个温度传感器,根据不同温度下的声速来计算,从而可以补偿温度变化带来的误差,有估算用的近似公式

声速 = 331 + 0.6 t (攝氏温度)

根据测得的实际温度矫正环境中的真实声速,以减小测量误差。这样的模块测距精度就可以达到1~2毫米了,而且同时能当做温度传感器来使用,但价格也会稍高。
超声波测距传感器可能是机器人中运用最为广泛的传感器之一了,它不仅便宜,拥有丰富的库,而且测量结果也较为可靠。我们都知道蝙蝠夜行时躲避障碍物的原理,下面以一款市面上最为成熟和常见的超声波测距模块HC-SR04为例来说明。

该超声波模块没有自带温度补偿,以340m/s的室温下声速作为参照基准,同个扩展库捕捉脉冲宽度获得超声波来回的时间后,通过简单的运算获得距离。

#include 

#define TRIGGER_PIN  12
#define ECHO_PIN     13

Ultrasonic ultrasonic(TRIGGER_PIN, ECHO_PIN);

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  float cmMsec, inMsec;
  long microsec = ultrasonic.timing();

  cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
  //下面被注释的三句以英寸显示距离,该单位较少使用,故注释掉相关语句
  //inMsec = ultrasonic.convert(microsec, Ultrasonic::IN);
  Serial.print("MS: ");
  Serial.print(microsec);
  Serial.print(", CM: ");
  Serial.print(cmMsec);
  //Serial.print(", IN: ");
  //Serial.println(inMsec);
  delay(1000);
}

       超声波测距的原理简单易懂,因为有成熟的扩展库,使用起来也很方便。所以很多机器人爱好者都会选择它来作为壁障的传感器,但是,超声波本身的性质也会导致一些问题的存在。
超声波测距其实是一种不完全感知,对于不同形状的物体它所表现的特性其实并不相同。而障碍物的形状对超声波测距的影响则是角度范围甚至是障碍物判定的正确与否。它下述两幅简图是由美国一超声波传感器制造商在用户手册中给出的关于不同形状障碍物超声波测距结果的比较,可以看出,对于不同形状的物体超声波测距的结果有很大差异,这样一来就会给壁障判断带来不利影响。

图表 1
图 超声波测距模块对圆柱障碍物的测量值分布图

图3.12 超声波测距模块对平板障碍物的测量值分布图
除上诉问题之外,国内外还有些学者还提到了超声波测距过程中可能因为幻影问题而难以穿越复杂障碍物环境并且为此提出了相应的模糊算法

图 超声波测距模块产生幻影原理示意及响应模糊算法对于复杂障碍物群的壁障轨迹

液压传动视频介绍

Hydraulic machines are machinery and tools that use liquid fluid power to do simple work. Heavy equipment is a common example.

In this type of machine, hydraulic fluid is transmitted throughout the machine to various hydraulic motors and hydraulic cylinders and which becomes pressurised according to the resistance present. The fluid is controlled directly or automatically by control valves and distributed through hoses and tubes.

The popularity of hydraulic machinery is due to the very large amount of power that can be transferred through small tubes and flexible hoses, and the high power density and wide array of actuators that can make use of this power.

Hydraulic machinery is operated by the use of hydraulics, where a liquid is the powering medium.

————————From wikipedia

 

液压技术与气动、电气装置都是机器人和机械驱动技术中不可忽视的选择之一。近年来由于电气技术的普及,而让许多人对此项技术的了解渐渐陌生。其实,生活中仍然有许多装置需要液压,这在重型机械中表现得尤为明显。而液压系统也可以类似于电路一样,进行仿真。下面的这些视频来源于德国一款优秀的液压与气动仿真软件,希望对于需要了解这项技术,想要了解这项技术,或者喜欢机器人技术但对工业现场实现该技术不甚了解的朋友有所帮助。

http://hydraulicspneumatics.com/网站拥有该项技术的完整及前沿资料的分享。欲了解更多的朋友或者机械专业从业者们可以从中收获更多相关细节

液压传动简介

工作油液

压力与流量

输出力和位移传递

压力传递

流动状态

液压系统结构

液压源部分

Hydraulic pump

Hydraulic pumps supply fluid to the components in the system. Pressure in the system develops in reaction to the load. Hence, a pump rated for 5,000 psi is capable of maintaining flow against a load of 5,000 psi.

Pumps have a power density about ten times greater than an electric motor (by volume). They are powered by an electric motor or an engine, connected through gears, belts, or a flexible elastomeric coupling to reduce vibration.

Common types of hydraulic pumps to hydraulic machinery applications are;

An exploded view of an external gear pump.

  • Gear pump: cheap, durable (especially in g-rotor form), simple. Less efficient, because they are constant (fixed) displacement, and mainly suitable for pressures below 20 MPa (3000 psi).
  • Vane pump: cheap and simple, reliable. Good for higher-flow low-pressure output.
  • Axial piston pump: many designed with a variable displacement mechanism, to vary output flow for automatic control of pressure. There are various axial piston pump designs, including swashplate (sometimes referred to as a valveplate pump) and checkball (sometimes referred to as a wobble plate pump). The most common is the swashplate pump. A variable-angle swashplate causes the pistons to reciprocate a greater or lesser distance per rotation, allowing output flow rate and pressure to be varied (greater displacement angle causes higher flow rate, lower pressure, and vice versa).
  • Radial piston pump: normally used for very high pressure at small flows.

Piston pumps are more expensive than gear or vane pumps, but provide longer life operating at higher pressure, with difficult fluids and longer continuous duty cycles. Piston pumps make up one half of a hydrostatic transmission.

液压缸和液压马达

控制阀基础

Control valves

Directional control valves route the fluid to the desired actuator. They usually consist of a spool inside a cast iron or steel housing. The spool slides to different positions in the housing, and intersecting grooves and channels route the fluid based on the spool's position.

The spool has a central (neutral) position maintained with springs; in this position the supply fluid is blocked, or returned to tank. Sliding the spool to one side routes the hydraulic fluid to an actuator and provides a return path from the actuator to tank. When the spool is moved to the opposite direction the supply and return paths are switched. When the spool is allowed to return to neutral (center) position the actuator fluid paths are blocked, locking it in position.

Directional control valves are usually designed to be stackable, with one valve for each hydraulic cylinder, and one fluid input supplying all the valves in the stack.

Tolerances are very tight in order to handle the high pressure and avoid leaking, spools typically have a clearance with the housing of less than a thousandth of an inch (25 µm). The valve block will be mounted to the machine's frame with a three point pattern to avoid distorting the valve block and jamming the valve's sensitive components.

The spool position may be actuated by mechanical levers, hydraulic pilot pressure, or solenoids which push the spool left or right. A seal allows part of the spool to protrude outside the housing, where it is accessible to the actuator.

The main valve block is usually a stack of off the shelf directional control valves chosen by flow capacity and performance. Some valves are designed to be proportional (flow rate proportional to valve position), while others may be simply on-off. The control valve is one of the most expensive and sensitive parts of a hydraulic circuit.

控制阀:换向阀

控制阀:开关阀

控制阀:压力控制阀

控制阀:流量控制阀

液压系统的回路图表示