问:
iRobot Create Serial Cable for Turtlebot I
I need an iRobot Create Serial Cable (one end 7-pin Mini-DIN Connector and the other end is USB) for Turtlebot I.  How can I connect my bot to my PC?</p>

答:
The iRobot Create and Roomba may have a rather unusual 7-pin mini-din socket for their serial interface, but it is otherwise a fairly standard 5v serial port.

Since the original iRobot Create cable no longer seems to be available, if you already have a USB serial adapter and don't want to buy the new iRobot Create 2 cable, then you may want to make your own RS232 iRobot Create cable.

It is fairly easy to create your own serial to roomba adapter with a standard RS232 cable, an 8-pin mini-din cable (the middle pin is just ignored), a MAX232 RS-232 transceiver IC, a 78L05 voltage regulator, an LED, a resistor and a few capacitors.

You can connect it all together with a small piece of prototyping board, and some basic electronics tools.

Once you have your Roomba serial to RS-232 cable, you just need to add a standard off the shelf USB to RS-232 adapter/cable to complete your connection.


问:
Can RC servo motors continually rotate?
I know that RC servo motors are designed for precise movement, rather than a D.C. motor's continual rotation. Are most RC servo motors limited to movement within one rotation or can they actually be made to continually rotate? That is to say, is their movement limited to a specific arc? Or does it depend on the type of RC servo motor?

I have seen videos of industrial size steppers rotating constantly, but, more specifically, I was wondering whether a MG995 can.

I don't own any RC servo motors yet, so I can't actually test it myself. I just want to make sure before I make a purchase. I keep seeing conflicting information, for example the instructable, How to modify a RC servo motor for continuous rotation (One motor walker robot), implies that a RC servo motor will not continually rotate, else otherwise, why would there be a need to modify it?

Addendum

I have just realised, after further digging about on google, and as HighVoltage points out in their answer, that I have confused steppers and servos.

In addition, I found out how to hack the TowerPro MG995 Servo for continuous rotation.

答:
Whether a motor can spin continuously depends how is is constrained by other parts of the system.

An rc servo like the MG995 will typically have a motor, a gearbox and a limited travel potentiometer to provide position feedback. It is this final component which prevents the rc-servo from rotating continuously. In the case of the MG995, it can apparently be purchased with 180 or 360 degree rotation for robotics applications.

If you remove this constraint, there may still be other constraints. If your motor is controlling the movement of a robot arm for instance, it may be constrained by mechanical end-stops on the joints, or cabling.

I once worked for a company which created a robot for de-heading fish, this had a shoulder joint which could rotate continuously, picking up each fish from one conveyor, orienting it correctly, presenting it to the cutting discs, dropping the de-headed fish onto another conveyor and then swinging around to pick up the next fish.

In order to get electrical power and control signals to the joints further down the kinematic chain, it used slip rings on the shoulder joint with some fancy power smoothing and signal correction techniques (slip rings are electrically very noisy).

ContentLicense: CC BY-SA 3.0

Title: Can RC servo motors continually rotate?


问:
Wiring & driving TowerPro SG90 servos
I got my hands on a few Tower Pro SG90 9G servos but cannot find their schematics or datasheet anywhere (besides that link).

I have the following concerns:

Looks like they're rated for 4.8V, but will they tolerate a 5V supply?

How do I determine the current they require, in amps, mA, etc.?

There's 3 wires: brown, red & yellow-orange, what do each of these guys do?

If I had to guess I'd say that red is power, another one is direction, and another one is the position to rotate to

答:
According to this datasheet(1), the red and brown wires are power and ground, while the orange wire is the PWM control (as Vinokanth Velu suggested).

The PWM line expects a pulse every 20ms. If the pulse is 1.5ms wide, the SG90 will move towards the midpoint of its 180 degree travel (position 0). If the pulse is 2ms, then it will move all the way to the right (position 90), while a pulse of 1ms, will move it all the way to the left (position -90).

The deadband determines the minimum move you can specify, 10us (as suggested by this datasheet) would be around 1.8 degrees, 1us (as the manufacturer specifies) would be 0.18 degrees.

As for how much power it will draw, that depends on what you are asking it to do. Holding position with no force will take very little power, swinging from one extreme to the other and back with the full 1.80 kg-cm force would take significantly more.

Title: Wiring & driving TowerPro SG90 servos


答:
The new Create2 cable should work with old Creates and all versions of Roomba.  You can purchase one at the iRobot web store.  And here are instructions how to make a cable yourself using an FTDI serial to USB converter.

Please also see www.irobot.com/create for more Roomba and Create hacks.

Title: iRobot Create Serial Cable for Turtlebot I

Body: I need an iRobot Create Serial Cable (one end 7-pin Mini-DIN Connector and the other end is USB) for Turtlebot I.  How can I connect my bot to my PC?</p>


问:
Building a controllable "knob"
I am trying to build a semi-analog timer. Something like those old egg timers that you rotate the face of. I want a knob that I can turn that can be read by a microcontroller, and I also want the microcontroller to be able to position the knob. I'd like to implement "stops" by letting the microcontroller push the knob towards certain positions. As it runs down, the knob should turn. This is my first project of this kind; I've built small robots in the past, but it's been many years.

I've considered hacking a servo motor to read its position, but the small hobby servos I've tried are too hard to turn, very noisy, and pick up too much momentum when turned. They don't act like a good knob.

I'm now considering a rotary encoder connected to a motor, but after hunting at several sites (SparkFun, ServoCity, DigiKey, Trossen, and some others), I haven't been able to find anything that seemed appropriate. I'm not certain how to find a motor that's going to have the right kind of low torque.

This seems like it shouldn't be a really uncommon problem. Is there a fairly normal approach to creating a knob that can be adjusted both by the user and a microcontroller?

答: How about using a stepper motor, you will be able to control the position exactly.

Title: Building a controllable "knob"


问:
Simple Sensor Fusion for pose estimation
I am currently working on a balancing robot project, which features fairly low-cost sensors such as an 9-Dof IMU with the measurement states

$\textbf{x}_\text{IMU} = \left[a_x, a_y, a_z, g_x, g_y, g_z, m_x,m_y,m_z \right]^\text{T}$.

Currently I use the accelerometer and gyroscope readings, fused by a complimentary filter to get the angular deviation of the robot's upright (stable) position. The magnetometer values are tilt-compensated and yield the robots orientation with respect to the earth-magnetic field (awful when close to magnetic distortion). Furthermore I have pretty decent rotational encoders mounted on the wheels which deliver information on a wheel's velocity.

$\textbf{x}_\text{ENC} = \left[v_l,v_r\right]^\text{T}$.

Given these measurements i want to try to get the robots pose (position + heading).

$\textbf{x}_\text{ROB} = \left[x,y,\theta\right]^\text{T}$

I do have minor theoretical knowledge on EKF or KF, but it is not sufficient for me to actually derive a practical implementation. Note that my computational resources are fairly limited (Raspberry Pi B+ with RTOS) and that I want to avoid using ROS or any other non-std libs. Can anybody help me on how to actually approach this kind of problem?

答:
So you have acceleration readings from your IMU (linear and angular), and you get velocity readings (linear only) from wheel encoders.

Get velocity from linear and angular accelerations with

$$
v = v + a*\mbox{dT}
$$

Get angular velocity from your wheel encoders by exploiting geometry of the vehicle

$$
\dot{\theta} = \mbox{atan2}((v_r - v_l) , \mbox{wheel base})
$$

Now you have two sources of linear and angular velocities - the IMU and the wheel encoders. Get to linear and angular positions with

$$
x = x + v*\mbox{dT}
$$

Here I've used $x$ but of course it's just a variable to use for whatever position you're interested in using.

Now you have heading and position from the IMU (via linear x and y accelerations and the z gyro), you have heading and position from the wheel encoders, and heading via the magnetometer.

I would suggest filtering IMU outputs before integration, but you can use whatever filter you want - lag, Kalman, or something more complicated. If computational simplicity is a priority I would highly suggest you check out the lag filter. It's basically a complimentary filter using the current sample and previous sample instead of two different sensors.

Finally, you can fuse the sensor readings with the complimentary filter. I don't think I can advise you as to which input you should place more emphasis because that will depend primarily on wheel slip (how much you "trust" the wheel encoder).


问:
Simulation environment for conducting visual servoing experiment
I want to conduct the following experiment:
I want to set up a scene with a kuka lwr4+ arm, a 3D model of an object and a camera overlooking them. I want to find the pose of the object using some pose estimation algorithm and move the arm towards the object.
In general I want a piece of software or a combination of cooperating software that can do all that without having to reinvent the wheel. Is there anything available?</p>

答: You could consider taking a look at Gazebo Robotic Simulation and the Robot Operating System. Both might require a bunch of work getting used to, but I am sure it is worth the effort.</p>


问:
What commands make the irobot create 2 go left and right not just forwards and backwards?
I am new to the create 2 and I downloaded real term to program, opened an interface to the robot and send numbers with it to the robot.

I can only get the drive command to work. I only know how to make the robot go faster, turning around or slower.

I would like to know how to make the other commands work along with making it go left and right.

答:
The documentation states on page 12:

A Drive command with a
  positive velocity and a positive radius makes Room
  ba drive forward while turning toward the left.  A
  negative radius makes Roomba turn toward the right.
   Special cases for the radius make Roomba turn in
  place or drive straight, as specified below

The radius value is documented this way:

Radius (-2000 – 2000 mm)

Special cases:

Straight = 32768 or 32767 = 0x8000 or 0x7FFF

Turn in place clockwise = -1 = 0xFFFF

Turn in place counter-clockwise = 1 = 0x0001

Obviously supply different values if you are not trying to achieve any of those special cases, like in the example that follows:

Example:

To drive in reverse at a velocity of -200 mm/s while
   turning at a radius of 500mm, send the following
  serial byte sequence:

[137] [255] [56] [1] [244]

Explanation:

Desired value -> two’s complement and convert to hex -> split into 2 bytes ->
   convert to decimal

Velocity = -200 = 0xFF38 = [0xFF] [0x38] = [255] [56]

Radius = 500 = 0x01F4 = [0x01] [0xF4] = [1] [244]


问:
Forward kinematics: Why ω should remain same?
Can anyone please explain me these lines found on page 5 of
Kinematics Equations for Differential Drive and Articulated Steering
by Thomas Hellström?

Note that plugging in $r$ and $v$ for both left and right wheel result in the same $\omega $ (otherwise the wheels would move relative to each other). Hence, the following equations hold:

$$
\begin{align}
\omega~ \left(R+\frac{l}{2}\right) &= v_r\\
\omega~ \left(R-\frac{l}{2}\right) &= v_l\\
\end{align}$$

where $R$ is the distance between ICC and the midpoint of the wheel axis, and $l$ is the
  length of the wheel axis (see Figure 6).

