答:
It all depends on your experience and comfort in coding and understanding the navigation algorithms needed to allow the drone to fly autonomously. Most flight controllers on the market come with inbuilt sensors (gyros,accelerometers,magnetometers,etc) and usually fly on manual control via an RC transmitter/receiver combo.

I'm in the same situation as you, and I'm attempting to make my own flight controller using the Arduino Mega board, for which I've bought external sensors to aid in flight.

If this is your first quadcopter project and you wish to program your own flight controller, write code to control the quadcopter manually, since that will give you experience and a wider understanding of how the flight controller works in tandem with the esc's,sensors and transmitter. Keep in mind that this is a lengthy process, and a lot of patience is needed to gain a good understanding of the project.

Good Luck!

PS: If you need any help with programming, PM me, i can provide you some links that might help you :)

Title: For a quadcopter: Premade flight controller or custom made?

Body:
I'm interested in building a quadcopter. The result I'd like to obtain is an autonomous drone. I'd be interested in a GPS to allow it to remain stationary in the air, and also to fly through checkpoints.

Can this be done with a flight controller, or does it need to be programmed? I'm not too sure about what flight controllers really are.

Could someone offer any materials to help me get towards this goal.

Thanks, Jacob


问:
How can I best protect sensitive components against damage through vibration?
It's common for components on some types of robots to experience large environmental stresses, one key one being vibration. Is this something I need to worry about with typical electronics and other sensitive components, or not really? If it is, then how do I secure such components?

I've heard of two main philosophies behind this, the first being that you should use a damping system such as with springs to absorb the shock. The second is that you should keep everything rigidly in place so it can't move, and therefore can't hit against anything else and break.

Which one should I follow, or if the answer is "it depends" what should I use as a guide as to best protect sensitive components?

答: It will take a lot to shake components off of a PCB/PWB so for the most part it should be safe if you make sure that the mounting is correct.  One thing that people forget is that if there is vibration then there may also be flex, and even tiny amounts of flex transmitted into a PWB can be damaging.  FR4 is stiff and in the wrong location will take a lot of the stress loads.  But this is easily fixed with the right kind of mounting that doesn't allow the force to transfer through the board - anchored on one side, semi-rigid on the other side.</p>

ContentLicense: CC BY-SA 3.0


问:
Controlling the Power of a Solenoid
I am trying to control the force of a solenoid. My current system has a bank of capacitors connected to a relay. In order to control the force (how hard I am trying to hit the object) I am increasing or decreasing the the time the relay is on. The problem is this works but it either hits with too much force or way too much force. I can turn the relay on for 5 ms or more. If I try to turn it on for 1 ms it does not even respond. (I am using a mechanical relay.)

I would like to have more control on how much of the energy I discharge so I can control how hard/soft the solenoid moves (say discharge only 10 percent of the total energy stored so it hits slower). While searching I found out about Solid State Relays which according to wikipedia can be switched on an off way faster that mechanical relay (of the order of microseconds to milliseconds).

So my question is am I on the right track? or is there something better to achieve what I am trying to achieve?

答:
To clarify, you have a bank of capacitors and you want to use them to power a solenoid for a short period of time, right?  I assume you are directly connected to the solenoid coil, not through a controller or anything.

In this case the variables you can alter are length of pulse, and current of pulse.  Decreasing either of these will of course cause your capacitors to drain less with each pulse.  The actual force from the solenoid is much more linearly affected by current than length of pulse, and the easiest way to decrease current is to simply stick a power resistor somewhere along the line between the caps and the solenoid.

Title: Controlling the Power of a Solenoid


问:
Arduino or Raspberry Pi?
I want to make a object tracking quadcopter for a project. While I'm using the Arduino Mega 2560 as the flight controller, I was thinking of using an additional offboard microcontroller/board for getting data from the onboard camera,which would then send an appropriate command to the onboard Arduino.

I was hoping someone could provide clarification on the advantages/disadvantages of doing object tracking with either choice.

Thanks!

答:
For interfacing with a camera, I would recommend the Pi. The reason is that the AVR in the Arduino is an ordinary processor, whereas the Broadcom SoC in the Pi was originally designed for multimedia. Besides the ARM processor, it contains video encoding/decoding hardware that you won't find in the Arduino.

Of course, you would need to learn how to use that extra hardware.

Title: Arduino or Raspberry Pi?


问:
Ultrasonic Sensor through a column
I am trying to measure the height of water inside a column. The column is 50mm in dia and 304mm long. I have mounted the sensor just above the column.

To measure the accuracy of the sensor, I filled the column up to a known value (a) and got the average sensor reading (b). a+b should give me the height of the sensor from the base of the column.

Repeating this for different values of a, I got very different values for (a+b). see attached chart.

My question is

Is the sensor expected to have error of this order?

Is my setup of confining the sensor through a column producing such errors.

Any other ideas to get the water column height. Please note that during the actual test, the water inside will be oscillating (up and down).I am thinking of making a capacitive sensor using aluminium foil. Water will work as the dielectric and the level of water will determine the capacitance.

P.S. I also did some open tests (not through a column) to get the distance of a fixed object, and it was quite accurate.

Any help is appreciated.

Arduino Code

```<code>#include <NewPing.h>

#define TRIGGER_PIN  7  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     8  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

double DB_ROUNDTRIP_CM = 57.0;

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.
}

void loop() {
  delay(100);
  unsigned int uS = sonar.ping();
  double d = uS / DB_ROUNDTRIP_CM;

  Serial.println(d);
}
</code>```

答:
Ultrasound sensors like this have a very wide beam spread. In fact the word "beam" is completely inappropriate. So I think you're right, confining it like this is likely to cause problems.

To test this, set the sensor up in free air then put a solid obstacle beside the beam, but a few centimetres clear of it. It'll probably cause stray readings.

If you need to measure in such a narrow column, I'm not sure what you could do... very high frequency ultrasound sensors have a narrower beam, but they are expensive. Maybe you could have some sort of optical sensors, arranged beside the column, and a "float" placed in there to block the sensors...

Title: Ultrasonic Sensor through a column


问:
Is there a way to combine and sync two 2K cameras @ 90fps with ICs
I am searching for a way to minimize the size of a stereo vision module and cannot find any ICs that will combine and sync two MIPI CSI-2 (4 lane) data streams without an FPGA and too much code.  there was one online (MAX7366A 3D Video Combiner/Synchronizer with two MIPI CSI-2 Input and one MIPI CSI-2 output) but the product is not publicly available.   Does anyone have knowledge of an arrangement of ICs that I could try?.</p>

答: The OV580 from Omnivision will do what you are asking for, and provide you with a USB3 interface. There is a product from leopard imaging with 2 MIPI CSI-2 interfaces. I think it will only work with certain Omnivision cameras though. </p>


问:
How can I charge a 11,1 volt LiPo akku?
I didn't found any modules to charge my 11,1 volt LiPo akku, only for 3,7 volt with 5 volt power supply. How can I handle that with a micro-USB connector on my robotplatform?</p>

答:
What exactly are you trying to do? You have an 11.1 volt, 5000mAh battery pack. That is, you have a (11.1*5)V-Ah battery pack, or a 55.5 Wh battery pack.

A micro USB connector can safely pass 9W of power, meaning it would take (55.5Wh/9W) = 6h10m to charge, assuming you could perfectly utilize all of that power.

You should consider instead either:

Take the batteries out of the vehicle to charge, or

Put a proper battery charger on your vehicle and use a different connector than micro USB.

I'll warn you that LiPo batteries are notorious for catching fire if they are not properly charged.

There are plenty of integrated circuits that will charge a LiPo battery, but again, I don't think you'll find one that simultaneously uses a micro USB input format to charge a battery of the style that you have because it would take so long.

Trying to hack your own circuit together to get what you want is needlessly dangerous.

Title: How can I charge a 11,1 volt LiPo akku?


问:
What does Simultaneous Localization And Mapping (SLAM) software do?
I took a course to have a better understanding of drones and their design. At the end of the course there was a test question that I got wrong and I would like to understand why.

I was supposed to select the choices that best describe SLAM.

and the possible answers were:

Estimates the location of features in the environment?

Controls the robot's flight through the environment?

Causes the robot to avoid obstacles in the environment?

Navigate in a cluttered environment?

Estimates the position and orientation of the robot with respect to
    the environment?

At first I knew that at least 3 and 4 were right because I watched a drone doing these things. I also thought that the last answer was linked to these two so I said yes to it too. Finally, I thought that the only thing that was still controlled by the user would be the flight...

Yet I failed again... Therefore what does Simultaneous Localization And Mapping (SLAM) software do?

答:
Localization is the process of estimating the pose of the robot the environment. Number 5 in your list. Mapping is estimating the position of features in the environment. Number 1.

2, 3, and 4 are not related to SLAM. They are all part of a complete robot system for which SLAM makes up yet another part. The software for a professional or research drone will have subsections that do flight control, obstacle avoidance, navigation (planning), SLAM, and other functions.

So you are correct in that you saw a drone do all those things, but SLAM is only one part of a robots software.

All this is a very simplistic view. In practice we never truly know the environment. We are estimating pose in the map, hoping it is the same as the environment. We build the map with feature positions but often have false readings of features, or mis-identify the same feature as being two separate ones. Few SLAM approaches consider features that move in the environment.


问:
Measuring vehicle's forward and lateral acceleration using a smartphone
I want to measure the acceleration (forward and lateral separately) using an android smartphone device in order to be able to analyse the driving behavior.

My approach would be as follows:

1. Aligning coordinate systems

Calibration (no motion / first motion):
While the car is stationary, I would calculate the magnitude of gravity using Sensor.TYPE_GRAVITY and rotate it straight to the z-axis (pointing downwards assuming a flat surface). That way, the pitch and roll angles should be near zero and equal to the angles of the car relativ to the world.

After this, I would start moving straight forward with the car to get a first motion indication using Sensor.TYPE_ACCELEROMETER and rotate this magnitude straight to the x-axis (pointing forward). This way, the yaw angle should be equal to the vehicle's heading relativ to the world.

Update Orientation (while driving):
To be able to keep the coordinate systems aligned while driving I am going to use Sensor.TYPE_GRAVITY to maintain the roll and pitch of the system via

where A_x,y,z is the acceleration of gravity.

