CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Control of four motors with PIC or DSPIC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
victorcastro89



Joined: 31 Oct 2011
Posts: 11

View user's profile Send private message

Control of four motors with PIC or DSPIC
PostPosted: Sat Jul 14, 2012 7:21 am     Reply with quote

I'm building a four-wheeled robot, where a Pic receives information wirelessly, sends other information for four other pic that controls the wheels, but the four pics that make the control wheel should return information on the current speed of each wheel to the first pic to make control of the robot.





My question is what kind of communication to use to the Master (pic1) transmit to the Slaves and the Slave Return information to the master.
Spi, I2c,rs485, Wich can do this?

Thank You!
jgschmidt



Joined: 03 Dec 2008
Posts: 184
Location: Gresham, OR USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Jul 14, 2012 9:45 am     Reply with quote

I'm working on something similar and am using CAN. Several of the Microchip processors support this. I have several reasons for using CAN: I am not limited by distance as I2C and SPI are and I don't have to write my own protocol/traffic handler as would be required with RS485. Also, CAN can be set up as peer-to-peer and many-to-many so my communications setup can be very flexible. You do have to be a bit creative with the physical topology since it is a linear bus.

I'm using the CCS CAN development kit as a starting point. Microchip also has a low-cost CAN dev kit that includes a great traffic logger which is invaluable for debugging. You have to know if the message ever got onto the bus so you know if the transmitter or the receiver is the problem if things go wrong. You can also use it to insert your own messages to test your receivers.

It takes a little bit to understand the philosophy behind the CAN protocols so be prepared for a little reading.

You can check out the bottom of this page for a list of CAN references:

http://www.jgscraft.com/microchip.php
_________________
Jürgen
www.jgscraft.com
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 9:45 am     Reply with quote

why so many pics?

cant you do all in one?
_________________
CCS PCM 5.078 & CCS PCH 5.093
temtronic



Joined: 01 Jul 2010
Posts: 9269
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 10:03 am     Reply with quote

Whole LOT simpler to use ONE PIC !
InterPIC communications will really eat up time and code space let alone programming and debugging time!

Without more details, like PIC to motor driver interface,feedback..encoder or ??, can't help more except even the 'old' 16F877 will more than handle all aspects of that robot.

Cut code to control 1 wheel(drive and feedback), once that's working right, clone 3 more times...done.
victorcastro89



Joined: 31 Oct 2011
Posts: 11

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 10:49 am     Reply with quote

Thank you all!
The first pic has a very robust control that has high processing costs, I tried using just two dsPIC, one to control the robot and another to control the motors.

But my dspic33fj128mc802 failed to receive information via the first dsPIC UART, reading speed of each motor, motor control, and return back the speed of each motor via UART.
The problem is that, for each hall effect sensor generates up to a thousand interrupts per second to calculate the speed of the motors, it hinders the dsPIC can receive information, make four controls and send data back to the first dsPIC.

You think the dsPIC can do it all at the same time and I did not get programming correctly?
Four interrupts 1000 times per second is crashing everything!

And about CAN, never worked with it, is difficult to implement?
Thank for the link!
jgschmidt



Joined: 03 Dec 2008
Posts: 184
Location: Gresham, OR USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Jul 14, 2012 11:27 am     Reply with quote

CAN is pretty easy from the hardware side. CCS has the necessary functions for handling the message traffic and there are dedicated CAN interrupts. I had a three-node system breadboarded and running in a day, blinking lights and returning messages in response to button presses. The fun is deciding on the message formats and getting into a "publish and subscribe" mindset for working with CAN. Some of that you would have to do regardless of the messaging system.
_________________
Jürgen
www.jgscraft.com
temtronic



Joined: 01 Jul 2010
Posts: 9269
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 1:23 pm     Reply with quote

Somewhere, somehow your code has a huge 'bug'...in either design or implementation.
4KHz interrupts are easily 'do-able' on even modest PICs(ie: 16F877).

Not seeing your code or the scope of the design does 'handcuff' us on the sidelines.

'robots' in general are slow and 4 wheeled ones probably don't need ground control down to the nearest millmeter. I've used 20MHz '877s for 3DOF helicopters, 3 axis CNC plotters, etc. for the past 15 years.

There are hundreds of wheeled robots out on the net for sale and they certainly don't have dsPICs or CAN bus controllers in them. Try to apply the 'kiss' principle..as all the commercial products have !
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 2:07 pm     Reply with quote

Gabriel wrote:
why so many pics?

cant you do all in one?


For ease of development and flexibility the One_PIC_for_each_major_function method is good. You write one set of code for the motor controller and put it into 4 chips. Now the code for the central controller becomes easy too. If your robot is less the a meter long I would vote for SPI communication between PICs.

About 20 years ago I inherited a failing project. The original designer was trying to use a 386 processor to make eight timing measurements. He could never get it to work and was encouraged to quit. I scrapped the 386 for one 16C58 and ten identical 16C54's on a SPI bus to make ten measurements and had it up and running in no time at a fraction of the hardware cost of the 386.

Divide & Conquer!
_________________
The search for better is endless. Instead simply find very good and get the job done.
victorcastro89



Joined: 31 Oct 2011
Posts: 11

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 2:31 pm     Reply with quote

SherpaDoug wrote:
Gabriel wrote:
why so many pics?