Figure
  6
  .
  When left and right wheel rotate with different speeds, the robot rotates around
  a common point denoted ICC
  My questions are:

How do these equations come to be?

Why does $\omega$ have to be same if we want to analyse the behavior after changing the wheel velocity relative to other?

How do we know about the circle, in which the robot rotates by doing variations in one wheel velocity, surely passes through the center point between two wheels.

答:
Recall that for a circle with radius $r$, the circumference $u$ (that is the arc length of the "curve") is given as:

$$u = 2 \pi r$$

Further recall the definition or radians, which is something along the lines of:

If a rope of length $r$ is placed on the circumference of a circle
  that has the radius $r$, the rope will "cover" a certain angle. This
  angle is 1 radian.

The following awesome animation from the wikipedia article on radian covers this better than my words:

You can now see how both are somewhat similar:
If you multiply the angle $1 rad$ with $2\pi $, you also get a rope length of $2\pi r$. Now this rope length is exactly the same as $u$.

We can therefore conclude:

The $2\pi$ in the formula for the circumference $u=2\pi r$ corresponds to the covered angle of the circle. A full circle is $360°$, which is equivalent to $2\pi $. Let's call this angle $\omega$ and write the formula again, with that angle:

$$u = \omega r$$

The wikipedia article about the arc length of a circle comes to the same conclusion.

You can calculate any arc length given any angle. For example, half a circle, with an angle of $180° = \pi $ has (obviously) half the circumference:

$$\frac{u}{2} = \frac{\omega}{2} r$$

Or one third of a circle has this circumference:

$$\frac{u}{3} = \frac{\omega}{3} r$$

I mixed the terms circumference and arc length within my answer on purpose. If you think of the circumference as a length you can imagine that it's a distance that you can walk along. More precisely: drive along, because your robot has wheels.

Each wheel covers a certain distance, $v_r$ and $v_l$ respectively.

If $v_r \neq v_l$, the robot moves on a circle as seen in your image, with center $ICC$ and radius $R$. Each wheel is on its own circle with a different radius:

the left wheel is closer to $ICC$, which means it has a smaller radius $R-\frac{I}{2}$

the right wheel is further away from $ICC$, which means it has a bigger radius $R+\frac{I}{2}$

If the robot drives around in that circle with center $ICC$ and radius $R$ by an angle of $\omega $, the relationship between the distances travelled by each wheel are the formulas that you found in the book:

$$
\begin{align}
\omega~ \left(R+\frac{l}{2}\right) &= v_r\\
\omega~ \left(R-\frac{l}{2}\right) &= v_l\\
\end{align}$$

$v_r$ and $v_l$ are the arc lengths of the circle that the wheels are driving on and $\omega$ is the angle that the robot goes around the circle.

The important thing to understand:
The circle is just a geometric aid to describe the motion of the robot, which exists because it's easier to handle and understand. It's really just another way to describe $v_r$ and $v_l$, but those two values are hard to imagine and depending on the wheelbase $l$, they could describe different motions.

If I give you $v_r = 5$, $v_l = 6$ and $l = 3$, can you easily answer the question whether the robot can do a full turn in a 50 x 50 room? It's kind of hard to tell. But if you had $R$, it's a lot easier.

Thinking in terms of a circle is a lot easier than to construct the motion from $v_r$ and $v_l$.

Why ω has to be same if we want to analyse the behavior after changing the wheel velocity relative to other?

I think you are misunderstanding the text in the book. The book says that $\omega$ is the same for both wheels, given two values for $v_r$ and $v_l$. Of course, if you change the values of $v_r$ and $v_l$, you will get a different value for $\omega$, but $\omega$ will still be the same for both wheels.

How do we know about the circle, in which the robot rotates by doing variations in one wheel velocity, surely passes through the center point between two wheels.

Because that's the way the geometry works out. Both wheels are on circles with different radii ($R\pm \frac{I}{2}$) with the came center $ICC$, but they have a fixed relation to each other, so the center of the robot must be on a circle with radius $R$.

Just imagine you are in a car driving in a roundabout. If the left side of the car is going in a circle and the right side is going in a circle, why do you think are you not going in a circle? Of course you do. And so does the center of the robot.


问:
How to determine x-axis if the two z-axis are intersecting in Denavit Hartenberg representation
Suppose I have a 3 link(1 dimensional) chain in which all the joints are revolutes, the axis of first revolute joint is along Z-axis(global) and axis of second joint is along X-axis(global). The first link is along X-axis(global) and second link is along Z-axis(global).

Now in order to use DH representation I introduced a local frame for link 1 at joint 1(z axis along Z and x axis along X) and another frame at joint 2.Here z-axis is along axis of rotation(global X) and here I am clueless how to determine x-axis for joint 2 because the two z axis are intersecting.(standard procedure is to find common normal between two z axis)
Thanks for your time.

答:
Check out this tutorial video on DH Parameters - it's amazing!.

Regarding your question, I believe if you try crossing your z-axes, $z_1 \times z_2$, you'll get the x-axis you're looking for (orthogonal to both axes). Because the two z axes intersect, your $r$ or $a$ value, depending on your notation, will be zero because the new x-axis lies on your previous z-axis.


问:
How do I dispense a greasy fluid?
I'm a agricultural engineering student and complete newbie trying to build a simple mechanism attached to a drone that dispenses a grease-type fluid. However, since I'm not familiar with the field, I'm having a hard time googling because I don't know the correct terms to search for.

I'm looking for a mechanism that will remotely push the grease out. The problem is carrying the necessary weight for an hectare (300g to 1,5kg of fluid) and the dispenser mechanism within the drone. So I'm looking for a lightweight dispenser mechanism capable of deliver small amounts of this fluid (3g) distributed on the trees canopy. The grease do not need to be heated as it flows naturally in normal temperatures (like a toothpaste). Both pump or syringe-type arrangement would be fine as long as I can control it remotely.

答:
It is difficult to answer your question without more details, but there are a number of design options for pumps, the two most obvious being the Metering pump and the Peristaltic pump.

A Metering pump delivers precise amounts of fluid, but relies on seals which may require ongoing maintenance:

Peristaltic pump is more appropriate for a more continuously pumped fluid, but where metered flow might be needed. It does require your fluid to be appropriate for the flexible pipe needed to make it however:

Title: How do I dispense a greasy fluid?


问:
Preventing leaks in motor shafts for underwater bots
Whenever building an aquatic bot, we always have to take care to prevent leakages, for obvious reasons. Now, holes for wires can be made watertight easily--but what about motors? We can easily seal the casing in place (and fill in any holes in the casing), but the part where the axle meets the casing is still left unprotected.

Water leaking into the motor is still quite bad. I doubt there's any way to seal up this area properly, since any solid seal will not let the axle move, and any liquid seal (or something like grease) will rub off eventually.

I was thinking of putting a second casing around the motor, maybe with a custom rubber orifice for the shaft. Something like (forgive the bad drawing, not used to GIMP):

This would probably stop leakage, but would reduce the torque/rpm significantly via friction.

So, how does one prevent water from leaking into a motor without significantly affecting the motor's performance?

(To clarify, I don't want to buy a special underwater motor, I'd prefer a way to make my own motors watertight)

答:
I wanted to create a submerged water pump as part of school science project. I really had a hard time in making a normal DC motor and its shaft in making water proof. i failed miserably.
Later i came with an idea. I removed the shaft and magnets from the motor . i removed the coil and attached magnet in the shaft. use a small pvc pipe piece and coil it. keep the shaft inside the coiled pvc pipe. Now when you pass AC current in the coil the shaft will rotate. So now you dont have to water proof the rotating shaft but the wire holes made in the wall which is very easy.

Now coils are water proof and shaft doesnt have any coil and electric circuit to get short. just magnectic field under water.


问:
Do "nano bots" (that can fit inside the human body) actually exist?
I was wondering, do we have real nano bots, like the ones in the movies?

I think we have bots which can move through the blood vessels, am I right?

答:
Movement of Artificial Bacterial Flagella in Heterogeneous Viscous
Environments at the Microscale† is a recent article from ETH Zürich that discusses the movement possibilities of an artificial bacteria in the blood stream or in the eye. Swim tests were performed in different methyl cellulose concentrations.

I do not think so that such methods can be used in human body in the near future because of the existing technological constraints.

It is still not clear how to

create such small machines from non-allergic material

with effective motors

and small battery storing enough energy for the duration of the job

that can move inside the body without making any
harm e.g. blocking the blood stream

and that can deliberately move to the planned location

recognize the destination

and perform its job there

and finally that could leave the body after the job is done,

all reliable and stoppable if necessary, even with the possibility to track
the progress.

† by Kathrin E. Peyer, Famin Qiu, Li Zhang, and Bradley J. Nelson (978-1-4673-1735-1/12/S31.00 ©2012 IEEE)


问:
Forward kinematics of constrained double pendulum
I was wondering whether maybe you could help me with this problem. I have a double pendulum. I have set the origin of cartesian coordinates to be the "head" of the first arm, which is fixed. The end of the second arm is attached to a block that slides along the x-axis. What I want to do is to derive the equations relating the pendulum's angles with the distance from the origin to the block.

Now, I know how I could go about deriving the equations without the constraint.

$$x_1 = L_1cos(a_1)$$
$$y_1 = L_1sin(a_1)$$

Where $x_1$ and $y_1$ is where the first arm joins the second arm and $a_1$ is the angle between the horizontal and the first arm.

Similarly, I can derive the equations for the end of the second arm
$x_2 = x_1 + L_2 cos(a_2)$ and $y_2 = y_1 - L_2 sin(a_2)$

Now then, if I attach a sliding block to the end of my second arm, I don't know whether my equation for $x_2$ would change at all. I don't think it would but  would I have to somehow restrict the swing angles so that the block only moves along the x direction?

Well, basically the problem is finding the equation of $x_2$ if it's attached to a block that only moves along the x- direction.

答:
What you are describing is a crankshaft.

if I attach a sliding block to the end of my second arm, I don't know whether my equation for $x_2$ would change at all.

No it wouldn't, because your restraint:

the second arm is attached to a block that slides along the x-axis

doesn't restrain $x_2$ but $y_2$

"Being on the x axis" basically means $y = 0$, which in your case means $y_2 = 0$, which is where you "lose" the second degree of freedom.

Take a look at the following image:

The formula for the relation between $x$ and $\varphi$ in the image is:

$$x=l_1\cos \varphi + l_2 \sqrt{1-\left(\frac{l_1}{l_2}\right)^2 \sin^2 \varphi}$$

To get there:

use the Pythagorean theorem for the second summand in the formula
for $x_2$ instead of trigonometry

replace $y_1$ with its definition

$$
\begin{align}
x_2 &= x_1 +  \sqrt{l_2^2 - \underset{\overbrace{l_1\sin\varphi}}{y_1^2}}\\
\end{align}$$