Usually, the yaw angle would be maintained via Sensor.ROTATION_VECTOR or Sensor.MAGNETIC_FIELD. However, the reason behind not using them is because I am going to use the application also in electrical vehicles. The high amounts of volts and ampere produced by the engine would presumably make the accuracy of those sensor values suffer. Hence, the best alternative that I know (although not optimal) is using the GPS course to maintain the yaw angle.

2. Getting measurements

By applying all aforementioned rotations it should be possible to maintain an alignment between the smartphone's and vehicle's coordinate systems and, hence, giving me the pure forward and lateral acceleration values on the x-axis and y-axis.

Questions:

Is this approach applicable or did I miss something crucial?

Is there an easier/alternative approach to this?

答:
There are many things to consider.

Assuming that you are developing an app to accomplish this, you should invest some time in filtering. Depending on the vehicle and the phone's position in the vehicle, you would expect to encounter sensor noise due to vibration induced by the road surface or possibly the engine. Among many filtering techniques, Kalman filtering is often used with Accelerometer/Gyroscopes to fuse the raw sensor measurements and implementation is straight forward. To understand Kalman filtering (and possibly pick up a few other techniques), I suggest Sebastian Thrun's textbook Probabilistic Robotics, which covers the topic quite well.

While we are considering things you may have left out, assuming you are attempting to characterize driving behaviour of many test subjects, you should count on the subjects not using your app as intended. If a subject uses the phone while driving, your measurements will obviously be affected. Consider implementing a "quiet mode" while testing to discourage using the phone. Furthermore, you cannot assume that the phone will start in any one place.

Of the concerns above and the many like them, rather than characterizing driver behaviour in real-time using the phone, you could instead have the phone log raw sensor data, including GPS location and raw accelerometer/gyroscope data--you could then use statistical techniques (again described in Thrun's text) to determine the transformation between the coordinates of the phone and the coordinates of the vehicle to finally determine the pose of the vehicle and characterize driving behaviour. This approach has the benefit of being easier to deploy and being robust in the event that your characterization procedures change in the future.


问:
How to use the opcode to start?
I am new to robotics.Recently came into contact code.So the teacher let me use the Serial port app for Android to enter the opcode.But the robot did not have any reaction.

I use the Communications Cable with Adapter in android phone.
App Use [DroidTerm: USB Serial port]

Serial Port Settings
Baud: 115200   (19200 also used)
Data bits: 8
Parity: None
Stop bits: 1
Flow control: None

I try to enter opcode, but no response.--> enter:128,135,134.....
But it did not show any reaction to the phone and robot.
I hope according to Opcode instructions to control robots to make the specified action.

答:
The robot's baud-rate may not be the default rate of 115200. Try resetting the robot (by holding dock and spot for 10 seconds, or removing the battery). This will reset the baud-rate back to 115200.

If that doesn't work, try connecting the robot to a computer and using RealTerm or some other serial program and send the same data.

Also, when sending the data bytes, make sure they are being sent as raw 'numbers' (not ASCI).

Title: How to use the opcode to start?


问:
Charging multiple LiFePO4 batteries at the same time?
I'm looking to use 4 of these 3.2V LiFePO4 batteries. I intend to have 2 pairs of 2 in series in parallel. So two 6.4V battery packs in parallel. Because my setup will be run off of this, it will also be easiest to recharge the batteries using the same setup. To accomplish this, I'm looking to charge all the batteries at once using this 6.4V LiFePO4 smart charger. From a simplistic standpoint, the resulting voltage should be correct and this should work fine. However, I know (from a previous question) that LiFePO4 battery chargers are a bit more complex then a basic voltage supply and check. Would the setup I've described work correctly? And in general, will a LiFePO4 smart charger be able to charge several batteries of the correct voltage at the same time so long as it doesn't try to charge them at too high an amperage? Or does a LiFePO4 battery also have a minimum amperage cutoff point to charge such that trying to charge more than one battery at a time will cause problems? Any other issues I didn't mention? Thank you much!</p>

答: Basically for charging LiPo/LiFe, you will need charger with balancer which measure each cell voltage level, as they tend to overheat or get damaged or even burst into a flame when handling carelessly. Lipo/life doesn't like trickle charge as NiMh or NiCd and also you will need constant current output at different voltage levels. But there are smart chargers that can handle this. I guess you will need to connect all 4 cells to balancer as they are separated battery packs...</p>


问:
How to create a model for temperature control?
I have a heated compartment, inside which, there is another object heated up by independent heater. I want to control temperatures of both chamber and the object. </p>

<p>I could achieve this by simple PID (or PI) controllers for both chamber and object, but I would like to try more thoughtful approach :) I have two temperature sensors, and two PWM outputs for heaters. How do I identify a model for an object I want to control?   </p>

答:
Generally you would only develop a model if (as in your case), you have something that you want to control. In that case, you should start by:

List the outputs that you want to control.

List the inputs that you can modulate.

In your case, you want to control chamber temperature and object temperature. You can modulate the chamber heater and the object heater. Now, you have to ask yourself:

How do the inputs affect the outputs? You should shoot for an equation in the form of $\mbox{[outputs] = f(inputs)}$

This is important because you generally only want to model the things that are pertinent to the task at hand.

For example, say you want to develop cruise control for a car. The output you want to control is vehicle speed and the input you can modulate is throttle position. Can you model coolant reservoir level? Sure, but you can also assume the coolant system is functioning normally. Can you model the internals of an automatic transmission? Sure, but you can also assume that the automatic transmission gives output power equal to input power minus some losses.

The point is, you have to make some set of assumptions about the "nominal" scenario. Once you have your initial model, you attempt to validate the model by getting test data. Typically this means feeding an actual system a particular set of inputs and recording the response, then feeding the same inputs to your model and recording the response. The results should be (very close to) the same. How close is "good enough" depends on your application, and could be anywhere from "it generally trends the same" to virtually no error.

You can try developing a rudimentary controller around an unvalidated model if you've got time to kill, but you should generally wait for validation before expending a lot of effort on the controller because math errors and faulty assumptions can cause you to have to start over with controller development.

You can also skip the mathematical description if the system is too complex to be described mathematically, or if doing so would take too much time. "Empirical modelling" runs a similar sort of tests you would use to validate a model, but with the concept that, by seeing how a particular set of inputs create an output, you can derive some pattern that you can extrapolate a model that gives outputs for other inputs.

In your case, if you're really concerned with better control, I would probably suggest trying to build an empirical model. Try a variety of inputs on only one heater and record how that impacts chamber and object temperatures. Then do the same on the other heater. Best case is the effect of each heater is decoupled or weakly correlated to the other temperature - the space heater only heats the space and the object heater only heats the object. In that scenario you can have independent control, though I would imagine this would probably only happen if you had significant chamber losses relative to the output of the object heater and/or the chamber had a large thermal mass relative to the object.

And on a final note, I'll just add that, when gathering test data for a particular model, you should try varying all of the "nominal" conditions that you assumed to make sure it doesn't have an effect you should be modelling. For you, that would probably mean checking the ambient air temperature around the chamber is varied through all of the expected conditions. As I mention above you're probably more likely to achieve independent temperature control with large chamber losses (because your heaters are not bi-directional; they only make heat and cannot remove it), and the chamber losses are going to be related to ambient temperature. Testing in only hot weather (or vice-versa) will skew your results, model, and thus controller to a point that it might not be useful when the weather changes.


答:
Chuck is right; you need to build a model so that you can appropriately choose your controller.

Temperature control is non-trivial because the underlying dynamics are non-linear. Because heat transfer has been studied extensively (see thermodynamics), you may be able to build a decent model for your system using only existing models and parameter characterization of your specific system. However, if this doesn't work for you, perhaps your system is too complex or non-linearities are not modeled correctly, you can apply machine learning to learn the model of your system.

The task of learning the model of your system is a regression task. Gaussian Process Regression will work, but k-Nearest Neighbors is a good place to start. The link is very thorough on how GPR is and can be used--KNN is on wikipedia. You will still need data from your system, but using GPR or some other machine learning technique will have the benefit of not requiring hand-crafting your model.

I know it sounds like a lot of work, and it might be overkill for what you are trying to do, but by using ML to build the model, you can confidently apply a non-linear controller--linearization may or may not be possible.

Title: How to create a model for temperature control?

Body:
I have a heated compartment, inside which, there is another object heated up by independent heater. I want to control temperatures of both chamber and the object. </p>

<p>I could achieve this by simple PID (or PI) controllers for both chamber and object, but I would like to try more thoughtful approach :) I have two temperature sensors, and two PWM outputs for heaters. How do I identify a model for an object I want to control?   </p>


答:
Is the sensor expected to have error of this order?

In brief, yes. All sensors will have some degree of noise, which is characterized by the manufacturer. To avoid this, you can use a different sensor, or you can apply filtering to a very large dataset to extract the correct measurement. If you have the budget for it, a laser and photodetector of some sort will certainly give you better (less noise) results. Otherwise, you can apply a Kalman Filter or some other probabilistic technique to get a better estimate of the ground truth measurement.

Is my setup of confining the sensor through a column producing such
  errors.

Since you are using an ultra-sonic sensor, which has a conical "beam", the column will be acting as a wave-guide, and you can expect interference as a result, especially for smaller depths; this will increase measurement noise.

Any other ideas to get the water column height.

I think that the ultra-sonic sensor will work under two assumptions. First, you must apply some sort of filter/technique to estimate the true measurement based on the noisy measurements. I recommend Probabilistic Robotics by Sebastian Thrun for learning how to do this--it is well covered. The second assumption is that you don't need extreme precision.

Another approach to the problem would be to set up a camera, and use computer vision techniques to estimate depth; this is probably as easy as what you are doing, but it will require a different experimental setup.

Title: Ultrasonic Sensor through a column

Body:
I am trying to measure the height of water inside a column. The column is 50mm in dia and 304mm long. I have mounted the sensor just above the column.

To measure the accuracy of the sensor, I filled the column up to a known value (a) and got the average sensor reading (b). a+b should give me the height of the sensor from the base of the column.

Repeating this for different values of a, I got very different values for (a+b). see attached chart.

My question is

Is the sensor expected to have error of this order?

Is my setup of confining the sensor through a column producing such errors.

Any other ideas to get the water column height. Please note that during the actual test, the water inside will be oscillating (up and down).I am thinking of making a capacitive sensor using aluminium foil. Water will work as the dielectric and the level of water will determine the capacitance.

