[Raspberry Pi +. net mf to create a video surveillance Smart Car] control (. net mf)

Source: Internet
Author: User


In the previous remote control article, we introduced the signal collection and programming of Sony PS2 controllers. Through simple encapsulation, we provided the key information in Event Mode. This article mainly introduces how to drive the vehicle motor and control manipulator after the. NET Micro Framework system receives the button information.

Both the driving vehicle motor and the control manipulator are controlled by the output PWM, but the method for controlling the PWM output is somewhat different. Let's first introduce the control of the vehicle motor.

Because the drive motor requires relatively large current, the I/O of the main chip cannot be directly driven, and a drive needs to be connected in the middle. That is to say, the main chip outputs a PWM control driver, and the driver outputs a large current to drive the motor.

Generally, a driver can drive two-way motors, while a motor usually requires two-way signals to control the speed and direction of the motor by controlling the output of two-way PWM. Our car uses a drive with photoelectric isolation, high power, one motor, three IO control, two of which is the control direction, one output PWM control of the car speed.

 

One driver module requires four GPIO (control direction) two-way PWM, plus a 3V3 And GND, a total of eight channels, we adopt the standard. NET Gadgeteer interface (10 pin: 1 3V3, 1 5 V, 1 GND, 7 GPIO channels), you can directly insert two on lingxiao Development Board. NET Gadgeteer interface, the wiring is simple and direct (as shown in the two flat cables ).

Manipulator control is more easy, a three-wire steering gear, power supply (5 V), ground and signal line (PWM), three steering gear, a total of three PWM output control. Note that power supply is also required. PWM is directly output by the lingxiao development board I/O.


The following describes the PWM interface function class of. NET Micro Framework

PWM (Cpu.PWMChannel channel, frequency_Hz, dutyCycle, PWM (Cpu.PWMChannel channel, period, duration, PWM.ScaleFactor scale, Duration {; DutyCycle {; Frequency {; Period {;
 

The two constructors are introduced separately.

PWM (Cpu.PWMChannel channel, double frequency_Hz, double dutyCycle, bool invert);

channel-channel, different systems, the number of supported channels is different. For example, Lingxiao system supports 16 channels, which should be more.

frequency_Hz-frequency, the unit is Hz, the frequency value of the pulse.

dutyCycle-Duty cycle, a number between 0 and 1, indicating the ratio of the duration of the high level to the entire cycle in a cycle.

Invert-signal inversion, high and low level inversion switching, generally the bottom layer does not process this parameter, so it is generally set to false.

 

public PWM (Cpu.PWMChannel channel, uint period, uint duration, PWM.ScaleFactor scale, bool invert);

channel-channel.

period-period. The unit and scale options are the same.

duration-High level duration, unit and period are the same.

scale-the time unit of the period, which can be milliseconds, microseconds, nanoseconds, microseconds is recommended.

Invert-Invert the signal.

 

The first constructor is generally used to control the motor, and the parameter setting is more intuitive. The frequency can be 1K ~ 250KHz (recommended about 10K), by setting the size of the duty cycle (0 is to stop, 1 is full speed) to adjust the speed.

The second constructor is suitable for controlling the steering gear. The typical control curve of the steering gear is as follows:

 

F is the so-called period. If we set the scale to microseconds, we can directly set it to 20000. The so-called pulse width is the value of duration. You can set it to between 1000 ~ 2000 There are differences, please adjust according to the actual).

With the above introduction, we can easily complete the motor drive and servo control.

A. Drive motor

Definition of motor drive control parameters:

  PWM [] motor_pwm = PWM [[] frequency = [] {,,, [] dutyCycle = [] {,,, [] states1 = [] {,,,,,,, [] states2 = [] {,, ,,,,, OutputPort [] In = OutputPort [];

  

  
= (i =; i <In.Length; i ++ = OutputPort (pins [i],
= (i =; i <motor_pwm.Length; i ++ = PWM (motor_chanels [i], frequency [i], dutyCycle [i],

In the event code of Sony PS2, we fill in the following code:

  ps2_Click ((e.key ==== (button.state ==)
[] buffer = [] {, () e.x, () e.y,,
] .Duration = (UInt32) (durations [] + (-e.x) *
] .Duration = (UInt32) (durations [] + (-e.y) *

= UInt32 [= (UInt32) (System.Math.Abs (e.x-= (UInt32) (System.Math.Abs (e.y-(i =; i <values.Length; i ++) values [i] = (e.y <

                     (i =; i <In.Length; i ++

                     (x> (e.x <] =] =] =] =

                     (i =; i <In.Length; i ++

                     (x> (e.x <] =] =] =] =

                 (i =; i <motor_pwm.Length; i ++) motor_pwm [i] .DutyCycle = (values [i] /

Definition of servo parameters:

 PWM [] steering_pwm = PWM [UInt32 [] periods = UInt32 [] {,,,,};

Cpu.PWMChannel [] steering_chanels = (i =; i <steering_pwm.Length; i ++ = PWM (steering_chanels [i], periods [i], durations [i], PWM.ScaleFactor.Microseconds,

  ps2_Click ((e.key == PS2.Key.LRocker)

] .Duration = (UInt32) (durations [] + (-e.x) *
] .Duration = (UInt32) (durations [] + (-e.y) * (e.key == PS2.Key.R2)

+ =; (value>) value =] .Duration = (UInt32) (durations [] + (value-) * (e.key == PS2.Key.R1)

-=; (value <) value =] .Duration = (UInt32) (durations [] + (value-) *

 

Video link: http://v.youku.com/v_show/id_XNjY2MTE1NjQ0.html

Article navigation:

1. [Raspberry Pi + .NET MF to create a video surveillance smart car] Remote control

2. [Raspberry Pi + .NET MF to create a video surveillance smart car] Control (.NET MF)

3. [Raspberry Pi + .NET MF to create a video surveillance smart car] Control (Raspberry Pi)

4. [Raspberry Pi + .NET MF to create a smart car for video surveillance] Video articles

 summary:

1. The design of the .NET Micro Framework PWM class is very consistent with the user's cognition and usage habits, and can easily implement the corresponding functions.

2. Through VS2010 / VS2012 online debugging, you can quickly test out the appropriate control value.

3. The above code can be completed in about ten minutes, which fully reflects the rapid development of .NET Micro Framework.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.