The relationship between the two angles can be derived from their shared opposite side in their respective triangles:

$$l_1\sin a_1 = l_2\sin a_2$$
$$ a_1 = \arcsin \left(\frac{l_2}{l_1}\sin a_2\right)$$


问:
How can I get the values of a IMU from the serial message received in Simulink via UART?
I try to read IMU sensor data from an Arduino mega 2560 UART with serial receive block of Arduino support package for simulink. The IMU can send binary packets and also nmea packets and I can configure it to any output. When the serial recieve block output is directly used, it displays just the numbers between 0-255. l need help about how to parse the coming data which contains the euler angles that I want to use.

Here is binary structure ;

"s","n","p",packet type(PT),Address,Data Bytes (D0...DN-1),Checksum 1,Checksum 0

The PT byte specifies whether the packet is a read or a write operation, whether it is a batch operation, and the length of the batch operation (when applicable). The PT byte is also used by the UM7 to respond to commands. The specific meaning of each bit in the PT byte is given below.

Packet Type (PT) byte;

7 Has Data,
6 Is Batch,
5 BL3,
4 BL2,
3 BL1,
2 BL0,
1 Hidden,
0 CF

Packet Type (PT) Bit Descriptions;

7...Has Data: If the packet contains data, this bit is set (1). If not, this bit is cleared (0).

6...Is Batch: If the packet is a batch operation, this bit is set (1). If not, this bit is cleared (0)

5:2..Batch Length (BL): Four bits specifying the length of the batch operation. Unused if bit 7 is cleared. The maximum batch length is therefore 2^4 = 16

1...Hidden: If set, then the packet address specified in the “Address” field is a “hidden” address. Hidden registers are used to store factory calibration and filter tuning coefficients that do not typically need to be viewed or modified by the user. This bit should always be set to 0 to avoid altering factory configuration.

0...Command Failed (CF): Used by the autopilot to report when a command has failed. Must be set to zero for all packets written to the UM7.

The address byte specifies which register will be involved in the operation. During a read operation (Has Data = 0), the address specifies which register to read. During a write operation (Has Data = 1), the address specifies where to place the data contained in the data section of the packet. For a batch read/write operation, the address byte specifies the starting address of the operation.
The "Data Bytes" section of the packet contains data to be written to one or more registers. There is no byte in the packet that explicitly states how many bytes are in this section because it is possible to determine the number of data bytes that should be in the packet by evaluating the PT byte.
If the Has Data bit in the PT byte is cleared (Has Data = 0), then there are no data bytes in the packet and the Checksum immediately follows the address. If, on the other hand, the Has Data bit is set (Has Data = 1) then the number of bytes in the data section depends on the value of the Is Batch and Batch Length portions of the PT byte.
For a batch operation (Is Batch = 1), the length of the packet data section is equal to 4*(Batch Length). Note that the batch length refers to the number of registers in the batch, NOT the number of bytes. Registers are 4 bytes long.
For a non-batch operation (Is Batch = 0), the length of the data section is equal to 4 bytes (one register). The data section lengths and total packet lengths for different PT configurations are shown below.
The two checksum bytes consist of the unsigned 16-bit sum of all preceding bytes in the packet, including the packet header.

Read Operations;

To initiate a serial read of one or more registers aboard the sensor, a packet should be sent to the UM7 with the "Has Data" bit cleared. This tells the device that this will be a read operation from the address specified in the packet's "Address" byte. If the "Is Batch" bit is set, then the packet will trigger a batch read in which the "Address" byte specifies the address of the first register to be read.
In response to a read packet, the UM7 will send a packet in which the "Has Data" bit is set, and the "Is Batch" and "Batch Length" bits are equivalent to those of the packet that triggered the read operation. The register data will be contained in the "Data Bytes" section of the packet.

here is an Example Binary Communication Code;

```<code>{
uint8_t Address;
uint8_t PT;
uint16_t Checksum;
uint8_t data_length;
uint8_t data[30];
}
UM7_packet;
// parse_serial_data.This function parses the data in ‘rx_data’ with length ‘rx_length’ and attempts to find a packet in the data. If a packet is found, the structure ‘packet’ is filled with the packet data.If there is not enough data for a full packet in the provided array, parse_serial_data returns 1. If there is enough data, but no packet header was found, parse_serial_data returns 2.If a packet header was found, but there was insufficient data to parse the whole packet,then parse_serial_data returns 3. This could happen if not all of the serial data has been received when parse_serial_data is called.If a packet was received, but the checksum was bad, parse_serial_data returns 4. If a good packet was received, parse_serial_data fills the UM7_packet structure and returns 0.

uint8_t parse_serial_data( uint8_t* rx_data, uint8_t rx_length, UM7_packet* packet )
{
uint8_t index;
// Make sure that the data buffer provided is long enough to contain a full packet The minimum packet length is 7 bytes
if( rx_length < 7 )
  {
  return 1;
  }
// Try to find the ‘snp’ start sequence for the packet
for( index = 0; index < (rx_length – 2); index++ )
  {
  // Check for ‘snp’. If found, immediately exit the loop
  if( rx_data[index] == ‘s’ && rx_data[index+1] == ‘n’ && rx_data[index+2] == ‘p’ )
    {
    break;
    }
  }
uint8_t packet_index = index;
// Check to see if the variable ‘packet_index’ is equal to (rx_length - 2). If it is, then the above loop executed to completion and never found a packet header.
if( packet_index == (rx_length – 2) )
  {
  return 2;
  }
// If we get here, a packet header was found. Now check to see if we have enough room left in the buffer to contain a full packet. Note that at this point, the variable ‘packet_index’contains the location of the ‘s’ character in the buffer (the first byte in the header)
if( (rx_length – packet_index) < 7 )
  {
  return 3;
  }
// We’ve found a packet header, and there is enough space left in the buffer for at least the smallest allowable packet length (7 bytes). Pull out the packet type byte to determine the actual length of this packet
uint8_t PT = rx_data[packet_index + 3];
// Do some bit-level manipulation to determine if the packet contains data and if it is a batch.We have to do this because the individual bits in the PT byte specify the contents of the packet.
uint8_t packet_has_data = (PT >> 7) & 0x01; // Check bit 7 (HAS_DATA)
uint8_t packet_is_batch = (PT >> 6) & 0x01; // Check bit 6 (IS_BATCH)
uint8_t batch_length = (PT >> 2) & 0x0F; // Extract the batch length (bits 2 through 5)
// Now finally figure out the actual packet length
uint8_t data_length = 0;
if( packet_has_data )
  {
  if( packet_is_batch )
    {
    // Packet has data and is a batch. This means it contains ‘batch_length' registers, each // of which has a length of 4 bytes
    data_length = 4*batch_length;
    }
  else // Packet has data but is not a batch. This means it contains one register (4 bytes)
    {
    data_length = 4;
    }
  }
else // Packet has no data
  {
  data_length = 0;
  }
// At this point, we know exactly how long the packet is. Now we can check to make sure we have enough data for the full packet.
if( (rx_length – packet_index) < (data_length + 5) )
  {
  return 3;
  }
// If we get here, we know that we have a full packet in the buffer. All that remains is to pullout the data and make sure the checksum is good. Start by extracting all the data
packet->Address = rx_data[packet_index + 4];
packet->PT = PT;
// Get the data bytes and compute the checksum all in one step
packet->data_length = data_length;
uint16_t computed_checksum = ‘s’ + ‘n’ + ‘p’ + packet_data->PT + packet_data->Address;
for( index = 0; index < data_length; index++ )
  {
  // Copy the data into the packet structure’s data array
  packet->data[index] = rx_data[packet_index + 5 + index];
  // Add the new byte to the checksum
  computed_checksum += packet->data[index];
  }
// Now see if our computed checksum matches the received checksum
// First extract the checksum from the packet
uint16_t received_checksum = (rx_data[packet_index + 5 + data_length] << 8);
received_checksum |= rx_data[packet_index + 6 + data_length];
// Now check to see if they don’t match
if( received_checksum != computed_checksum )
  {
  return 4;
  }
// At this point, we’ve received a full packet with a good checksum. It is already fully parsed and copied to the ‘packet’ structure, so return 0 to indicate that a packet was processed.
return 0;
}
</code>```

答:
I think there are two issues here - one is that you are referring to your IMU as though you were communicating with it, but in reality you are communicating with the Arduino, not the IMU.

The packet structure has nothing to do with the fact that you are seeing numbers between 0-255 because those numbers appear with communication between the Arduino and Simulink, not between the IMU and the Arduino.

The Simulink block only reads one byte - you need to concatenate/parse the data coming back from that block instead of just displaying the data as though it were a uint8 format.

:EDIT:

I use Matlab (command-line scripting) and not Simulink, so I can't say for sure if Simulink does or does not have a parse block, but all serial packets are different so that, coupled with the fact that I didn't see anything after a cursory search, would lead me to believe there is no Simulink block that will do everything for you.

My advice would be to make a Matlab function block and simply paste in the serial parse example that you've shown and modify it until it parses the message you are expecting.

Again I would caution you that the serial packet you will receive from the Arduino is not the packet that is coming from the IMU. You need a parser on the Arduino to read the IMU, then you need to transmit the results of that to the PC. You can just save the entire packet from the IMU and re-broadcast the same packet to the PC, but again, that's something you need to configure on both the Arduino and the PC.

I could give advice now about an outline for parsing a serial message, but (1) you already have example code and (2) my advice would be to follow the packet structure, which is not defined because it's whatever you want it to be.


问:
Beginner Soldering question
So, I need to know a couple of things about soldering. My primary workspace, robotics and otherwise, is a desk with a computer and only a little bit of free space (4 ft. by 6 in.). I am wondering if it is safe to solder in such a small area. Also, what level of ventilation do I need to solder safely? My desk is in a normal house room and my desk is write next to an air vent. My house has heating and A/C. Do I need a fan or a fume sucker thing? I plan to only solder a little to get things to stay in my solder less bread board (soldering header pins onto wires and such). So, basically, what are the minimum requirements for soldering safely (space and ventilation)? Also, if anyone could point me to some hobby/beginner level soldering must-haves on Amazon that would be great, thanks.</p>

答:
For occasional light-duty soldering as you describe, no special ventilation arrangement is required but sometimes a fan or hood is helpful.  For example, I use an open-front plastic cube, 34 cm on each edge, with a fan that draws air into the front and exhausts it through a hole in the back.  Two bright LED floods are mounted in the top of the box.

Piping the exhaust to a window or vent is a good idea if you do much soldering and want to keep smoke from smelling up the area. My fan's flow is low, just enough that smoke from rosin-core solder moves away from me instead of into my face.  It is a 12 V computer fan powered by a 9 V source, so is quiet and low-flow.  Too much flow would make noise and would cool off whatever you are soldering.