P.S. I also did some open tests (not through a column) to get the distance of a fixed object, and it was quite accurate.

Any help is appreciated.

Arduino Code

```<code>#include <NewPing.h>

#define TRIGGER_PIN  7  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     8  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

double DB_ROUNDTRIP_CM = 57.0;

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.
}

void loop() {
  delay(100);
  unsigned int uS = sonar.ping();
  double d = uS / DB_ROUNDTRIP_CM;

  Serial.println(d);
}
</code>```


问:
What is a suitable model for two-wheeled robots?
What is a suitable model for two-wheeled robots? That is, what equations of motion describe the dynamics of a two-wheeled robot.

Model of varying fidelity are welcome. This includes non-linear models, as well as linearized models.

答:
The answer to this is simple, but the other answers obfuscate the dynamics.

Differential drive robots can be modeled with unicycle dynamics of the form: $$\left[\begin{matrix}\dot{x}\\ \dot{y} \\ \dot{\theta} \end{matrix}\right] = \left[\begin{matrix}cos(\theta)&0\\sin(\theta)&0\\0&1\end{matrix}\right] \left[\begin{matrix}v\\\omega\end{matrix}\right],$$ where $x$ and $y$ are Cartesian coordinates of the robot, and $\theta \in (-\pi,\pi]$ is the angle between the heading and the $x$-axis. The input vector $\left[v, \omega \right]^T$ consists of linear and angular velocity inputs.


问:
What frequency does my quadcopter output-sense-calculate-output update loop need to stay stable?
With a 600 mm (2 foot) motor-to-motor quadcopter, what frequency does my output-sense-calculate-output update loop need to stay stable?

I'm estimating a total takeoff weight of very roughly 2 pounds ( 0.9 kg ),
which I expect to be mostly motors and batteries.

答: Your question can only be answered specifically if we have the model parameters of your system. The most principled approach to answering your question would be to represent the highly nonlinear dynamics of your system in discrete time; then using this representation, a maximum step size for which stability is achieved can be determined--this will be maximum value that your system can successfully use. A minimum step size will be determined not by the dynamics of the system, but by the hardware that you are using--overrunning is what would concern me in this case.  </p>


问:
What kind of torque is needed for a small 5-6 axis robotic arm?
I'm new to robotics and I'm looking to make a 5-6 axis robotic arm out of stepper motors but I honestly don't know how much torque I should have for each part. Below I have described in more detail what my current plan is but I'm really not sure as to how much I really should be spending on each of these joints.

My general plan for this project was to make a arm that when fully extended would only be around 40-50(max) cm long. It would be consisted of light weight aluminum and I am hoping for it to weigh only a couple of pounds when done.

Here is my current list of actuators for each of the joints:

(Bottom = 1, Top = 6)

1st joint, (Nema 23 CNC Stepper Motor 2.8A)

2nd and 3rd joints

4th, 5th and 6th joints

My real questions is, is this overkill or is it not enough for what I'm really trying to make. I really don't need it to be able to pick up a lot of weight, at most 1 to 2 kilos but I highly doubt I will ever be picking up anything more than that. Anyway I just wanted to see if this was sufficient enough for my project.

答:
Well, Henry, at this point I would resort to a spreadsheet. Since lower motors need to hold higher motors, you would need the weight of each motor, as well as all of the other arm weights. Then, with the length of each arm, you can calculate the torque needed for each motor to just hold the rest of the arm, on down the chain to the gripper. It's a long string of calculations just to know how much torque you need to hold your load still in any position (most difficult is typically fully extended). Balancing each arm segment with counterweights would drastically reduce the needed torque, but the added mass will decrease acceleration.