cant you do all in one?


For ease of development and flexibility the One_PIC_for_each_major_function method is good. You write one set of code for the motor controller and put it into 4 chips. Now the code for the central controller becomes easy too. If your robot is less the a meter long I would vote for SPI communication between PICs.

About 20 years ago I inherited a failing project. The original designer was trying to use a 386 processor to make eight timing measurements. He could never get it to work and was encouraged to quit. I scrapped the 386 for one 16C58 and ten identical 16C54's on a SPI bus to make ten measurements and had it up and running in no time at a fraction of the hardware cost of the 386.

Divide & Conquer!



But the four SPI (Slave) is capable of sending information to the master?
There will be no conflict?
 
Later put my code in a dsPIC controlling four motors ....
Thank you!
temtronic



Joined: 01 Jul 2010
Posts: 9269
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 2:47 pm     Reply with quote

I can see both sides here, one PIC versus 5 PICs, having done both methods.

Using only one PIC you save on the R&D time to cut code to send/rcv data to the other 4 PICs which should(_must_) have some form of 'data valid' in the communications(CRC or ???).Without that a wheel or two could go 'funny', causing all sorts of grief! This added 'overhead' takes up CPU cycles(overall time), as well as additional PCBs,wiring,costs,etc.
Also some form of 'still connected' signalling should be built in.What happens when a wire breaks to the right rear wheel PIC?

Overall it is simpler,faster and cheaper to have one PIC do all the work.Any 40 pin PIC is capable of the task.Simpler, tends to be easier to code, easier to debug and faster to manufacture.

'distributed processing' has it's place but really is overkill for a simple robot.
victorcastro89



Joined: 31 Oct 2011
Posts: 11

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 3:22 pm     Reply with quote

temtronic wrote:
I can see both sides here, one PIC versus 5 PICs, having done both methods.

Using only one PIC you save on the R&D time to cut code to send/rcv data to the other 4 PICs which should(_must_) have some form of 'data valid' in the communications(CRC or ???).Without that a wheel or two could go 'funny', causing all sorts of grief! This added 'overhead' takes up CPU cycles(overall time), as well as additional PCBs,wiring,costs,etc.
Also some form of 'still connected' signaling should be built in.What happens when a wire breaks to the right rear wheel PIC?

Overall it is simpler,faster and cheaper to have one PIC do all the work.Any 40 pin PIC is capable of the task.Simpler, tends to be easier to code, easier to debug and faster to manufacture.

'distributed processing' has it's place but really is overkill for a simple robot.


Is not so simple, here is my application:

http://www.youtube.com/watch?v=7Low18WrjAE
And:
http://small-size.informatik.uni-bremen.de/

One dsPIC not can handle everything ... My Robot Can Go from 0.1ms to 3 m/s,
Kick ball, robot control system, engine control system, wireless information Receive Every 1 m / s, etc ...

Understand now?
temtronic



Joined: 01 Jul 2010
Posts: 9269
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 4:28 pm     Reply with quote

Your original post asked about controlling 4 motors through a wireless module.

One PIC will easily do all that.
Been there..done that 15 years ago,'simple' fire fighting bot to seek out and put out a fire(candle) in an unknown maze.

What you didn't include were the other 'things' it has to do...vision, collision advoidance,FOF,ball kicker,interRobot communications,'find the ball',etc.There's probably a few LEDs that have to be lit up too.

Also not stated was the physical size limits.Maybe not a problem with SMT today, but should be noted,along with any other 'must haves'.

Given the new scope of the project I'd still use one PIC, running at 80MHz, gives millions of machine cycles to do the various required tasks.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 4:44 pm     Reply with quote

In an application this small and fast I wouldn't bother with CRCs or checksums. Just refresh the motor control commands every 10ms or 25ms and if one occasionally gets corrupted the trajectory will not be too far off anyway. The overhead of verifying CRCs and requesting retransmission of packets would be too much.

What is the update rate of robot position you get from the video? Is this something you extract from raw video, or does the arena provide this to you?
_________________
The search for better is endless. Instead simply find very good and get the job done.
victorcastro89



Joined: 31 Oct 2011
Posts: 11

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 5:30 pm     Reply with quote

SherpaDoug wrote:
In an application this small and fast I wouldn't bother with CRCs or checksums. Just refresh the motor control commands every 10ms or 25ms and if one occasionally gets corrupted the trajectory will not be too far off anyway. The overhead of verifying CRCs and requesting retransmission of packets would be too much.

What is the update rate of robot position you get from the video? Is this something you extract from raw video, or does the arena provide this to you?


I'm using dspic33FJ to do tests but dspic33EP family have CRC implemented in hardware, I'm planing to use this...

Update is 60 frame/second, arena provide raw video to my team Computer and computer Send's via Xbee Broadcast information like velocity of all robots, each robot separate your own information, make a embedded control of robot speed and wheels Speed.

Robot control need hard CPU cost, because it separated only to do this one dsPIC.

My problem is in another dsPIC I'm using to receive the first DSPIC setpoint for each engine, making the control of four and return information back of the four motor current speed, so that the control of the robot can be done.

failing to make four motor work with one dspic, I decided to use one dsPIC for each engine,maybe i'm not handling interrupts properly, the control of four motors worked but not good as control with one motor,in other words it was awful!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group