The free space mentioned (4ft. by 6 in.) is rather narrow, but is big enough if you have an effective way to keep the soldering iron from falling off the edge, and a way to keep it out of the way of your hands when it is set down.  Burning yourself is more of a safety risk, I think, than is causing a fire.

For “soldering must-haves”, thin solder (about 1 mm or less) is needed for typical electronics soldering.  Solder wick is good to have if you don't solder perfectly.  (See solder wick videos on youtube.)  Tweezers are a good idea.  Occasionally the following are useful:  small metal clips to heat-sink wires or parts, a “third hand tool”, a PCB vise, a magnifying glass (or camera), etc.

ContentLicense: CC BY-SA 4.0

Title: Beginner Soldering question


问:
How to rotate a dc motor at a fixed rpm
I am using 8051 microcontroller and a dc motor.What to do if i have to rotate the motor at any fixed rpm. Let's say 120rpm.

And if it is possible by generating pwm,how to do the calculations for the relation between duty cycle and rpm?

答:
This would be possible if you had a perfect motor. The speed of a motor is basically fixed by the voltage you apply on it. More precisely, the speed is proportional to the back EMF of the motor, and, with no current, BEMF is equal to the voltage you apply on the motor.

No current means no torque, so no mechanical power. If you have current, you'll have loss in the wiring of your motor (which is resistive), on the iron core and in the rotor, due to magnetic hysteresis and Foucault currents in the rotor (iron losses).

So, on a real motor, you can't know the exact rotation speed from the voltage you apply on the motor.

One solution is to put a sensor on the rotor to measure the rotor speed, and put a speed regulator in your 8051.

There is a more sophisticated solution: if you know the resistance and the iron losses of your motor, by sensing the current in your motor, and knowing the voltage you apply, you can compute the actual speed, and then run you speed regulation.

And, finally, a more basic solution, very easier: if your load is always the same (for instance, you have a propeller on your motor), you can measure the speed at different voltage, and rebuild mathematically a conversion law from PWM to speed, and use it to command your motor. If your load is very small, or roughly constant, you may even assume that speed is proportional to the voltage.

Title: How to rotate a dc motor at a fixed rpm


问:
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?

答:
On the Asguard system that we have been working on, we have a lot of shocks due to the wheel geometry. On this system we were also able to reduce the vibrations on the control side as Mark suggested. This was done through synchronising the wheels in optimal patterns.

The system also has some mechanical design features that reduces the vibrations. Flexible wheels, elestic couplings between the gears and the wheel and locking mechanisms for most of the screws.

The electronics are not rigidly connected to the structure, but use a combination of foam and rubbers to hold them in place. This has worked well so far. We had a lot of problems with connecters however, where we frequently would get micro-fractures on the board connectors, especially on the heavier connectors like firewire. In these cases we had to create mechanical structures to hold the connectors in place, or replace the connectors by lightweight alternatives where possible.

Sensitive components, like for example the IMU and the cameras we have rigidly connected to the system. It is true that this improves the noise on the accelerometers, but the Kalman Filter never had a big problem with it for estimating the orientation. When using short exposure times on the camera, the vibrations are also not much of a problem. From a sensor point of view we really expected much more problems than we actually had.

So I guess the answer to your question is that it really depends on your system, and as we have seen in our case that often you do not even need to protect your components from vibration too much.


问:
IRobot Create 2: Powering Up after Sleep
I've notice the IRobot Create 2 does not respond to the app's commands when it has been sleeping.  If I press the Clean button and re-run the app then the robot is responsive to the commands.

My initialization sequence (Android/Java) using usb-serial-for-android:

```<code>port.open(connection);
port.setParameters(115200, 8, UsbSerialPort.STOPBITS_1,UsbSerialPort.PARITY_NONE);
command(Opcode.START);
command(Opcode.SAFE);
</code>```

The physical architecture is IRobot Create 2 connected by IRobot Serial Cable to Google Project Tango Tablet.

How can my app wake up the Roomba from it's sleep?

答: Roomba goes to sleep to save power after five minutes of inactivity, as detailed in the OI spec (Aug. 10, 2015) on page 6, under "Passive Mode." The documentation is not in error where you have quoted it, as Roomba powers on with the OI off (and not in passive, safe, or full). If you want your robot to never fall asleep, put it into FULL. If you want the robot to wake up, instead, simply pulse the BRC pin before communicating, as detailed in the same passage as mentioned above. If you are using a USB to Create cable, one easy way to do this would be to open your serial port with hardware flow control, as the Roomba's BRC is attached to RTS on the computer side, and so when characters are Ready To Send, the BRC will be pulsed. It appears that at least some of the official Create to USB cables do not properly implement this functionality, but making the cable following the directions on the site does work. The second version of the Create cable, which has a 0.1" header along with a USB A connector in its overmold, has this error corrected. Please note that I am an iRobot employee, but the postings on this site are my own and don't necessarily represent iRobot's positions, strategies, or opinions.</p>


答:
No, you cannot get an exact RPM from PWM, and you probably cannot even get a close RPM from PWM without a good model of the system.

As Jacen notes in their answer, the voltage constant gives motor RPM for a given terminal voltage for an unloaded motor, but, thanks to friction, the motor is always under load. Worse, because of viscous friction, the load varies with RPM.

You could try to guess rpm based on voltage (which you could get from PWM duty cycle) and current, but the issue there is that motor output power is a combination of frictional losses, load losses, and acceleration torque. That is, if you have half voltage and full current, you could be accelerating from a stop to half speed or you could be operating at half speed under heavy load. It is not possible to divine contributions due to load and acceleration from output power alone.

That said, you can command an exact RPM by simply adding an encoder to the motor. With feedback you can read RPM exactly and implement a simple PID controller to drive output RPM to whatever you desire.

Title: How to rotate a dc motor at a fixed rpm

Body:
I am using 8051 microcontroller and a dc motor.What to do if i have to rotate the motor at any fixed rpm. Let's say 120rpm.

And if it is possible by generating pwm,how to do the calculations for the relation between duty cycle and rpm?


答:
It depends! In case you are going to attach either nothing or a constant load to your motor, one can calculate/approximate a relation between duty cycle and rpm by performing a series of input-output measurements or given the motor parameters $K_{mf}\ J \ L\ R\ b$ (see here) by analytical derivation.

The relation between the motor input voltage $V$ your supply voltage $V_\text{sup}$ and the duty-cycle $\nu \in [0,1]$ is approximately given as

$V = \nu\, V_{sup}$

Given the motors transfer-function (Angualr velocity $\omega$):

$\dfrac{\omega(s)}{V(s)} = \dfrac{K}{(J\,s+b)\,(L\,s+R)+K^2} $,

you can calculate the unit-step response of the motor as

$\lim_{s\rightarrow 0}\ \dfrac{1}{s} \dfrac{\omega(s)}{V(s)} \, s = \dfrac{K}{b\, R+K^2}$.

Thus your free running motor's verlocity should settle at approximately yield

$\omega = \dfrac{K}{b\, R+K^2}\, \nu \, V_{sup}$

However you must be lucky to be given precise motor parameters. Note due to modelling errors (neglecting many disturbances, heat, ...) this is only a rough approximation.

I recently did a comparison of a motor's step response to different input voltages (PWM controlled) and the theoretical step response of a modelled DC-Motor:

However, if the load or respectively the torque you're applying at the motor's shaft is not constant, you most certainly will have to implement a control loop, measuring the momentary rpm of the motor, calculating the deviation from the reference velocity and applying a duty-cycle that depends on this deviation. This can be done by using simple controler such as a PI-controler and is extensively discussed in literature. Tuning for the controller parameters can be done by "intelligent trying", approximative rules (Ziegler-Nichols) or given that you have the parameters of your motor, by numerical optimization techniques.

Title: How to rotate a dc motor at a fixed rpm


问:
What's an efficient way to visit every reachable space on a grid with unknown obstacles?
I'm trying to create a map of the obstacles in a fairly coarse 2D grid space, using exploration.  I detect obstacles by attempting to move from one space to an adjacent space, and if that fails then there's an obstacle in the destination space (there is no concept of a rangefinding sensor in this problem).

example grid http://www.eriding.net/resources/general/prim_frmwrks/images/asses/asses_y3_5d_3.gif (for example)

The process is complete when all the reachable squares have been visited.  In other words, some spaces might be completely unreachable even if they don't have obstacles because they're surrounded.  This is expected.

In the simplest case, I could use a DFS algorithm, but I'm worried that this will take an excessively long time to complete — the robot will spend more time backtracking than exploring new territory.  I expect this to be especially problematic when attempting to reach the unreachable squares, because the robot will exhaust every option.

In the more sophisticated method, the proper thing to do seems to be Boustrophedon cell decomposition.

However, I can't seem to find a good description of the Boustrophedon cell decomposition algorithm (that is, a complete description in simple terms).  There are resources like this one, or this more general one on vertical cell decomposition but they don't offer much insight into the high-level algorithms nor the low-level data structures involved.

How can I visit (map) this grid efficiently?  If it exists, I would like an algorithm that performs better than $O(n^2)$ with respect to the total number of grid squares (i.e. better than $O(n^4)$ for an $n*n$ grid).