To that number, you now need to add the torque required for moving. This will be based in your desired acceleration (velocity typically doesn't matter). The torque required to accelerate any given section is equal to the desired angular acceleration times the rotational-inertia of that arm segment and the segments that follow. Knowing the rotational-inertia of your arm segments is often difficult, and I often just over-estimate. Keep in mind that rotational-inertia increases as the arm extends to a longer radius, so you need to calculate worst-case.

So now you see why I use a spreadsheet. Your question is not an easy one to answer, and it requires a lot of data.

For a small robot arm, the motors become intrusive. They can be larger and heavier than the arm itself, and need to be large, just to carry their own weight. For small arms, I would recommend using tendons, and leave all motors on the base, where their weight is not an issue. It also means that you can tailor the size of the pulleys at each end to adjust the torque. That gives you an easy remedy if you find you need more torque or more speed.


问:
PID with position and velocity goal?
I'm trying to design a control system for a robot that tracks moving object. Thus I want to robot to match the position and velocity state of the object. I don't want robot to simply to arrive at the position, but I want to arrive at the position with the same velocity of the object.

Object velocity and position data will be provided externally.

I'm not sure if a traditional PID controller (with velocity controls) with just a position based error is enough. Wouldn't position only state goal result in tracking that is always lagging behind?

Is PID what I want or should I be looking at something else like trajectory controls?

答:
In the case of MIMO systems (Multi-Input, Multi-Ouput), my warm suggestion is to go with State Space Control, which will give you enough freedom to move the closed-loop poles and thus achieve your control requirements. One viable solution, explored quite a lot in literature, is to employ a LQR controller coupled with a state observer, where here the state is obviously composed of position and velocity.

With regards to the use of a simple PID, I believe these two following questions are very much related:

The aerial refueling problem: sketch of a feedback controller.

Control both Velocity and Position (Linear Actuator).

Title: PID with position and velocity goal?


问:
Local Localisation with particle filter
I am doing Local Localisation with sonar, particle filter (i.e all particles are initially with robot pose).

I have grip map of environment. When I execute algorithm in environment (where doors are closed/open), particles are not able to followup the robot.

I don't have random particles since I know the initial position of the robot exactly.

Adding random particle will change the pose of robot (i am find median of particles as robot pose).

Any idea/methods how to improve local localisation?

I want to know, do I need random variable if I am doing local localisation? And how do I improve localisation if there are many changes in the map without adding random particles?

答:
Of course adding random particles will change the pose of the robot. That's the point: To add randomness to account for errors you can't compute yourself. You should add random particles every time the state of the robot may change, then adjust the weight of the particles based on which seem likely given sensor data.

This is a very basic definition of particle filters. I suggest you roll up your sleeves and do some more research on the subject.

Title: Local Localisation with particle filter


问:
Detect physical touch/hit
I'm making a target to an outdoor robot competition.

The target should detect if some of the robot got touched or got an hit   automatically. and the target can get hit 360 degree.

I'm searching for the perfect sensor to detect an hit, without get false positive from a wind.

My option right now are:
1- ultrasonic sensor (bad coverage)
2- tilt sensor  (bad FP rate)
3- wooden conductive

I would like to know if someone has other ideas (that affordable - less than 30$ dollar per target might be o.k)

Edit: the target is static, and just waiting to a robot to touch it.

Edit: The specs are:

1- The target dimension is 1 meter height, 0.5 meter width , 0.3 depth.

2- To trigger the target ,the robot should be around 10 centimeter long to any point of the target surface.

3-To trigger the target the robot needs to get close up to 10 centimeter or even press with around 1 Newton force. the robot might even throw an object that satisfy the previous condition.

4-Detection must be only from intentional touch.

5-Wooden conductive is trigger because a human is Electrically conductive. this might not be the option when we throw an object.

6- Target will be placed outdoor, so the sensor need to be wind-resistance (not extreme wind condition- just around 20-25 km/h)

7- I  prefer a sensor that detect touch (more than proximity)because it might make my solution more cheap and reliable(in factor of amount sensors as i estimate).

Thanks.
Guy

答: Just an idea, I have used this Doppler radar module: https://www.amazon.com/SMAKN-Microwave-10-525GHz-Doppler-Detector/dp/B00FFW4AZ4, for velocity estimation and presence detection. I don't completely understand what the scenario is, but in theory if a target was moving towards your robot, you could measure that by looking at the output of the Doppler radar. If a target moves towards you then the frequency of the output signal would increase, if it moves away the frequency would decrease. Good alternative to an ultrasonic because of larger range, but you would probably need one on the front and back for full 360 coverage. Also you may have issues if the target is too small, but again I don't fully understand your scenario.</p>

Title: Detect physical touch/hit


答: The only issue with having the off-board controller is that the commands to the quad-rotor might lag, because of 1. range to controller or 2. the complexity of image processing code. With that said I wouldn't say use an Arduino only, because it probably won't be fast enough to do image processing + stabilization from accelerometers and gyroscopes. Instead use a raspberry pi and arduino in tandem, maybe the arduino is connected via serial. That way the arduino can do normal flight stabilization, and the raspberry pi can do image processing and send maneuvers to the arduino for appropriate action to the quad-rotor.</p>

Title: Arduino or Raspberry Pi?

Body:
I want to make a object tracking quadcopter for a project. While I'm using the Arduino Mega 2560 as the flight controller, I was thinking of using an additional offboard microcontroller/board for getting data from the onboard camera,which would then send an appropriate command to the onboard Arduino.

I was hoping someone could provide clarification on the advantages/disadvantages of doing object tracking with either choice.

Thanks!


答:
If in fact you need the robot to be at the same speed as the tracked object at the time it arrives with it, you might need to employ more sophisticated methods. However, a controller that is the correct type will achieve asymptotically 0 tracking error on position (implying zero error on velocity by extension). Type is the amount of integrators in your controller. Now if your object you will be tracking is moving linearly, you need a type 1 controller. If it is changing its speed as well as its position (up to quadratic paths), you need a type 2 controller.
My point is that if you know the constraints on the motion of the object you're tracking, and your specifications are that you must asymptotically approach the velocity and position of your object, you may be able to get away with employing a PID controller + integrator, which would look something like this: $$
\frac{k_{d}s^2+k_{p}s+k_{i}}{s^2} $$

or this:

$$ \frac{k_{d}s^2+k_{p}s+k_{i}}{s^3} $$

Careful though, these integrators can make your system unstable. You can test in Matlab.

Title: PID with position and velocity goal?

Body:
I'm trying to design a control system for a robot that tracks moving object. Thus I want to robot to match the position and velocity state of the object. I don't want robot to simply to arrive at the position, but I want to arrive at the position with the same velocity of the object.

Object velocity and position data will be provided externally.

I'm not sure if a traditional PID controller (with velocity controls) with just a position based error is enough. Wouldn't position only state goal result in tracking that is always lagging behind?

Is PID what I want or should I be looking at something else like trajectory controls?


答: Why don't just use bumpers? HCR robot is a nice example of a platform that uses this method.  The only downside is that they require some force to be pushed.</p>

Title: Detect physical touch/hit

Body:
I'm making a target to an outdoor robot competition.

The target should detect if some of the robot got touched or got an hit   automatically. and the target can get hit 360 degree.

I'm searching for the perfect sensor to detect an hit, without get false positive from a wind.

My option right now are:
1- ultrasonic sensor (bad coverage)
2- tilt sensor  (bad FP rate)
3- wooden conductive

I would like to know if someone has other ideas (that affordable - less than 30$ dollar per target might be o.k)

Edit: the target is static, and just waiting to a robot to touch it.

Edit: The specs are:

1- The target dimension is 1 meter height, 0.5 meter width , 0.3 depth.

2- To trigger the target ,the robot should be around 10 centimeter long to any point of the target surface.

3-To trigger the target the robot needs to get close up to 10 centimeter or even press with around 1 Newton force. the robot might even throw an object that satisfy the previous condition.

4-Detection must be only from intentional touch.

5-Wooden conductive is trigger because a human is Electrically conductive. this might not be the option when we throw an object.

6- Target will be placed outdoor, so the sensor need to be wind-resistance (not extreme wind condition- just around 20-25 km/h)

7- I  prefer a sensor that detect touch (more than proximity)because it might make my solution more cheap and reliable(in factor of amount sensors as i estimate).

Thanks.
Guy


答:
In many cases, a single traditional PID controller is adequate to track an object and match both position and velocity of the object.
With the error term of the PID in terms of position, the integral term ("I" of the PID) and the derivative term (the "D" term in the PID) each help compensate for the velocity of the object.

No matter what control system you use, if the object makes a sudden unexpected movement, the tracking will lag behind -- that's part of the nature of our causal universe.
(Please tell us if there are any, even completely infeasible, ways of eliminating all lag from an object tracker).

There are various feedforward approaches that can reduce (but never eliminate) the lag in a PID controller.
In your case, rather than the (traditional, error-amplifying) approach that makes D proportional to the derivative of the position error,
you may have less lag by directly measuring the speed of the object and the speed of your tracker and setting D proportional to their difference.
(Or perhaps proportional to the speed of the object alone).

If you want the tracker to arrive at the velocity of the object at the same instant that it arrive at the position of the object,
then you want a control system "without overshoot".
There are lots of applications that require such a control system,
and PID control systems can be tuned such that they have no overshoot after a step impulse.
(You probably already know that most PID control systems are tuned using a different critera that allows some overshoot and oscillation in order to reduce the lag in settling time; people using such systems use the term "overdamped" to describe settings that have no overshoot).

Bob Pease. "What's All This P-I-D Stuff, Anyhow?" ("you may get better results from having two sensors. The one that drives the Differentiator may be located very close to the heater as an aid to stability. But the one that drives the integrator may live in the "sweet spot" -- the exact place where highest precision is needed.")

The aerial refueling problem: sketch of a feedback controller

Leith Znaimer and John Bechhoefer. "Split PID control—Two sensors can be better than one".

"PID control without overshoot"

"Modified PID controller for avoiding overshoot in temperature of barrel heating system"

Title: PID with position and velocity goal?


问:
Linearize a non linear system
How do I linearize the following system using taylor series expansion:

$\dot x = v cos\theta \\ \dot y = v sin\theta \\ \dot \theta = u$

Here, $\theta$ is the heading direction of my robot, measured counter clockwise with respect to $x$ axis.

$v$ is the linear velocity of the robot,

$u$ is the angular velocity of the robot.

答:
The short answer to this question is that linearization won't work, and here's why:

Differential drive robots can be modeled with unicycle dynamics of the form: $$\dot{z}=\left[\begin{matrix}\dot{x}\\ \dot{y} \\ \dot{\theta} \end{matrix}\right] = \left[\begin{matrix}cos(\theta)&0\\sin(\theta)&0\\0&1\end{matrix}\right] \left[\begin{matrix}v\\\omega\end{matrix}\right],$$ where $x$ and $y$ are Cartesian coordinates of the robot, and $\theta \in (-\pi,\pi]$ is the angle between the heading and the $x$-axis. The input vector $u=\left[v, \omega \right]^T$ consists of linear and angular velocity inputs.

We can re-write this in affine form, such that:
$$\dot{z}=f(z)+g(z)u.$$
Notice that $f(z)=0$, which is equivalent to saying that there is no drift in the system. For clarity, let $\mathbf{g}(z,u)=g(z)u.$ The Jacobian, which is essentially a matrix of truncated Taylor series expansions, is used to linearize nonlinear systems about an equilibrium point, but the eigenvalues of the Jacobian matrix, evaluated at equilibrium, must be nonzero in order for the linearization to hold (there are some important theorems that come into play here, which are covered in linear algebra and linear systems textbooks). The Jacobian for state matrix A of the possible linearized unicycle system is given by: $$A:=D\mathbf{g}(z,u)=\frac{\partial \mathbf{g}(z,u)}{\partial z}=\left[\begin{matrix}\frac{\partial g_1(z,u)}{\partial x}&\frac{\partial g_1(z,u)}{\partial y}&\frac{\partial g_1(z,u)}{\partial \theta}\\\frac{\partial g_2(z,u)}{\partial x}&\frac{\partial g_2(z,u)}{\partial y}&\frac{\partial g_2(z,u)}{\partial \theta}\\\frac{\partial g_3(z,u)}{\partial x}&\frac{\partial g_3(z,u)}{\partial y}&\frac{\partial g_3(z,u)}{\partial \theta}\end{matrix}\right]=\left[\begin{matrix}0&0&-v\text{sin}(\theta)\\0&0&v\text{cos}(\theta)\\0&0&0\end{matrix}\right],$$
where $g_n$ is the $n^{th}$ function of $\mathbf{g}(z,u)$. Each element in the Jacobian is evaluated as follows, using $n=1$ as an example: $$\frac{\partial g_1(z,u)}{\partial x}=\frac{\partial (v cos{\theta})}{\partial x}=0.$$

By inspection, we can see that the eigenvalues of the Jacobian are zero for all $z$, never mind at any equilibrium point, so this system cannot be linearized. Despite not being able to linearize the system, non-linear control of unicycle robots is straightforward and well studied.

Title: Linearize a non linear system


问:
"Smooth" inverse kinematics model for 2-wheeled differential drive robot
I have been reading about kinematic models for nonholonomic mobile robots such as differential wheeled robots. The texts I've found so far all give reasonably decent solutions for the forward kinematics problem; but when it comes to inverse kinematics, they weasel out of the question by arguing that for every possible destination pose there are either infinite solutions, or in cases such as $[0 \quad 1 \quad 0]^T$ (since the robot can't move sideways) none at all. Then they advocate a method for driving the robot based on a sequence of straight forward motions alternated with in-place turns.

I find this solution hardly satisfactory. It seems inefficient and inelegant to cause the robot to do a full-stop at every turning point, when a smooth turning would be just as feasible. Also the assertion that some points are "unreachable" seems misleading; maybe there are poses a nonholonomic mobile robot can't reach by maintaining a single set of parameters for a finite time, but clearly, if we vary the parameters over time according to some procedure, and in the absence of obstacles, it should be able to reach any possible pose.

So my question is: what is the inverse kinematics model for a 2-wheeled differential drive robot with shaft half-length $l$, two wheels of equal radii $r$ with adjustable velocities $v_L \ge 0$ and $v_R \ge 0$ (i.e. no in-place turns), and given that we want to minimize the number of changes to the velocities?

答:
If I understand correctly, you would like to understand how control a two-wheeled differential drive robot so that you can achieve smooth/elegant driving while arriving at a desired final orientation--this is known as the parking problem. Ian presented an AI approach to the problem, which is interesting, but I would be remiss if I didn't interject with a control theoretic perspective.

Because two-wheeled differential drive robotics are a well-studied robotic platform, we can determine a control law from a model of the dynamics. Differential drive robots can be modeled with unicycle dynamics of the form: $$\dot{z}=\left[\begin{matrix}\dot{x}\\ \dot{y} \\ \dot{\theta} \end{matrix}\right] = \left[\begin{matrix}cos(\theta)&0\\sin(\theta)&0\\0&1\end{matrix}\right] \left[\begin{matrix}v\\\omega\end{matrix}\right],$$ where $x$ and $y$ are Cartesian coordinates of the robot, and $\theta \in (-\pi,\pi]$ is the angle between the heading and the $x$-axis. The input vector $\left[v, \omega \right]^T$ consists of linear and angular velocity inputs.

The parking problem that you mention interest in in your comment has been studied widely. A Smooth Control Law for Graceful Motion of Differential Wheeled Mobile Robots in 2D Environment presents one possible solution.

Another solution to tracking a trajectory is to control a point, which is holonomic, some small distance $l$ away from the center of the the two wheels rather than controlling the unicycle robot directly. To do this, we can derive the following rotation matrix to transform the control law of the robot to the control law of the point: $$\dot{p}=\left[\begin{matrix}\dot{p_x}\\\dot{p_y}\end{matrix}\right]=\left[\begin{matrix}\text{cos}(\theta)&-l\text{sin}(\theta)\\\text{sin}(\theta)&l \text{cos}(\theta)\end{matrix}\right]\left[\begin{matrix}v\\\omega\end{matrix}\right]$$

$\dot{p}$ is the velocity of the point being controlled, and it is decomposed into its $x$ and $y$ components. At this point, control is quite simple, simply control the point directly! Setting $$\dot{p}=u=r(t),$$ accomplishes this, where $u$ is the input, and $r(t)$ is the reference trajectory that you want; this will accomplish smooth movement along the trajectory.


问:
Arduino or Raspberry Pi?
I want to make a object tracking quadcopter for a project. While I'm using the Arduino Mega 2560 as the flight controller, I was thinking of using an additional offboard microcontroller/board for getting data from the onboard camera,which would then send an appropriate command to the onboard Arduino.

I was hoping someone could provide clarification on the advantages/disadvantages of doing object tracking with either choice.

Thanks!