答:
In the end, I found that the best way to do this was to employ a very simple concept: Flood Fill.  I used a stack-based iterative approach instead of the recursive option, and modified it for physical space by using an A* search to find a path from the current location to the next location in the stack (using only those grid squares that have already been visited, since I'm guaranteed to have a path between them).

The efficiency seems fairly reasonable.


问:
How can I tell if a servo motor is capable of being controlled degree by degree?
I want to create a rotating control mechanism that can turn a surface to face any direction in a sphere. My dad (an electrical engineer) said I can probably do it by connecting two servo motors together.

I am looking for a servo motor that can do what I want to do, which is moving the sphere with decent precision (within ~1 degree) but I don't know which kinds of motors are able to handle such precision.

Another challenge is that one servo will have to hold the second servo on top. As I understand it, the torque rating determines the maximum amount of force the servo can exert on its load so I can figure out if the servo is strong enough through some math?

答:
I had a very similar problem. I searched several days in internet without success and then I took a wrong decision. I took a "normal" PWM (pulse width modulation) servo and it was extremely imprecise. The position results were not exactly reproducible. Additionally these cheap servos always rotate with the maximum speed which is mostly unuseful.

After my project was already finished with the wrong servos I knew that the servos which I need really DO exist. Why didn't I know of them before ?

I tell you the secret: Use Dynamixel.
I use the AX-12A which runs at 12V and does precise positioning and allows also to control the speed. And if this would not be enough it also returns to you the current position from 0 to 300 degree! I don't know of any other servo which has this functionality.

Download the detailed datasheet and read it.

P.D. There is no problem to put one servo on top of the other. You can even put three servos on each other to move in the 3 directions. A short plastic bracket (very hard) to mount one servo directly on top of another comes with the servo, also the screws. You can also order longer brackets of metal.


问:
How can one determine whether a LiPo battery is going bad?
In our lab we use LiPo batteries to power our quadrotors. Lately we have been experiencing stability issues when using certain batteries. The batteries seem to charge and balance normally and our battery monitor indicates they are fine even when putting them under load. However when we attempt to fly the quadrotor with one of these batteries, manually or autonomously, it has a severe tendency to pitch and/or roll. My guess is that the battery is not supplying sufficient power to all the motors which brings me to my question. Is this behavior indicative of a LiPo going bad? If so what is the best way to test a battery to confirm my suspicions?</p>

答:
You can use an RC battery checker,

to verify the individual cells in a battery pack. These are cheap, for about $3.

If any cell is below 3V on a LiPo battery then it should be considered as dead, or dying, and hence, it should be replaced.


答:
In the real world, this cannot be calculated.  You have three options, from best to worst:

Measure the actual RPM in real time and make appropriate adjustments to the motor's input power (such as with a PID).

Use a stepper motor, control the step rate, and assume that it will never stall.

Allow "fixed RPM" to mean "bell curve of acceptable RPMs".  Then, characterize the motor's commanded speed versus its actual speed, base your calculations on that, and be prepared to do it again when the motor's characteristics inevitably drift (due to load, lubrication, ambient temperature, etc) and cause your RPMs to move out of the acceptable range.

Title: How to rotate a dc motor at a fixed rpm


答:
The measurement you're looking for is called "resolution" -- it will tell you how many positions the motor can be in.  One way to calculate this is based on the number of bits returned by the encoder (or resolver).   This page has a great introduction to servo motors, including this bit on resolution:

Resolution – this is a measure of the smallest angular movement that the motor can be commanded to make. This is pretty crucial [...]. However, things get quite tricky here, because most hobbys servo motors do not provide their angular resolution ratings – this can be quite infuriating, as servos will be rated as “super accurate”, but nothing more. Resolution is also confusing because in reality there are two resolutions at play here – the Servo Controller Resolution and the Servo Motor Resolution.

The Servo Controller Resolution is the smallest change to pulse width that the servo controller can make. If the exact pulse width is specified to your servo controller, by a 16 bit number, you should be able to specify $2^{16}$ distinct pulse widths. If the servo motor that you have, has a rotation range of 180° the controller should be able to command it to move to one of $2^{16}$ positions, giving you an angular resolution of 0.003°.

However in reality, because of the physical design of hobby servos, the servo motor resolution is much coarser than that. Depending on the motor, you should be able to get between 0.5° to 0.3° (an exception is the MX-28 which has a resolution of 0.088°). I.e. it would take a few step changes in the pulse width, before the change in pulse width got large enough for the hobby servo motor to actually detect it and move. Like a bunch of other properties, it turns out that resolution depends on the load that you are trying to move – at larger loads, the resolution of the motor could drop off (though you may be able to counter this by operating the motor at higher voltages – provided you stay within the rated motor voltages).

Depending on the type of servo, the presence of a gear system might work in your favor.  If it takes multiple turns of the motor to get one turn of the output shaft, you will have gained resolution and torque (at the expense of angular velocity).

Title: How can I tell if a servo motor is capable of being controlled degree by degree?

Body:
I want to create a rotating control mechanism that can turn a surface to face any direction in a sphere. My dad (an electrical engineer) said I can probably do it by connecting two servo motors together.

I am looking for a servo motor that can do what I want to do, which is moving the sphere with decent precision (within ~1 degree) but I don't know which kinds of motors are able to handle such precision.

Another challenge is that one servo will have to hold the second servo on top. As I understand it, the torque rating determines the maximum amount of force the servo can exert on its load so I can figure out if the servo is strong enough through some math?


答: It sounds like the simplest option would be to put the grease into a pressurized container (e.g. spring-loaded) and control the metering by just opening and closing the valve.  That would mean you just need a solenoid valve to control the opening and closing.</p>

Title: How do I dispense a greasy fluid?

Body:
I'm a agricultural engineering student and complete newbie trying to build a simple mechanism attached to a drone that dispenses a grease-type fluid. However, since I'm not familiar with the field, I'm having a hard time googling because I don't know the correct terms to search for.

I'm looking for a mechanism that will remotely push the grease out. The problem is carrying the necessary weight for an hectare (300g to 1,5kg of fluid) and the dispenser mechanism within the drone. So I'm looking for a lightweight dispenser mechanism capable of deliver small amounts of this fluid (3g) distributed on the trees canopy. The grease do not need to be heated as it flows naturally in normal temperatures (like a toothpaste). Both pump or syringe-type arrangement would be fine as long as I can control it remotely.


问:
Powering a Project Tango Tablet with iRobot Create 2
Project Tango Development Kits come with a mini-dock (see picture below).

I am controlling the iRobot Create 2 by the mounted Tablet using the USB cable provided plugged into the mini-dock. (see docs).

The USB 3.0 port on the mini-dock is only functional when the tablet is docked. The port can be used to attach an external memory drive or standard peripherals to the tablet.

I wish to recharge the tablet using the power from the iRobot. The mini dock comes with a port for external charging:

The mini-dock accepts a power adapter for faster charging (not provided). The power adapter output must be 12V, 2A, and the connector must be a barrel plug with 5.5mm outer diameter, 2.1mm inner diameter, center positive.

Ideally the charging would happen only when the iRobot is also charging, but charging all the time is acceptable.

Is this possible?  If so, how?

答:
Short answer - No, it is not possible.

None of the motor drivers will deliver 24W, see link.  In addition the power supply that provides charging power to the robot is limited to just over 24W under the best case. See the dock rating on the label (22.5V @ 1.25A).  All of this power is used to charge the robot battery and power the robot electronics to control charging.  Even if you waited until the robot battery was finished charging you would still need to convert the 22.5V to 12V but there is no suitable access to the 22.5V.

You will either have to live with charging your Tango independently from the robot or use a lower power computer (Arduino, RasPi, etc.) to control Create 2.


问:
Arduino mega shield v2.0 compatibility with arduino due
Like the title says.. Will it work? I know about the due 3.3 volt limitations.

I want to build a hexapod with 18 servo's.

The shield I am looking at:

http://yourduino.com/sunshop2/index.php?l=product_detail&p=195

If it isn't compatible. Is there an alternative shield which will work? I can't seem to find much for the due.

答:
It should be possible to plug that shield into either a Due or a Mega, with the caveat that the URF01 pins on the shield may interfere with two sockets of the Power header (IOREF and the opening next to it).  (Older Mega's may have a six-pin Power header rather than eight-pin.)  If there's interference you might need to remove a pin or two from the URF01 group.  Here is a picture of a Due overlaid (at 41% transparency) on top of a Mega:

The overlay is imperfect (due to slight mispositioning, slight scale errors, and camera distortion) but is good enough to show that the shield should plug in.  The shield appears to have a power-indicator LED on it, but aside from that apparently has no electronics to cause problems.

The photos that I overlaid came from arduinoBoardMega and ArduinoBoardDue or related sites.

The following is from “nice drawings of the arduino uno and mega 2560” on arduino.cc and should let you measure your Due to see if it matches:

Numbers in the picture above are in mils, that is, in thousandths of an inch.  Numbers in the picture below (from hwkitchen.com) are in millimeters.  Note, the picture above is the more-recent R3 version, with 8 pins in the power block, vs the 6 pins in that block in the picture below.

The thread shield layout for DUE/Mega in forum.arduino.cc also may be of interest.  It suggests the Due and Mega have matching pin layouts.  It also gives links to some CAD files for the boards.


问:
Non linear control system?
I have a dual (sequential) loop control system controlling the angle of a rotational joint on a robot using an absolute encoder. I have tuned the inner control loop (for the motor) and am now working on tuning the outer loop (for the joint).

Example of a dual loop controller

When I disturb the system the response isn't what I would expect.

Kp = 0.4

Kp = 0.1 Kd = 0.001

I didn't add a Ki term because I don't have any steady state error.

I'm confused by the fact that the second overshoot in the first plot is larger than the first one. No matter how I adjust the parameters I can't seem to get rid of the oscillation in the velocity of the joint (seen in the second plot). One limitation I have is if I increase both Kp and Kd too high the gearbox of the becomes very noisy because the noise in the encoder signal creates larger adjustments in the position of the motor. I'm working on adding a filter to the output using the method described here.

The code I'm using for the outer loop is:

```<code>static float e_prev = 0.0;

e = joint_setpoint - joint_angle;
e_i += e/0.001; // dt = 0.001s
e_d = (e - e_prev)/0.001; // dt = 0.001s

e_prev = e;

motor_setpoint += k_p * e + k_i * e_i + k_d * e_d;
</code>```

I'm beginning to think that the system might not be able to be modeled by a first order equation, but would this change the implementation of the control loop at all? Any advice is appreciated!

Ben

答:
If you see integral, think area. Derivative, think slope. Integral error is error times sample time (plus previous integral error), derivative error is the change in error divided by time.

Your derivative error term is correct, but your integral error term is not. This shouldn't be an issue because you aren't using an integral term (even though you should!)

Where I would guess your problem lies is with your controller output - you have

motor_setpoint += k_p * e + k_i * e_i + k_d * e_d;

Here you have the += operator, which indicates that motor_setpoint is accumulating the output of your controller. This is incorrect. The output of your PID controller alone is the input to your motor.

I would guess you might be thinking that you are adding the control signal to your reference, but remember that your reference was already taken into account when calculating the error!

This is, for me at least, the magical aspect of the PID controller. It doesn't care what is between the controller and the output, it just adjusts until there is zero error.

If error is accumulating quickly (integral error is high), the controller "opens up", but then if error starts to drop quickly (derivative error is high) it will "ease off" to minimize the overshoot.

If anything, I would suggest eliminating the derivative term and using only the PI controller - this is commonly done in industry because the derivative term is highly sensitive to noise.

Anyways, hopefully this fixes your issue, but if not please at least make the changes and then re-generate  and re-post your plots. If the base controller isn't right we can't divine anything from the plots.

Also, check out Ziegler-Nichols tuning if you're looking for some professional PID tuning advice.

Title: Non linear control system?


问:
Do "toy" robots move technology forwards?
Over the last month, I saw many robots that don't have any real purpose, which made me ask myself: "Does this have any value?" I saw dancing robot on CES, advanced lego based robots and also robots combined for very limited purpose. I saw ten year old children playing with robots, and competitions for them. Someone has told me that this is just for education and logic spreading.

In other cases, there were arguments like, "this is for informing people that everything is going forwards". I know that people will buy robotic vacuum cleaners because they think that they'll save some time, but these robotic cleaners are not very reliable and I see it only as marketing.

Do these things (children's education, dancing robots, and other instances of selling a pig in a poke) have any value in terms of robotics, and are really advancing the field as manufacturers say?

答:
It certainly does. Ever since they started writing fiction about robots, they imagined robots as intelligent beings among ourselves. No one thought of robots as mechanical arms that replace your jobs. So first of all, there is no reason to think why the humans wouldn't want to make useless robots.

You may have heard of the karakuri dolls from the 17th century, that serve tea (pretty useless, huh?):

Or the digesting duck from the 18th century (even worse):

that you would argue that they don't make sense and they did not bring the technology forward, but that is not entirely correct.

There are many aspects why such robots are useful:

Psychological effect: As a human, you would probably be creeped out if you suddenly start seeing humanoids walking around. Useless robots (as well as fictional books) help the transition from our current life to one with robots.

Technological effect: The useless robot could well be (and probably often is) the testbed for a new technology. The dancing robot may indeed be a prototype on which a system that keeps the robot in balance is being tested. Since dancing is more difficult than walking or running, the balance system on a robot that can dance can very well perform on one that merely walks.

Cultural effect: In this subject, the Japanese come to mind. I am not thoroughly familiar with the Japanese culture, but they certainly seem to have a knack for robots that mimic a human. By your definition of "useless", we humans all more or less are useless, so it is ok for them for the robots to be that way, too.

On the second part of your question:

are robotics really moving forwards as manufacturers say?

I would again say yes. Most of the advances in technology (robotics included) is not made public, and by public I don't mean engineers and scientists, but your average teenage girl. You would probably never even hear in the news that they had made a super fantastic <whatever> for robots. All you would probably see is the fun robots that people would enjoy watching.

I merely work in a lab and hear every now and then who does what, and I certainly believe that robotics is being developed quite fast!

To answer your comment:

But what about using new technlogoies[sic] as deception of customer when saying this will help you; and it finally won't in most of cases.

I'm afraid we live in a world of greed and lies. You hear all sorts of advertisements on all sorts of useless junk every day from companies that want to get more and more money.  And you should note that any company that mass produces robots (or any other thing) has only one goal: sell those robots. It's not just robotics, so any effect such false advertising would have on people, you should ask psychologists rather than roboticists.


问:
Robot localization without any sensors
Is it possible to localize a robot without any sensors, odometer and servo motors?

Assume robot has dc motors and no obstacles.

答:
If you know the wheel radius and the speed of the robot, you will be able to calculate its location at any time relatively to its initial position.

```<code>travelled_distance = Speed * time;
current_position = initial_position + travelled_distance;
</code>```

This is a simplified 1-dimensional equation than can help you. But keep in mind that without sensors and odometry the localization can't be very accurate.

Title: Robot localization without any sensors

Body:
If you know the wheel radius and the speed of the robot, you will be able to calculate its location at any time relatively to its initial position.

travelled_distance = Speed * time;
current_position = initial_position + travelled_distance;

This is a simplified 1-dimensional equation than can help you. But keep in mind that without sensors and odometry the localization can't be very accurate.


问:
Inverse kinematics solution for 6DOF serial arm
My 6 joint robot arm structure doesn't meet the requirements for a closed form solution (no 3 consecutive axes intersecting at a point or 3 parallel axes...).

What would be best method to adopt to get solution in 1ms or less? Estimation accuracy of 1mm. I'm assuming the computation is done on an average laptop Intel Core i3, 1.7GHz, 4GB RAM

答:
I don't believe 3 consecutive axes intersecting at a point rules out closed form solutions.  Although i don't have a reference for this.

You should investigate OpenRave and ikfast.  This will generate library independent optimized C++ code with closed form solutions for a wide variety of kinematic chains and IK types.

I found this paper that might be of interest to you:

Luo, R.C.; Tsung-Wei Lin; Yun-Hsuan Tsai, "Analytical inverse kinematic solution for modularized 7-DoF redundant manipulators with offsets at shoulder and wrist," in Intelligent Robots and Systems (IROS 2014), 2014 IEEE/RSJ International Conference on , vol., no., pp.516-521, 14-18 Sept. 2014

While it describes a 7 DOF arm, its shoulder and wrist joints don't intersect at a point.  You might gain some insight from their formulation, or perhaps some of their references.


问:
How can I recognize animals in a video stream or static images with openCV or other library/software?
I'm a software developer not experienced in AI or machine learning, but I'm now interested in developing this kind of software. I want to develop software that recognizes some specific objects, specifically, animals from a video stream (or a sequence of static images).

I saw there's a library called openCV which is often commented in this forum, but what I saw so far is this library is a helper for working with images, I didn't find the object recognition or self learning part.

Is openCV a good starting point? better go for some theory first? or there are other already developed libraries or frameworks aimed for object recognition?

EDIT
To give some context: I will have ona camera checking a landscape, mostly static but some leaves may move with the wind or some person may step in, and I want to get an alert when some animal is into view, I can reduce the "animals" to only birds (not always I will have a nice bird/sky contrast).

I did some work with supervised neural networks some 15 years ago and studied some AI and machine learning theory, but I guess things have improved way too much since then, that's why I was asking for some more practical first steps.

Thank you

答:
Given that you are doing a more "constrained" goal, with a "mostly" static background, I would recommend simply doing a "background image subtraction" method. The "hard part" which has come a long way over the last decade is how you deal with shadows, light changes, and foliage moving.

There are tons of resources on this topic, but here is a good one I found after a quick cursory search:
http://www.pyimagesearch.com/2015/05/25/basic-motion-detection-and-tracking-with-python-and-opencv/

This should get you to a 80% solution for what you want.

If you want to go deeper, and try to identify specific animals, there are two main approaches you can potentially follow. The easy one is Template Matching, the harder one is creating a Bayes Classifier.

In either approach, you would:

Gather a sample set of data (most likely by using the output from above)

Either:

Create templates you would match against

Train your classifier to identify the animals you would want

A couple of notes:

Template matching out of the box is highly scale and orientation dependent. While you can start with basic template matching, you'll probably quickly want to create a Gaussian pyramid. Here is a good reference: https://stackoverflow.com/questions/22480485/image-matching-in-opencv-python

Doing Bayesian Classifiers well is hard, and if you just search on Google Scholar, you'll see a tons of papers on the subject. However, it seems to be the "way to go" for high accuracy. Generally you would combine the base classifier with some other machine learning technique (such as a Markov Model). If you do go this route, I would recommend trying to do something "simpler" than trying to find a whole bird. Instead, I would recommend perhaps identifying a simple feature that would "mean" bird/animal, such as locating an "eye" or "beak".

Hope this helps.


问:
Positioning Sensor
I would like to locate the position of a stationary autonomous robot in x-y-z axis relative to a fixed starting point.

Could someone suggest sensors that would be suitable for this application?

I am hoping to move the robot in 3D space and be able to locate it's position wirelessly. The rate of position update is not important as I would like to stop the robot from moving and relay the information wirelessly.

The range I am looking for is roughly 2 KM + (the more the better) with accuracy of  +/- 1 CM.

Is there any system that could do this? Thanks for your help.

答:
Differential GPS could be a starting point. But 1 cm will cost a bit.

The basic idea is to increase the accuracy of gps. Stationary antennas at known positions allow to measure the error in the gps signal transit times.

A robot can then receive the error from the antennas and use it to improve its gps result.

According to German wikipedia:

Die erreichbare Genauigkeit liegt je nach Qualität des Empfängers und der Korrekturdaten zwischen 0,3 m und 2,5 m für die Lage (x, y) und bei 0,2 m bis 5 m für die Höhe.

that is:

The possible accuracy depending on the quality of the receiver and the correction data lies between 0,3m and 2,5m for the position (x,y) and between 0,2m and 0,5m for the height.

On top of that, the phase shift of the carrier wave can be evaluated to increase accuracy even further:

Hochqualitative Systeme werten zusätzlich die Phasenverschiebung der Trägerwelle aus [...] und erreichen so Genauigkeiten von wenigen Millimetern (± 1 mm bis ± 10 mm pro km Abstand zur Referenzanlage).

that is:

High quality systems additionally evaluate the phase shift of the carrierwave and allow accuracy of few milimeters (from $\pm 1mm$ up to $\pm 10mm$ per $1km$ distance to the reference station)

Title: Positioning Sensor


问:
How to numerically calculate the Jacobian?
I'm trying to calculate the Jacobian for days now. But first some details. Within my Master's Thesis I have to numerically calculate the Jacobian for a tendon-driven continuum Robot. I have all homogeneous transformation matrices as I already implemented the kinematics for this Robot. Due to it's new structure there are no discrete joint variables anymore but rather continuous parameters. Therefore I want to compute the Jacobian numerically.
It'd be awesome if someone could provide a detailed way how to compute the numerical Jacobian for a 6-DoF rigid-link robot (only rotational joints => RRRRRR). From that I can transfer it to the continuum robot.

I've already started computing it. Let T be the homogeneous transformation matrix for the Endeffector (Tip)  with

$$T=\begin{bmatrix}R & r \\ 0 & 1 \end{bmatrix} $$

with R = rotational matrix (contains orientation) and $ r = \begin{bmatrix} x & y & z \end{bmatrix}^T$ endeffector position.
My approach is to compute the first three rows of J by successively increasing the joints, computing the difference to the "original" joint values and dividing it by the increment delta, the joint-space is $ q = \begin{bmatrix} q_1 & q_2 &  q_3 & ... &q_6 \end{bmatrix}T $

$q_1 = q_1 + \delta$ => $J(1,1) = (X_{increment} - X_{orig})/\delta$

$q_2 = q_2 + \delta$ => $J(1,2) = (X_{increment} - X_{orig})/\delta$

and so on. I do the same for the y and z coordinates. So I get the first 3 rows of J.

Now I don't know how to compute the last three rows as they refer to the rotational Matrix R. Since it's a 3x3 matrix and no scalar value I don't know how to handle it.

答:
Well, although, I didn't well understand what have wrote as a solution to the first part (upper) half of the Jacobian, but AFAIK, the manipulator Jacobian is a $6\times n$ matrix, for that let's say $ J$ is the Jacobian thus:

$$
J = \begin{bmatrix} J_v \\
J_\omega \end{bmatrix} \\
$$
where both the upper part $ J_v$ and the lower one $ J_\omega$ are $ 3 \times n $ now: $ J_{v_i} = z_{i−1} \times (o_n − o_{i−1}) $ is the upper half of the Jacobian for the joint $ i$ and

$$
z^0_{i−1} = R^0_{i−1}k \\
$$

where $ R^0_{i-1}$ is the transformation between the two neighboring frames, and $ z^0_0= k = (0, 0, 1)^T$, also $o_i$ is the position vector for the joint $ i$. and the lower part $ \textbf{which you're looking for} $ is simply:
$$ J_{\omega_i} = z_{i−1}$$ the upper transcript could be ignored.
All this for $ \textbf{for revolute joint, as your case.}$

$\textbf{If we have a prismatic joint}$, then:
$$
J_{v_i} = z_{i−1}$$ and $$ J_{\omega_i} = 0 \\
$$
You may consult Spong: robot dynamics and control for more details (ch4).


问:
Do "nano bots" (that can fit inside the human body) actually exist?
I was wondering, do we have real nano bots, like the ones in the movies?

I think we have bots which can move through the blood vessels, am I right?

答:
Yes! Yes we do have robots which can swim through the bloodstream!

rics did a good job of summarizing the difficulties in producing a completely autonomous nano robot. Something like a Mars rover, with more autonomy, but tiny. This is not the only type of robot. While this is definitely beyond the capabilities of our current-day researchers / engineers, there is another thread in this domain that is worth mentioning: nano manipulators.

Traditionally, robots have been automated manipulators. In the case of robotic manipulators, most of the processing and localization challenges are offloaded, and the robot just carries out the task of delivering part A to location B.

This closely matches the job description of a nano robot: deliver drug A to organ B, or take sample A, etc.  In this case, a very small magnetic manipulator can be inserted into the body and moved, turned, etc, by use of magnetic fields from outside the body. So the robot ends up being a small piece of innocuous metal.

(source: ethz.ch)

Think of it as the "hand." The magnetic fields are the "arms," an MRI is the "eyes," and a computer somewhere is the "brain."  Its not fully embedded, but it is technically a nano-scale robotic manipulator.

If you are interested in this (who wouldn't be?) Check out the following. There are plenty of awesome videos ahead:

The key guy in this field is Brad Nelson. He gave a keynote talk at
ICRA 2012, in Saint Paul, MN. It is available freely
here. Have
a look.

More information (including the above reference paper), can be found on his webpage,
http://www.iris.ethz.ch/msrl/research/current/index.php

One of the coolest takeaways from the talk was his work on "swimmer" robots. More info (and videos!) here:
http://www.iris.ethz.ch/msrl/research/current/helical_swimmers/

There are two types of manipulators he is researching, but both are inserted, tracked using MRI, moved / manipulated using magnetic
fields, and then removed via a simple needle.

The two types are based on size. A larger manipulator is easier to move using magnets, but a smaller one can be more precise.

My impression after the keynote talk was this technology is quickly approaching human trials. They have tested in cow eyes and other biological organs. I'm interested to see what they produce this year.


问:
Robot path planning
My goal is to move robot in certain points as shown in the figure. It's initial position is (x0,y0) and move along other coordinates.

I am able to track robot position using a camera which is connected to pc and camera is located at the top of the arena. I've mounted a ir beacon on the robot, camera find this beacon and locates it's coordinate(in cm) in the arena. Using this coordinate how can I move my robot to another position, say new position (x1,y1)

My robot has arduino mega 2560 with two DC motors, communication between pc and robot is done using bluetooth

Update:

Thanks @Chuck for the answer, however I still have few doubts regarding turning angle.

My robot position setup is as shown in the image.

(xc, yc) is the current position and (xt, yt) is the target position.

If I want to align robot in the direction of the target coordinates, I've to calculate atan2 between target and current coordinates. But the angle remains same since it's current position is not changing with respect to the target point. so I assume robot simply makes 360' rotation at current position?

Update:

The path points is as show below in the image, is my initial heading angle assumption is correct?

'1' is the starting point.

Update

Thank you for your patience and time, I'm still struck at turning, my code goes like this

```<code>//current points
float xc = -300;
float yc = 300;

//target points

float xt = -300;
float yt = -300;

//turning  angle
float turnAngle;

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

void loop() {

  turnAngle = atan2((yt-yc), (xt-xc)); //calculate turning angle

  turnAngle = turnAngle * 180/3.1415; //convert to degrees

  if (turnAngle > 180) {
    turnAngle = turnAngle-360;
  }

  if (turnAngle < -180) {
    turnAngle = turnAngle+360;
  }

  if (turnAngle < -10) {
    //turn right
  }

  if (turnAngle > 10) {
    //turn left
  }
}
</code>```

Since angle is always -90' robot only makes right turn in loop at current point, since angle is not changing. I think I'm missing something here.

答:
You have to know your initial heading, let's call it $\theta_0$. So you start at some position, $p_{start}$, and you're trying to get to some end position, $p_{end}$.

Assume starting position and ending positions are given by:

$$
p_{start} = <x_0 , y_0> \\
p_{end} = <x_1 , y_1> \\
$$

Those positions are absolute, but you are trying to get from one to another, so all you really care about are relative distances. Then, let:

$$
dX = x_1 - x_0 \\
dY = y_1 - y_0 \\
$$

Now you can find the absolute heading $\theta_{0 \rightarrow 1}$ with the arc tangent of $dX$ and $dY$, but the basic $atan{}$ function doesn't handle negative signs correctly because it can't tell if which or both of $dX$ and $dY$ were negative. What you need is atan2.

$atan2{(dY, dX)}$ will give you the absolute heading of $p_{end}$ with respect to $p_{start}$. Now to find how much your vehicle needs to turn, find the difference between your starting heading and the required heading:

$$
\mbox{Turn angle}= \theta_{0 \rightarrow 1} - \theta_0 \\
\mbox{Turn angle}= atan2{(dY, dX)} - \theta_0 \\
$$

With turn angle, I like my vehicles to turn the direction that requires the least movement, so instead of limiting $\mbox{Turn angle}$ to $0<= \mbox{Turn angle} <= 2\pi$, I would limit the angle to $-\pi<= \mbox{Turn angle} <= \pi$.

In this way you would wind up turning -10 degrees (10 degrees clockwise) instead of +350 (350 degrees CCW). Ultimately you should wind up in the same spot, but -10 looks "right" and +350 looks foolish.

You can limit the turn angle with code like:

```<code>while turnAngle > 3.1415
    turnAngle = turnAngle - 2*3.1415:
end
while turnAngle < -3.1415
    turn Angle = turnAngle + 2*3.1415;
end
</code>```

This code runs and doesn't care what multiple of +/-2$\pi$ you're in, it spits out the same angle bounded to within +/-$\pi$.

Finally, calculate how far you travel along your new heading with the magnitude of distance between the points:

$$
\mbox{distance} = \sqrt{dX^2 + dY^2} \\
$$

Remember to set the new absolute heading, $\theta_{0 \rightarrow 1}$, as your current heading then get the next point!

:UPDATE: - Numeric Example

I believe a point of confusion here may be that I didn't state that the absolute heading is relative to the +x-axis. That said, I'll work through OP's problem as shown in the most recent update.

The initial heading $\theta_0$ is in-line with the +x-axis, so $\theta_0 = 0$.

$$
p_{start} = <-300,300> \\
p_{end} = <-300,-300> \\
$$

$$
dX = x_{end} - x_{start} = (-300) - (-300) \\
\boxed{dX = 0} \\
$$

$$
dY = y_{end} - y_{start} = (-300) - (300) \\
\boxed{dY = -600} \\
$$

$$
\theta_{0 \rightarrow 1} = atan2(dY,dX) \\
\theta_{0 \rightarrow 1} = atan2(-600,0) \\
\theta_{0 \rightarrow 1} = -1.5708 \mbox{rad} = -90^o
$$

Now, the change in heading:

$$
\mbox{Turn Angle} = \theta_{0 \rightarrow 1} - \theta_0 \\
\mbox{Turn Angle} = -1.5708 - 0 \\
\mbox{Turn Angle} = -1.5708 = -90^o\\
$$

The distance you need to travel after turning $\mbox{Turn Angle}$ is given by:
$$
\mbox{distance} = \sqrt{dX^2 + dY^2} \\
\mbox{distance} = \sqrt{0^2 + (-600)^2} \\
\mbox{distance} = \sqrt{(-600)^2} \\
\mbox{distance} = 600 \\
$$

Now the new heading $\theta_1$ is equal to the absolute heading between start and end:

$$
\theta_1 = \theta_{0 \rightarrow 1} \\
$$

Or, alternatively, the new heading is equal to the initial heading plus the turn angle, but the turn angle was defined by the difference between $\theta_{0 \rightarrow 1}$ and $\theta_0$, so the equation above is just a shortcut.

Now, proceed to the next point:

$$
p_{start} = <-300,-300> \\
p_{end} = <0,-300> \\
$$

$$
dX = x_{end} - x_{start} = (0) - (-300) \\
\boxed{dX = 300} \\
$$

$$
dY = y_{end} - y_{start} = (-300) - (-300) \\
\boxed{dY = 0} \\
$$

$$
\theta_{1 \rightarrow 2} = atan2(dY,dX) \\
\theta_{1 \rightarrow 2} = atan2(0,300) \\
\theta_{1 \rightarrow 2} = 0 \mbox{rad} = 0^o
$$

Now, the change in heading:

$$
\mbox{Turn Angle} = \theta_{1 \rightarrow 2} - \theta_1 \\
\mbox{Turn Angle} = 0 - (-1.5708) \\
\mbox{Turn Angle} = +1.5708 = +90^o \\
$$

The distance you need to travel after turning $\mbox{Turn Angle}$ is given by:
$$
\mbox{distance} = \sqrt{dX^2 + dY^2} \\
\mbox{distance} = \sqrt{(300)^2 + (0)^2} \\
\mbox{distance} = \sqrt{(300)^2} \\
\mbox{distance} = 300 \\
$$

Now the new heading $\theta_1$ is equal to the absolute heading between start and end:

$$
\theta_2 = \theta_{1 \rightarrow 2} \\
$$

This process repeats as you see fit.

:Second Update: Code Issues

You need to turn (left or right) by the amount turnAngle. You have not described your physical robot so nobody can tell you exactly how to turn.

You have your code in void loop(), which makes me think you are running the same code over and over, but you never take the following steps:

You never declare a starting heading.

You fail to define turnAngle as the difference between atan2((yt-yc),(xt-xc)) and the starting heading.

After you have turned, you fail to set your new heading.

You fail to move forward.

You fail to update your current position with the target position

I would suggest modifying your code as follows:

Last update

The wheel base is the distance from the center of the tire to the center of the other tire. Assuming that the motor speeds while turning are the same magnitude but opposite sides (leftMotorSpeed = - rightMotorSpeed), and the wheels are the same diameter, you can find out how quickly you are turning by using the arc length equation s = L*theta, so theta = s/L, where theta is the rotation, s is the arc length, and L is half the wheel base. Then, taking a derivative, $\dot{\theta} = \dot{s}/L$, where $\dot{s}$ is the linear tire speed, given by $\dot{s} = r_\mbox{tire}*v_\mbox{motor}$

So you can take motor speed and get back to rotation rate, and then numerically integrate that and compare to the $\mbox{Turn Angle}$:

thetaDot = (rTire * vMotor) / (wheelBase/2);

then

theta = theta + thetaDot*dT;

where dT is the sample/sweep time on the controller. Finally, use a while loop to turn the motors until the desired angle is reached. Putting it all together:

```<code>//current points
float xc = -300;
float yc = 300;

//target points

float xt = -300;
float yt = -300;

//turning  angle
float turnAngle;

//***************
float startingHeading = 0;
float currentHeading = startingHeading;
//***************

//***************
float turnRight = 1;
float turnLeft = -1;
float wheelBase = <This is a number you get by measuring your vehicle>
float tireRadius = <This is a number you get by measuring your vehicle>
float speedModifier = 0;
float vRightMotor = 0;
float vLeftMotor = 0;
float vMotor = 0;
float theta = 0;
float distance = 0;
//**************

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

void loop() {
  //*************
  destinationHeading = atan2((yt-yc), (xt-xc)); //calculate turning angle
  destinationHeading = destinationHeading * 180/3.1415; //convert to degrees
  turnAngle = destinationHeading - currentHeading;
  //*************

  if (turnAngle > 180) {
    turnAngle = turnAngle-360;
  }

  if (turnAngle < -180) {
    turnAngle = turnAngle+360;
  }

  //***************
  if (turnAngle < 0) {
    speedModifier = turnRight;
  }

  if (turnAngle > 0) {
    speedModifier = turnLeft
  }

  theta = 0;
  while abs(abs(theta)-abs(turnAngle)) > 0
    {
    vRightMotor = speedModifier * <100 percent speed - varies by your application>;
    vLeftMotor = -speedModifier * <100 percent speed - varies by your application>;
    <send the vRightMotor/vLeftMotor speed commands to the motors>
    vMotor = vRightMotor;
    thetaDot = (tireRadius * vMotor) / (wheelBase/2);`
    theta = theta + thetaDot*dT;
    }
  <send zero speed to the motors>

  currentHeading = destinationHeading;
  distance = sqrt((xt - xc)^2 + (yt - yc)^2);
  if (distance > 0) {
    // go forward
  }
  xc = xt;
  yc = yt;
  //****************
}
</code>```

Title: Robot path planning

Body:
You have to know your initial heading, let's call it $\theta_0$. So you start at some position, $p_{start}$, and you're trying to get to some end position, $p_{end}$.

Assume starting position and ending positions are given by:

$$
p_{start} = <x_0 , y_0> \\
p_{end} = <x_1 , y_1> \\
$$

Those positions are absolute, but you are trying to get from one to another, so all you really care about are relative distances. Then, let:

$$
dX = x_1 - x_0 \\
dY = y_1 - y_0 \\
$$

Now you can find the absolute heading $\theta_{0 \rightarrow 1}$ with the arc tangent of $dX$ and $dY$, but the basic $atan{}$ function doesn't handle negative signs correctly because it can't tell if which or both of $dX$ and $dY$ were negative. What you need is atan2.

$atan2{(dY, dX)}$ will give you the absolute heading of $p_{end}$ with respect to $p_{start}$. Now to find how much your vehicle needs to turn, find the difference between your starting heading and the required heading:

$$
\mbox{Turn angle}= \theta_{0 \rightarrow 1} - \theta_0 \\
\mbox{Turn angle}= atan2{(dY, dX)} - \theta_0 \\
$$

With turn angle, I like my vehicles to turn the direction that requires the least movement, so instead of limiting $\mbox{Turn angle}$ to $0<= \mbox{Turn angle} <= 2\pi$, I would limit the angle to $-\pi<= \mbox{Turn angle} <= \pi$.

In this way you would wind up turning -10 degrees (10 degrees clockwise) instead of +350 (350 degrees CCW). Ultimately you should wind up in the same spot, but -10 looks "right" and +350 looks foolish.

You can limit the turn angle with code like:

while turnAngle > 3.1415
    turnAngle = turnAngle - 2*3.1415:
end
while turnAngle < -3.1415
    turn Angle = turnAngle + 2*3.1415;
end

This code runs and doesn't care what multiple of +/-2$\pi$ you're in, it spits out the same angle bounded to within +/-$\pi$.

Finally, calculate how far you travel along your new heading with the magnitude of distance between the points:

$$
\mbox{distance} = \sqrt{dX^2 + dY^2} \\
$$

Remember to set the new absolute heading, $\theta_{0 \rightarrow 1}$, as your current heading then get the next point!

:UPDATE: - Numeric Example

I believe a point of confusion here may be that I didn't state that the absolute heading is relative to the +x-axis. That said, I'll work through OP's problem as shown in the most recent update.

The initial heading $\theta_0$ is in-line with the +x-axis, so $\theta_0 = 0$.

$$
p_{start} = <-300,300> \\
p_{end} = <-300,-300> \\
$$

$$
dX = x_{end} - x_{start} = (-300) - (-300) \\
\boxed{dX = 0} \\
$$

$$
dY = y_{end} - y_{start} = (-300) - (300) \\
\boxed{dY = -600} \\
$$

$$
\theta_{0 \rightarrow 1} = atan2(dY,dX) \\
\theta_{0 \rightarrow 1} = atan2(-600,0) \\
\theta_{0 \rightarrow 1} = -1.5708 \mbox{rad} = -90^o
$$

Now, the change in heading:

$$
\mbox{Turn Angle} = \theta_{0 \rightarrow 1} - \theta_0 \\
\mbox{Turn Angle} = -1.5708 - 0 \\
\mbox{Turn Angle} = -1.5708 = -90^o\\
$$

The distance you need to travel after turning $\mbox{Turn Angle}$ is given by:
$$
\mbox{distance} = \sqrt{dX^2 + dY^2} \\
\mbox{distance} = \sqrt{0^2 + (-600)^2} \\
\mbox{distance} = \sqrt{(-600)^2} \\
\mbox{distance} = 600 \\
$$

Now the new heading $\theta_1$ is equal to the absolute heading between start and end:

$$
\theta_1 = \theta_{0 \rightarrow 1} \\
$$

Or, alternatively, the new heading is equal to the initial heading plus the turn angle, but the turn angle was defined by the difference between $\theta_{0 \rightarrow 1}$ and $\theta_0$, so the equation above is just a shortcut.

Now, proceed to the next point:

$$
p_{start} = <-300,-300> \\
p_{end} = <0,-300> \\
$$

$$
dX = x_{end} - x_{start} = (0) - (-300) \\
\boxed{dX = 300} \\
$$

$$
dY = y_{end} - y_{start} = (-300) - (-300) \\
\boxed{dY = 0} \\
$$

$$
\theta_{1 \rightarrow 2} = atan2(dY,dX) \\
\theta_{1 \rightarrow 2} = atan2(0,300) \\
\theta_{1 \rightarrow 2} = 0 \mbox{rad} = 0^o
$$

Now, the change in heading:

$$
\mbox{Turn Angle} = \theta_{1 \rightarrow 2} - \theta_1 \\
\mbox{Turn Angle} = 0 - (-1.5708) \\
\mbox{Turn Angle} = +1.5708 = +90^o \\
$$

The distance you need to travel after turning $\mbox{Turn Angle}$ is given by:
$$
\mbox{distance} = \sqrt{dX^2 + dY^2} \\
\mbox{distance} = \sqrt{(300)^2 + (0)^2} \\
\mbox{distance} = \sqrt{(300)^2} \\
\mbox{distance} = 300 \\
$$

Now the new heading $\theta_1$ is equal to the absolute heading between start and end:

$$
\theta_2 = \theta_{1 \rightarrow 2} \\
$$

This process repeats as you see fit.

:Second Update: Code Issues

You need to turn (left or right) by the amount turnAngle. You have not described your physical robot so nobody can tell you exactly how to turn.

You have your code in void loop(), which makes me think you are running the same code over and over, but you never take the following steps:

You never declare a starting heading.

You fail to define turnAngle as the difference between atan2((yt-yc),(xt-xc)) and the starting heading.

After you have turned, you fail to set your new heading.

You fail to move forward.

You fail to update your current position with the target position

I would suggest modifying your code as follows:

Last update

The wheel base is the distance from the center of the tire to the center of the other tire. Assuming that the motor speeds while turning are the same magnitude but opposite sides (leftMotorSpeed = - rightMotorSpeed), and the wheels are the same diameter, you can find out how quickly you are turning by using the arc length equation s = L*theta, so theta = s/L, where theta is the rotation, s is the arc length, and L is half the wheel base. Then, taking a derivative, $\dot{\theta} = \dot{s}/L$, where $\dot{s}$ is the linear tire speed, given by $\dot{s} = r_\mbox{tire}*v_\mbox{motor}$

So you can take motor speed and get back to rotation rate, and then numerically integrate that and compare to the $\mbox{Turn Angle}$:

thetaDot = (rTire * vMotor) / (wheelBase/2);

then

theta = theta + thetaDot*dT;

where dT is the sample/sweep time on the controller. Finally, use a while loop to turn the motors until the desired angle is reached. Putting it all together:

//current points
float xc = -300;
float yc = 300;

//target points

float xt = -300;
float yt = -300;

//turning  angle
float turnAngle;

//***************
float startingHeading = 0;
float currentHeading = startingHeading;
//***************

//***************
float turnRight = 1;
float turnLeft = -1;
float wheelBase = <This is a number you get by measuring your vehicle>
float tireRadius = <This is a number you get by measuring your vehicle>
float speedModifier = 0;
float vRightMotor = 0;
float vLeftMotor = 0;
float vMotor = 0;
float theta = 0;
float distance = 0;
//**************

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

void loop() {
  //*************
  destinationHeading = atan2((yt-yc), (xt-xc)); //calculate turning angle
  destinationHeading = destinationHeading * 180/3.1415; //convert to degrees
  turnAngle = destinationHeading - currentHeading;
  //*************

  if (turnAngle > 180) {
    turnAngle = turnAngle-360;
  }

  if (turnAngle < -180) {
    turnAngle = turnAngle+360;
  }

  //***************
  if (turnAngle < 0) {
    speedModifier = turnRight;
  }

  if (turnAngle > 0) {
    speedModifier = turnLeft
  }

  theta = 0;
  while abs(abs(theta)-abs(turnAngle)) > 0
    {
    vRightMotor = speedModifier * <100 percent speed - varies by your application>;
    vLeftMotor = -speedModifier * <100 percent speed - varies by your application>;
    <send the vRightMotor/vLeftMotor speed commands to the motors>
    vMotor = vRightMotor;
    thetaDot = (tireRadius * vMotor) / (wheelBase/2);`
    theta = theta + thetaDot*dT;
    }
  <send zero speed to the motors>

  currentHeading = destinationHeading;
  distance = sqrt((xt - xc)^2 + (yt - yc)^2);
  if (distance > 0) {
    // go forward
  }
  xc = xt;
  yc = yt;
  //****************
}