答: One point that hasn't been addressed, which is admittedly outside the scope of the prompt, is whether or not a Pi should be used at all as the off-board component. Unless you are trying to develop on the Pi for a specific reason (possibly cost), you will be losing out on serious computational power that can be achieved with a laptop or desktop computer. Other posts highlight the fact that image processing will be computationally expensive, especially if it is needed in real-time. If you can keep everything on-board, then the following doesn't hold, but if you need to do off-board processing, I would advise you to develop on a "larger" linux box (or VM/dual-boot with Windows) first.</p>

Title: Arduino or Raspberry Pi?


答:
One option could be to use the MPU6050 IMU, or some other accelerometer. These sensors are cheap, so they will come in under your budget.

With acceleration measurements, you can detect impulses caused by striking the target surface. If you are assuming light wind, then you can probably just set a threshold that on the magnitude of the impulse, classifying measurements as hits only if they exceed a certain value. If you expect significant wind, you can do some sort of filtering.

It is hard to say more because your description is somewhat nebulous. Perhaps adding a diagram would help.

Title: Detect physical touch/hit


问:
iRobot Create2: Granularity of drive control?
I own an iRobot create2 on which I am planning to implement a control algorithm. After playing with the different drive commands, I noticed that changing the desired velocity values marginally doesn't seem to do anything.

Even the Drive PWM command that ranges from -255 to 255 seems to have an internal granularity that is bigger than 1.

In this video the create seems to change its driving direction nearly seamlessly, which I am not able to reproduce with the described behavior.

Does anyone have any suggestions?

答:
In my brief stint working with the Create 2, I noticed the same thing. Specifying very low velocities doesn't work very well, and small increases don't seem to do anything up to a certain point. This non-linearity in the response of the motors to the inputs can likely be explained by resistance (stiction) of the motors, which must be sufficiently overcome.

To get past the resistance, you could try supplying large jerk initially, then decreasing acceleration until the desired velocity is achieved.

I cannot speak to the velocities or controls used in the video, but I will point out that whenever the velocity (linear or angular) changes, there appears to be a rapid acceleration, which is what I have suggested.


问:
How does ODE determine contact points in Gazebo?
I was looking at the contact points for the Atlas in the DRCsim package. Each foot has 4 contact points at each vertex of the rectangle. I'd like to know how these points are determined. I've tried looking at the ODE code, but C++ isn't my strong suit so I had some difficulty figuring out what was going on. What I understand is that ODE compares the geometries one by one however it's not possible to compare all points so it only compare a select few points. What I'm trying to understand is what basis are those particular points selected? Why does the Atlas have the 4 contacts set up the way they are, and not some additional points on the heel? Can I add them myself?

Thanks.

答:
Collision detection is a main part of ODE

ODE has two main components: a dynamics simulation engine and a collision detection engine.

For ODE, there is a wiki page outlining how that part of ODE works. Collision is detected between geometric primitives that have been defined to resemble the shape of the simulated objects. There is a trade-off here between speed and accuracy. More complicated shapes will require more checks and reduce the overall performance of the simulation.

The basic geometry is not so complicated. The difficult part is making the checks fast. Diving into the C++ code might be challenging because of this.

And yes, you should be able to change the collision model. Have a look at the model files. Note that the collision model not necessarily the same as the visualisation.


问:
How would I go about making an art drawing robot like this?
I saw this art drawing robot on youtube:

http://www.youtube.com/watch?v=Wo15zXhFdzo

What do I need to learn in order to build something like that? What are some beginner oriented projects that could lead up to building something like this?

I'm an experienced programmer but I have very little hardware experience.

答:
This project is a great starter project for a programmer trying to get into robotics because it doesn't require a lot of knowledge or experience. Though it does require a small investment.

The arm itself is one of the LynxMotion Arms though I don't remember precisely which. An SSC-32 was used to interface the arm with the controlling computer. The SSC-32 has a really simple protocol and appears as a serial device. As such if you have any experience working with serial devices then you already know how to communicate with this robot. Otherwise, and it probably goes without saying, you need to learn how to communicate with serial devices.

With that said the real challenge with such a project would be learning how to control the location of the end effector by setting the angles of the joints. This is known as the forward kinematics problem and requires a kinematic model of the arm. You will also need to learn how to determine what joint angles are required given a desired end effector position. This is known as the inverse kinematics problem. Dr. Hollerbach's notes are a good resource for learning how to solve these problems. Interestingly @abstractcement had the idea of using bilinear interpolation to bypass the need for solving these problems which worked out beautifully.

You could also look into creating a dynamical model to control the forces and torques in the system. However in this project the robot moved slowly enough that the dynamics were neglible and were ignored altogether.

The real challenges with a painting robot are in the automated planning, motion planning, and control. But I won't go into any of that here because I believe it's beyond the scope of what you are asking.


问:
iCreate 2 with Arduino (Just getting going)
I am new to the iRobot Create 2 but I do know a thing or two about the Arduino (don't assume too much though). However, in this case, I am beyond stumped over what I am sure is something simple but is somehow not obvious to me. Three people have confirmed my wiring from the Create 2 to the Arduino to be correct and the code I have looks similar to many examples that I have seen on this forum. However, I cannot get my Create 2 to do ANYTHING. I am not at all sure what is wrong and I am starting to wonder if the robot is even receiving commands let alone doing anything with them. Is there anything wrong with this code and can anybody suggest a way to verify that the robot is receiving data (since it does not beep or provide return messages)? Thank you.

EDIT (06/24 01:10 EST); Updated code (with a few notes).

```<code>#########################
#include <SoftwareSerial.h>
#include <SPI.h>

int baudPin = 17;
int i;
int ledPin = 13;
int rxPin = 19;
int txPin = 18;

unsigned long baudTimer = 240000; // 4 minutes
unsigned long thisTimer = 0;
unsigned long prevTimer = 0;

SoftwareSerial Roomba(rxPin, txPin);

void setup() {
  pinMode(baudPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

  // I have tired communicating with both baud rates (19200 and 115200).
  // When trying the 115200 baud, I set "i<=0;" in the loop below since
  // the pulse does not need to be sent.
  Roomba.begin(19200);
  Serial.begin(115200);
  delay(2000);

  // I hooked up an LED in series with the baudPin so that it would turn
  // off when low thus giving me some kind of visual confirmation that a
  // pulse is being sent. See additional note in loop() below.
  for (i = 1; i <= 3; i++) {
    digitalWrite(baudPin, HIGH);
    delay(100);
    digitalWrite(baudPin, LOW);
    delay(500);
    digitalWrite(baudPin, HIGH);
  }

  // I know this might not be the right way to send data to the robot,
  // but I was fiddling with this while trying to figure out a separate
  // problem regarding the TX/RX lines which I am putting off until I
  // get the baud issue straightened out.
. /*
    int sentBytes = Roomba.write("128");
    Serial.print(sentBytes);
    Serial.print("\n");
  */

  i = 0;
}

void loop() {
  thisTimer = millis();

  // The LED that I have hooked up in series with the baudPin blinks
  // when the pulse is low, thus indicating that a pulse is being sent.
  // However, it only seems to wake the robot when it is asleep. If the
  // robot is already awake when the pulse is sent, it has no affect and
  // the robot will fall asleep a minute later.
  if (thisTimer - prevTimer > baudTimer) {
    prevTimer = thisTimer;
    i = 10;
    Serial.print("Sending pulse...\n");
    digitalWrite(baudPin, LOW);
    delay(500);
    digitalWrite(baudPin, HIGH);
  }

  /*
    i++;
    Serial.print(prevTimer);
    Serial.print(" --> ");
    Serial.print(thisTimer);
    Serial.print(" --> ");
    Serial.print(i);
    Serial.print("\n");
    delay(1000);
  */
}
#########################
</code>```

答:
It looks like you're trying to initialize two different baud rates:

```<code>Roomba.begin(19200);
Serial.begin(115200);
</code>```

So, first off I don't think it would work to have your setup using two different rates (though I may be wrong). But, more importantly, from the manual

By default, Roomba communicates at 115200 baud. If you are using a microcontroller that does not support 115200 baud, there are two ways to force Roomba to switch to 19200:

Method 1:

While powering off Roomba, continue to hold down the Clean/Power button after the light has turned off. After about 10 seconds, Roomba plays a tune of descending pitches. Roomba will communicate at 19200 baud until the processor loses battery power or the baud rate is explicitly changed by way of the OI.

Method 2:

Use the Baud Rate Change pin (pin 5 on the Mini-DIN connector) to change Roomba’s baud rate. After turning on Roomba, wait 2 seconds and then pulse the Baud Rate Change low three times. Each pulse should last between 50 and 500 milliseconds. Roomba will communicate at 19200 baud until the processor loses battery power or the baud rate is explicitly changed by way of the OI.

Did you put it in the 19200 mode? Have you tried 115200?

Body:
It looks like you're trying to initialize two different baud rates:

Roomba.begin(19200);
Serial.begin(115200);

So, first off I don't think it would work to have your setup using two different rates (though I may be wrong). But, more importantly, from the manual

By default, Roomba communicates at 115200 baud. If you are using a microcontroller that does not support 115200 baud, there are two ways to force Roomba to switch to 19200:

Method 1:

While powering off Roomba, continue to hold down the Clean/Power button after the light has turned off. After about 10 seconds, Roomba plays a tune of descending pitches. Roomba will communicate at 19200 baud until the processor loses battery power or the baud rate is explicitly changed by way of the OI.

Method 2:

Use the Baud Rate Change pin (pin 5 on the Mini-DIN connector) to change Roomba’s baud rate. After turning on Roomba, wait 2 seconds and then pulse the Baud Rate Change low three times. Each pulse should last between 50 and 500 milliseconds. Roomba will communicate at 19200 baud until the processor loses battery power or the baud rate is explicitly changed by way of the OI.

Did you put it in the 19200 mode? Have you tried 115200?


问:
Bldc motors erratic behavior with Arduino program
I've been making my own quadcopter flight controller using Arduino Mega. This is the sample code I wrote in order to test the esc timers and motors:

```<code>byte channelcount_1, channelcount_2, channelcount_3, channelcount_4;
int receiverinput_channel_1, receiverinput_channel_2, receiverinput_channel_3, receiverinput_channel_4, start;
unsigned long channel_timer_1, channel_timer_2, channel_timer_3, channel_timer_4, current_time, esc_looptimer;
unsigned long zero_timer, timer_1, timer_2, timer_3, timer_4;
void setup() {
  // put your setup code here, to run once:
  DDRC |= B11110000; //Setting digital pins 30,31,32,33 as output
  DDRB |= B10000000;; //Setting LED Pin 13 as output
  //Enabling Pin Change Interrupts
  PCICR |= (1 << PCIE0);
  PCMSK0 |= (1 << PCINT0); //Channel 3 PIN 52
  PCMSK0 |= (1 << PCINT1); //Channel 4 PIN 53
  PCMSK0 |= (1 << PCINT2); //Channel 2 PIN 51
  PCMSK0 |= (1 << PCINT3); //Channel 1 PIN 50
  //Wait till receiver is connected
  while (receiverinput_channel_3 < 990 || receiverinput_channel_3 > 1020 || receiverinput_channel_4 < 1400) {
    start++;
    PORTC |= B11110000;
    delayMicroseconds(1000); // 1000us pulse for esc
    PORTC &= B00001111;
    delay(3); //Wait 3 ms for next loop
    if (start == 125) { // every 125 loops i.e. 500ms
      digitalWrite(13, !(digitalRead(13))); //Change LED status
      start = 0; //Loop again
    }
  }
  start = 0;
  digitalWrite(13, LOW); //Turn off LED pin 13
  zero_timer = micros();
}
void loop() {
  // put your main code here, to run repeatedly:
  while (zero_timer + 4000 > micros());
  zero_timer = micros();
  PORTC |= B11110000;
  channel_timer_1 = receiverinput_channel_3 + zero_timer; //Time calculation for pin 33
  channel_timer_2 = receiverinput_channel_3 + zero_timer; //Time calculation for pin 32
  channel_timer_3 = receiverinput_channel_3 + zero_timer; //Time calculation for pin 31
  channel_timer_4 = receiverinput_channel_3 + zero_timer; //Time calculation for pin 30
  while (PORTC >= 16) //Execute till pins 33,32,31,30 are set low
  {
    esc_looptimer = micros();
    if (esc_looptimer >= channel_timer_1)PORTC &= B11101111; //When delay time expires, pin 33 is set low
    if (esc_looptimer >= channel_timer_2)PORTC &= B11011111; //When delay time expires, pin 32 is set low
    if (esc_looptimer >= channel_timer_3)PORTC &= B10111111; //When delay time expires, pin 31 is set low
    if (esc_looptimer >= channel_timer_4)PORTC &= B01111111; //When delay time expires, pin 30 is set low
  }
}
//Interrupt Routine PCI0 for Receiver
ISR(PCINT0_vect)
{
  current_time = micros();
  //Channel 1
  if (PINB & B00001000)
  {
    if (channelcount_1 == 0 )
    {
      channelcount_1 = 1;
      channel_timer_1 = current_time;
    }
  }
  else if (channelcount_1 == 1 )
  {
    channelcount_1 = 0;
    receiverinput_channel_1 = current_time - channel_timer_1;
  }
  //Channel 2
  if (PINB & B00000100)
  {
    if (channelcount_2 == 0 )
    {
      channelcount_2 = 1;
      channel_timer_2 = current_time;
    }
  }
  else if (channelcount_2 == 1)
  {
    channelcount_2 = 0;
    receiverinput_channel_2 = current_time - channel_timer_2;
  }

  //Channel 3
  if (PINB & B00000010)
  {
    if (channelcount_3 == 0 && PINB & B00000010)
    {
      channelcount_3 = 1;
      channel_timer_3 = current_time;
    }
  }
  else if (channelcount_3 == 1)
  {
    channelcount_3 = 0;
    receiverinput_channel_3 = current_time - channel_timer_3;
  }
  //Channel 4
  if (PINB & B00000001) {
    if (channelcount_4 == 0 )
    {
      channelcount_4 = 1;
      channel_timer_4 = current_time;
    }
  }
  else if (channelcount_4 == 1)
  {
    channelcount_4 = 0;
    receiverinput_channel_4 = current_time - channel_timer_4;
  }
}
</code>```

However, my issue here is that the bldc motors i'm using don't work smoothly when connected to the Arduino. They erratically stop and even change direction of rotation at the same throttle input. I've tested them by connecting them directly to the transmitter and they work fine there with perfect rotation and speed. Can someone please help me out and tell me where I might be going wrong?

EDIT: I do realize posting the entire Arduino code might be overkill, but I've been trying to solve this problem for three days (as of 22nd June,16) and I really do hope someone can point out any improvements/corrections in my code.

答:
Can you make a written description (comments, text, or block diagram) of what you think the code is supposed to be doing?

I can't figure out what your whole timer scheme is supposed to do. Here's what happens when you execute it, though (assuming you make it to the main loop okay):

void loop() {

So here you start a loop. By definition, it loops.

while (zero_timer + 4000 > micros());

zero_timer = micros();

Here you set a while loop based on the condition (some starting time + constant) > current time, but then on the next line you declare (some starting time) = current time. So this looks like you're setting up an infinite loop... inside the infinite loop.

PORTC |= B11110000;

You set the four output pins to ON, but then:

channel_timer_1 = receiverinput_channel_3 + zero_timer;

Here you set channel_time_N equal to receiverinput_channel_3 (note you do this for all of the channel timers - they're all set equal to channel_3) plus zero_timer. Zero timer was just set one line ago equal to the current time.

What is receiverinput_channel_3? Well, it's not initialized, so it's either whatever was in the allocated memory when the function was declared, or:

receiverinput_channel_3 = current_time - channel_timer_3, which evaluates to whatever the interrupt time step is for the first interrupt.

receiverinput_channel_3 gets locked in to the interrupt time interval. This is because it *only gets updated if channelcount_3 is equal to one. However, when you set the value for receiverinput_channel_3, you set channelcount_3 equal to zero, meaning that it never gets updated until the interrupt gets called again. At that point, if the other criteria are met, you set channel_timer_3 equal to current_time and toggle channelcount_3 again.

Now that channelcount_3 has been toggled, on the next interrupt call, you again define receiverinput_channel_3 = current_time - channel_timer_3, but channel_timer_3 was set equal to the current_time on the previous interrupt, so receiverinput_channel_3 is always equal to the interrupt interval.

So now, realizing that channel_timer_1 is set to the almost-current time (zero_timer) plus the interrupt interval (now + a very small value), we continue:

while (PORTC >= 16) {

Okay, start a loop to basically pause execution until all of the timers expire, BUT:

esc_looptimer = micros();

Set another constant equal to the now-current time, and THEN:

if (esc_looptimer >= channel_timer_1)PORTC &= B11101111;

As soon as the current time (as continuously defined by esc_looptimer) is greater than the start time outside this inner loop (zero_time) plus the interrupt interval, (channel_timer_1 as defined above), you turn the output pin off.

If you manage to hit the timing such that you invoke an interrupt before you hit the esc_looptimer >= channel_timer_1 criteria for turning the output, then you set channel_timer_1 = current_time, meaning that on the next loop iteration, you declare esc_looptimer = (current time) and then you meet the criteria and immediately turn the output off.

So, the tl;dr version of this is that you are turning your ESCs on then immediately back off, probably before the ESCs get a chance to evaluate the timing on the motors. Depending on the BLDC motors you're using, they may not have shaft position encoders ("sensorless" BLDC), meaning that:

"A stationary motor generates no back EMF, making it impossible for the microcontroller to determine the position of the motor parts at start-up. The solution is to start the motor in an open loop configuration until sufficient EMF is generated for the microcontroller to take over motor supervision. These so-called “sensorless” BLDC motors are gaining in popularity.

So you turn the ESC on, then before it has a chance to start the motor to the point it has adequate control, you turn the ESC back off again. Once all the ESCs are off you turn them back on then immediately back off again. This process repeats.

With a BLDC motor, the commutator is removed. The commutator was what had previously provided the electrical current to the correct coils at the right time. Instead, a BLDC motor relies on electronic commutation, meaning you have to sequence the coils in the correct order, at the correct time.

If you turn the ESC on and then off again before it has a chance to determine the correct timing for energizing the coil then you would get erratic behavior from the motors because they're not being controlled properly.

I really have no idea what your whole interrupt sequence is supposed to be doing, but I can pretty much guarantee it's not doing what you intended. If you just want the motor to be on for some period of time, then my suggestion would be to hard-code that run time as a constant and wait for it to elapse.

As @Jakob mentioned, the code is made more difficult to read because you're trying to control all four ESCs at once. Try getting one to work as desired first, then try to encapsulate the code for that into a function, then invoke that function for each ESC you want to run.

As a final note, I'd say that I'm dubious as to what the output of PINB & B00000100 and similar lines would evaluate to: true or false? I thought PINB was one pin - how do you AND one pin with 8? What is the output of that function?. Also, you don't appear to really initialize anything equal to zero. This means that you're stuck with whatever is in the allocated memory when the program starts - if this isn't a 1 or a 0 in your channelcount_N variables, then your code never does anything.

If you revamp the code and it still doesn't work, please post a wiring diagram showing how everything is connected. But again, as it stands I don't think your code is doing what you think it's doing.


问:
Quadcopter forward speed
I am trying to better understand the dynamics of forward flight in multirotors.

Assuming I have a quadcopter with 4 motor/propeller combinations capable (each) of a propeller pitch speed of, say, SpeedMax= 100 mph.

In forward horizontal flight, the quadcopter will pitch down at a certain angle, let's say AlphaP, from horizontal. If AlphaP is, say, 45 degrees, and drag is neglected, wouldn't the quadcopter be capable of a max theoretical speed of sin (45)* SpeedMax ~ 70Mph?

Also, seems to me AlphaP cannot go all the way to 90 degree (quadcopter flying like a plane), as at that point the propellers would not produce any  upward thrust to maintain the copter aloft given there is no wing loading as available in a plane.  If drag was to be neglected, what factors would the optimum AlphaP be depended on, and what would that angle be, for maximum speed?

答: Great question!  And, yes props develop acceleration, but neglecting friction does not mean speed is infinite, because the thrust from the prop is a function of the angle of attack which changes as speed increases.  At some angle, with maximum power applied, lift=weight and forward thrust=drag.  It's not a simple problem to solve.  At the prop tip the effective airspeed in hover is r*w (radius of prop x angular velodicy in radians/sec (RPM/10)).  In forward, tilted flight, the effective airspeed at the prop tip is the sum of the propeller speed vector, plus the relative movement of the quad at the forward tilt angle.  My point is, this is a VERY VERY complex problem to solve.  You can do it but you need to be very strong in math, geometry and maybe even calculus and Excel.  I've done calculations like this using the Iterate feature in Excel.  I broke the problem down into tiny pieces (small sections of the prop) and solved the aerodynamics for each little piece of the prop, and then added them all up for the total effect.  LOTS of work.  Best bet is probably to survey some data from quad racers in online forums and make some educated guesses from that.  Good Luck.  (BTW, I found this thread because I'm looking for exactly the same answer).  But I'm looking for it so that I can understand the difference in lift on the advancing blade versus the retreating blade.  The advancing blade sees a higher airspeed, but it also has a smaller angle of attack because the airframe is tilted forward.  Do these two effects cancel each other out?.</p>

Title: Quadcopter forward speed


问:
Connect to video stream with Java app instead of console and mplayer
I'm building a quadcopter using Raspberry Pi. There is the Pi Camera connected to the Raspberry Pi which is streaming the captured video. I can connect to this stream via Wi-Fi on my notebook (Linux) by using the console command "nc" and then show it by "mplayer".

What I want to do though is avoid the console commands and connect to this stream directly through my Java application. The reason is I want to do some image processing operations with this video so I need to have it in my application.

Is there anyone able to help me?

答:
I think this should be possible. You could still run nc on the pi side, and use a socket connection in your java application.

One important aspect is the encoding of the stream. It would probably be easiest to use mjpeg here. Mjpeg is just a concatenation of single jpeg images, and decoding jpegs is much easier than h.264 (the other alternative in the raspivid as far as I recall).

The server could e.g. be

```<code>raspivid -t 0 -w 300 -h 300 -hf -fps 20 -codec MJPEG -o - | nc -l 4000
</code>```

On the client side you could look for example at this mjpeg-viewer to get you started.

The support for MJPEG in the raspivid seems to be recent. I don't know if this will work.

Body:
I think this should be possible. You could still run nc on the pi side, and use a socket connection in your java application.

One important aspect is the encoding of the stream. It would probably be easiest to use mjpeg here. Mjpeg is just a concatenation of single jpeg images, and decoding jpegs is much easier than h.264 (the other alternative in the raspivid as far as I recall).

The server could e.g. be

raspivid -t 0 -w 300 -h 300 -hf -fps 20 -codec MJPEG -o - | nc -l 4000

On the client side you could look for example at this mjpeg-viewer to get you started.

The support for MJPEG in the raspivid seems to be recent. I don't know if this will work.


问:
What is the best way to plug in more than 3 stepper motors into a Arduino Uno board?
I'm developing a 5 axis robotic arm with stepper motors and I am getting around to ordering most of my parts. I plan on using 5 EasyDriver shields to drive all of my motors. I am also planning on using just a basic arduino uno board to go with it. So here are my questions:

Is there any alternative instead of buying a ton of Easy Drivers and connecting all of them to a single board?

And if there isn't, then how would the setup look to use more than 3 stepper motors? This is the most useful picture I found, however It only shows 3 and while I know I could plug in a 4th I am unsure whether I could plug in a 5th.

答:
There probably are boards that can handle 5 motors, but one of them is probably going to cost more than 5 of the boards you have identified.  Also when you blow a component on the big board you loose all 5 motors.  I don't know what your current requirements are but there may be smaller and cheaper boards that would do the job. (Other driver??)

In my opinion you would be better using multiple simple boards, it will make your code easier, your layout easier and leave you room to expand more easily.

I would mount your drivers on a single piece of strip board using Pins and Sockets and then bring all the connections out to an edge and use a 'ribbon cable' to hook it up to your UNO.


答: Well if i understand you question which im not sure if i do your asking how to make the copter move and the answer to that is lower the power slightly on the direction you want to move sorry for being unhelpful</p>

Title: Quadcopter forward speed

Body:
I am trying to better understand the dynamics of forward flight in multirotors.

Assuming I have a quadcopter with 4 motor/propeller combinations capable (each) of a propeller pitch speed of, say, SpeedMax= 100 mph.

In forward horizontal flight, the quadcopter will pitch down at a certain angle, let's say AlphaP, from horizontal. If AlphaP is, say, 45 degrees, and drag is neglected, wouldn't the quadcopter be capable of a max theoretical speed of sin (45)* SpeedMax ~ 70Mph?

Also, seems to me AlphaP cannot go all the way to 90 degree (quadcopter flying like a plane), as at that point the propellers would not produce any  upward thrust to maintain the copter aloft given there is no wing loading as available in a plane.  If drag was to be neglected, what factors would the optimum AlphaP be depended on, and what would that angle be, for maximum speed?


问:
Using robotic simulator for prediction step in probabilistic localization approaches
Probabilistic localization approaches like Kalman or Monte Carlo benefit from an accurate prediction step. The more accurate the prediction step, the more accurate is the belief of the robots pose. In most approaches probabilistic motion models are applied, mainly because robot dynamics are more difficult to model. Still some approaches rely on dynamic models in order to increase the accuracy.

Therefore, I was wondering if it’s reasonable to utilize a robotic simulator like V-REP or Gazebo for the prediction step. The advantages I see in doing so are the following:

the robots kinematic is solved by default, simply through modeling it in the robotic simulator

the robots dynamics are taken into account

nonlinear behaviors like slippage or collision can be modelled up to a certain extend

the robots workspace is taken into account, by modeling its environment (if the robot drives against a wall previous models would predict it behind the wall, which won’t happen in a robotic simulator)

With the shown advantages I hope to achieve a more accurate prediction.

However there might be some problems using a robotic simulator. For a start it has to ensure real time behavior and there will be delay in the prediction due to the communication with the simulator.

I was looking for some papers which pick up on that idea but couldn’t find any. Are there any approaches similar to my idea? If not, are there any reasons why nobody is using a robotic simulator for the prediction? What are your opinions about my proposal?

答:
In the probabilistic approaches that you mentioned, specifically Monte Carlo Localization (MCL), the prediction step is made based on state (pose) information and measurements. MCL relies on the Markov Assumption, which is the assumption that at each time step, the knowledge of previous time steps contains no more information than knowledge of the current state. Motion and measurement models use the state and measurement information to make the prediction; these models are similar, if not the same, as those used in simulations.

To answer your question, using a full-blown simulation environment is a very slow way of predicting the state because the underlying models are the same (motion models include the dynamics, and measurement models include sensor noise), but the computation time needed to simulate the system is greater when using the simulator. In short, nothing new is gained by using a simulation environment, and it takes longer.

Probabilistic Robotics by Sebastian Thrun gives this material very good treatment.


问:
Charging multiple LiFePO4 batteries at the same time?
I'm looking to use 4 of these 3.2V LiFePO4 batteries. I intend to have 2 pairs of 2 in series in parallel. So two 6.4V battery packs in parallel. Because my setup will be run off of this, it will also be easiest to recharge the batteries using the same setup. To accomplish this, I'm looking to charge all the batteries at once using this 6.4V LiFePO4 smart charger. From a simplistic standpoint, the resulting voltage should be correct and this should work fine. However, I know (from a previous question) that LiFePO4 battery chargers are a bit more complex then a basic voltage supply and check. Would the setup I've described work correctly? And in general, will a LiFePO4 smart charger be able to charge several batteries of the correct voltage at the same time so long as it doesn't try to charge them at too high an amperage? Or does a LiFePO4 battery also have a minimum amperage cutoff point to charge such that trying to charge more than one battery at a time will cause problems? Any other issues I didn't mention? Thank you much!</p>

答:
It sounds like you're planning to create a 2×2 configuration of individual cells, which is a common configuration:

(source: diytrade.com)

The 6.4V charger is designed for a pair of 3.2V cells in series, so you should be able to add as many parallel stacks of these as you like.  They will simply take longer to charge.

At one of my previous jobs, we had a homemade 1.5kW battery that was made of 648 (yes, six hundred and forty eight) LiPoly 18650 cells: 24 supercells in series, each cell being 27 batteries in parallel.  I do not recommend this setup.  The cells within each supercell will charge evenly because they are in parallel, but the series cells do not.  Here's an example of what the supercell charges looked like when we serviced the battery and each supercell was equally charged (ours were 3.7V min, 4.2V max):

As you can see, they mostly discharge and charge together -- you can see the point at which we plugged in the charger.  A few testing days later, one of the cells began drifting apart:

Eventually, they look like this (what it looked like before servicing):

The moral of the story is that using many cells in series doesn't guarantee even charging, because each cell has a slightly different capacity.  Using cells in parallel is better because it keeps their voltages equal.

For your particular case: if you don't charge all 4 cells in parallel, make sure that you monitor the voltage of each set of cells in the series -- one parallel pair will have a higher voltage than the other parallel pair.  Don't discharge them below the minimum rated voltage of the low pair, and don't charge them above the maximum rated voltage of the higher pair.  The difference in voltage between the two sets of cells will impact your available operating time, so it will make sense to manually balance the voltages (using 3.2V parallel charging) every so often.

ContentLicense: CC BY-SA 4.0


问:
What are the prerequisites for learning ROS?
It is helpful in robotics to first learn about "Linux kernel development" or "device driver development in Linux" before I start learning ROS? I know C and JAVA! In brief, I want to know any prerequisites which are essential to understand ROS better.</p>

答:
It sounds like you're excited to learn ROS. The best way to learn ROS well is to dive in and learn any necessary bits along the way. Once you finish going through EVERYTHING in the ROS tutorials you can tinker with a project like turtlebot.

Last but not least there is http://answers.ros.org/ for any ROS related questions you may have.

Enjoy!

EDIT

I took the route I suggested and it took me a while to learn some VERY helpful things so I want to point those out as well.

Electric, Fuerte, Groovy, Hydro, Indigo, Jade, Kinetic are all different versions of ROS from oldest (Electric) to newest (Kinetic). I personally use Hydro/Indigo because they have the most/best support in communities.

catkin is a type of ROS friendly workspace. You can build ROS in a workspace (required by some devices/distros) or you can simply do a desktop or full install of ROS.

You can learn to build URDF models from the tutorials. You can use URDF models as robots in Gazebo (mentioned by @NBCKLY). Use this to debug your robot as you can see where it thinks it is and what it thinks it is doing. You can also try throwing parts on, like a laser scanner, to see if that will help your invention.


问:
Motor Choice given size constraint and load requirement
Good day everyone :)

I am an undergraduate student working on a project involving the use of high torque small-sized DC motors for use in designing a person following trolley bag. Where in the problem is to use small sized motors but still maintain the usability and efficiency in carrying loaded luggages.

I have been looking for motors in local stores as well as in RS components as well as Element 14. However I am not sure if my choices are the right fit as I am at a loss on what specifications to look for when selecting a particular motor for this application. I have also tried to look for motors used in current products that can be used in my application such as todays electric skate boards but unfortunately have no luck on finding their suppliers.

Basically the question I would like to ask  is what specifications or calculations can I perform to select the proper motors given size constraints and weight carrying requirments. Or does anyone have suggestions on common motors that are already normally used for this application. My target maximum load capacity is 20kg.

Thank you!

答: Thanks for the suggestions guys. I'll consider your suggestions and give an update once I have chosen a motor.</p>


答:
To learn and use ROS, you do not need to know anything about Linux kernel development, and at first, you shouldn't need to worry about writing drivers. All you need to know is how to use a command line environment.

Like Jacksonkr said, the Turtlebot tutorials are pretty good. In addition, using Gazebo, you can simulate the robot without needing to have one physically, which is fantastic. Once you learn the basics, you can simulate and implement solutions to a huge number of robotics problems like SLAM.

Title: What are the prerequisites for learning ROS?

Body: It is helpful in robotics to first learn about "Linux kernel development" or "device driver development in Linux" before I start learning ROS? I know C and JAVA! In brief, I want to know any prerequisites which are essential to understand ROS better.</p>


问:
Covering Up Ultrasonic Sensor
I'm using a basic trig/echo Ultrasonic Sensor with an Arduino Uno. I get accurate readings until I cover the sensor at which point I receive very large numbers. Why is this?

Program

```<code>int trigPin = 8;
int echoPin = 9;
float pingTime;
float targetDistance;
const float speedOfSound = 776.5; // mph

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

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

}

void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2000);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(15);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(10);

  pingTime = pulseIn(echoPin, HIGH);
  pingTime /= 1000000; // microseconds to seconds
  pingTime /= 3600; // hours
  targetDistance = speedOfSound * pingTime; // miles
  targetDistance /= 2; // to from target (averaging distance)
  targetDistance *= 63360; // miles to inches

  Serial.print("distance: ");
  Serial.print(targetDistance);
  Serial.println("");

  delay(100);
}
</code>```

Example Output

I moved my hand from 10" away until I cover the sensor

```<code>10.20 distance: // my hand is 10" away from the sensor
10.01 distance:
9.51 distance:
8.71 distance:
7.85 distance:
6.90 distance:
5.20 distance:
4.76 distance:
3.44 distance:
2.97 distance:
1.65 distance:
1211.92 distance: // my hand is now pressed up against the sensor
1225.39 distance:
1197.16 distance:
1207.43 distance:
1212.66 distance:
1204.60 distance:
</code>```

EDIT

I changed the amounts from inches to milimeters to get a more precise reading. I held the sensor ~100mm from a granite counter-top and quickly lowered it until the tabletop covered the front of the sensor.

```<code>distance: 103.27 // 100mm from tabletop
distance: 96.50
distance: 79.84
distance: 76.72
distance: 62.66
distance: 65.78
distance: 54.85
distance: 47.04
distance: 44.95
distance: 38.71
distance: 28.81
distance: 25.69
distance: 27.08
distance: 25.17
distance: 27.77
distance: 22.04 // sensor continues toward table but values start to increase when they would logically decrease ??
distance: 23.95
distance: 26.73
distance: 28.81
distance: 46.52
distance: 2292.85 // sensor is now flush against tabletop
distance: 2579.59
distance: 2608.75
distance: 2595.56
distance: 2591.57
distance: 2583.75
distance: 2569.87
distance: 2570.91
distance: 2600.07
distance: 30579.64 // extreme high & low values with sensor is same place against tabletop
distance: 37.66
distance: 30444.43
distance: 37.66
distance: 30674.23
distance: 38.71
</code>```

答:
You should consider building a measurement model for your sensor--this will enable you to use your measurements in an effective probabilistic manner. The problem is that beam sensors are noisy, ultrasonic sensors especially so; furthermore, this sensor noise is not typically uniformly distributed.

Sebastian Thrun covers this topic quite well in Chapter 6 of Probabilistic Robotics, in fact, he considers an ultrasonic sensor explicitly. Thrun suggests that the probability distribution of measurements is combination of four different distributions characterized by beam sensor response.

The image above shows the four distributions and is taken from Thrun's text. The upper left is a Gaussian distribution centered on the ground truth distance. The upper right is a truncated exponentially decaying distribution for measurements that are too close to the sensor. The bottom graphs depict the uniform noise of the sensor and the max value measurement. These four distributions are combined and normalized to give a single measurement model; to do this properly, you need to build a model for every distance.

There are two takeaway points:

Ultrasonic sensors are noisy/not accurate, so you probably aren't doing anything wrong; it looks like you found the minimum sensing distance of the sensor

You need measurement models to inform your predictions about the robot's pose, which is important for things like control and navigation

Title: Covering Up Ultrasonic Sensor


答:
You said it yourself: you're using an echo-based ultrasonic sensor.

Imagine this: you are a sensor looking at a piece of fiber optic cable. From far enough away, you see the cable as an object. You can determine how far away it is because you are looking at it.

The cable gets closer and you continue looking at the object until, at some point, it becomes coupled to you and you now begin to look through the cable.

I would imagine the same thing is happening with your hand. In time of flight sensors there's usually some "turn on" time that delays turning on the receiver to prevent the transmitter from directly driving the receiver. This turn on time corresponds with some minimum distance, inside which an object cannot be detected.

At your skin there is an interface, where some of the sound is reflected and some of the sound is absorbed. This is like a window or a two-way mirror. Depending on some properties (acoustic impedance mismatch), the percentage of sound energy that gets absorbed varies, but some always gets absorbed.

So, your hand gets closer, and the sensor sees your hand as an object. At some point you pass the minimum threshold, and the sensor no longer detects the reflection at the air/skin interface. It still listens for an echo, though, but now all the remaining sound energy is inside you.

You are now akin to a (crappy) fiber optic cable - the sound is free to bounce around inside you, reflecting off of whatever doesn't have the same acoustic impedance as your skin. Every time it hits an interface (skin/muscle, muscle/bone, etc.), some energy is absorbed and some is reflected. This is exactly how a medical ultrasound works.

At some point the sound waves scatter back to the point where they entered, and pass back through your skin and that's when the echo is recorded. The scattered path length is the distance you are seeing.

I would bet the value would change based on what part of your arm you use (not that I would recommend doing it).

Also,  FYI, ultrasound jelly exists to help match acoustic impedances to minimize reflection and get more sound energy into the body.

Title: Covering Up Ultrasonic Sensor

Body:
I'm using a basic trig/echo Ultrasonic Sensor with an Arduino Uno. I get accurate readings until I cover the sensor at which point I receive very large numbers. Why is this?

Program

```<code>int trigPin = 8;
int echoPin = 9;
float pingTime;
float targetDistance;
const float speedOfSound = 776.5; // mph

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

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

}

void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2000);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(15);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(10);

  pingTime = pulseIn(echoPin, HIGH);
  pingTime /= 1000000; // microseconds to seconds
  pingTime /= 3600; // hours
  targetDistance = speedOfSound * pingTime; // miles
  targetDistance /= 2; // to from target (averaging distance)
  targetDistance *= 63360; // miles to inches

  Serial.print("distance: ");
  Serial.print(targetDistance);
  Serial.println("");

  delay(100);
}
</code>```

Example Output

I moved my hand from 10" away until I cover the sensor

```<code>10.20 distance: // my hand is 10" away from the sensor
10.01 distance:
9.51 distance:
8.71 distance:
7.85 distance:
6.90 distance:
5.20 distance:
4.76 distance:
3.44 distance:
2.97 distance:
1.65 distance:
1211.92 distance: // my hand is now pressed up against the sensor
1225.39 distance:
1197.16 distance:
1207.43 distance:
1212.66 distance:
1204.60 distance:
</code>```

EDIT

I changed the amounts from inches to milimeters to get a more precise reading. I held the sensor ~100mm from a granite counter-top and quickly lowered it until the tabletop covered the front of the sensor.

```<code>distance: 103.27 // 100mm from tabletop
distance: 96.50
distance: 79.84
distance: 76.72
distance: 62.66
distance: 65.78
distance: 54.85
distance: 47.04
distance: 44.95
distance: 38.71
distance: 28.81
distance: 25.69
distance: 27.08
distance: 25.17
distance: 27.77
distance: 22.04 // sensor continues toward table but values start to increase when they would logically decrease ??
distance: 23.95
distance: 26.73
distance: 28.81
distance: 46.52
distance: 2292.85 // sensor is now flush against tabletop
distance: 2579.59
distance: 2608.75
distance: 2595.56
distance: 2591.57
distance: 2583.75
distance: 2569.87
distance: 2570.91
distance: 2600.07
distance: 30579.64 // extreme high & low values with sensor is same place against tabletop
distance: 37.66
distance: 30444.43
distance: 37.66
distance: 30674.23
distance: 38.71
</code>```


问:
Switch activated by a microcontroller
I'm working on a project where I'm using a voltage that is higher than what most microcontrollers can handle. I'm looking for a kind of switch that will connect a power source to an electromagnet and all of this controlled by my microcontroller. I also thought about using a potentiometer to control the speed of two high voltage DC motors via my microcontroller so please tell me if this is a good idea aswell.

Thanks for your time

Zakary

答:
You can use a relay for the switch. Relays typically have 4 pins: 2 are the switch, and the other 2 control the switch. For reed relays, the switch is a small metal reed (normally closed) that makes contact when an internal electromagnetic coil is powered.

You have to pick the right relay so that your microcontroller can supply sufficient current to controlling pins of the relay. You also need to make sure that the switch of the relay can handle the current flowing from your power source to the electromagnet.

For the motors, consider getting a separate motor control board, which will isolate your microcontroller from the motors and allow you to control their velocity with PWM--you can then use the potentiometer to set the specific PWM duty cycle to control the motors.

Title: Switch activated by a microcontroller